use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.
the class ParticleEffectLoader method getDependencies.
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, ParticleEffectLoadParameter parameter) {
Json json = new Json();
ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file);
Array<AssetData> assets = null;
synchronized (items) {
ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>();
entry.key = fileName;
entry.value = data;
items.add(entry);
assets = data.getAssets();
}
Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>();
for (AssetData<?> assetData : assets) {
// If the asset doesn't exist try to load it from loading effect directory
if (!resolve(assetData.filename).exists()) {
assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path();
}
if (assetData.type == ParticleEffect.class) {
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter));
} else
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type));
}
return descriptors;
}
use of com.badlogic.gdx.utils.Array in project libgdx-inGameConsole by StrongJoshua.
the class AbstractConsole method execCommand.
/* (non-Javadoc)
* @see com.strongjoshua.console.Console#execCommand(java.lang.String)
*/
@Override
public void execCommand(String command) {
if (disabled)
return;
log(command, LogLevel.COMMAND);
String[] parts = command.split(" ");
String methodName = parts[0];
String[] sArgs = null;
if (parts.length > 1) {
sArgs = new String[parts.length - 1];
for (int i = 1; i < parts.length; i++) {
sArgs[i - 1] = parts[i];
}
}
Class<? extends CommandExecutor> clazz = exec.getClass();
Method[] methods = ClassReflection.getMethods(clazz);
Array<Integer> possible = new Array<Integer>();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equalsIgnoreCase(methodName) && ConsoleUtils.canExecuteCommand(this, method)) {
possible.add(i);
}
}
if (possible.size <= 0) {
log("No such method found.", LogLevel.ERROR);
return;
}
int size = possible.size;
int numArgs = sArgs == null ? 0 : sArgs.length;
for (int i = 0; i < size; i++) {
Method m = methods[possible.get(i)];
Class<?>[] params = m.getParameterTypes();
if (numArgs == params.length) {
try {
Object[] args = null;
try {
if (sArgs != null) {
args = new Object[numArgs];
for (int j = 0; j < params.length; j++) {
Class<?> param = params[j];
final String value = sArgs[j];
if (param.equals(String.class)) {
args[j] = value;
} else if (param.equals(Boolean.class) || param.equals(boolean.class)) {
args[j] = Boolean.parseBoolean(value);
} else if (param.equals(Byte.class) || param.equals(byte.class)) {
args[j] = Byte.parseByte(value);
} else if (param.equals(Short.class) || param.equals(short.class)) {
args[j] = Short.parseShort(value);
} else if (param.equals(Integer.class) || param.equals(int.class)) {
args[j] = Integer.parseInt(value);
} else if (param.equals(Long.class) || param.equals(long.class)) {
args[j] = Long.parseLong(value);
} else if (param.equals(Float.class) || param.equals(float.class)) {
args[j] = Float.parseFloat(value);
} else if (param.equals(Double.class) || param.equals(double.class)) {
args[j] = Double.parseDouble(value);
}
}
}
} catch (Exception e) {
// Error occurred trying to parse parameter, continue to next function
continue;
}
m.setAccessible(true);
m.invoke(exec, args);
return;
} catch (ReflectionException e) {
String msg = e.getMessage();
if (msg == null || msg.length() <= 0 || msg.equals("")) {
msg = "Unknown Error";
e.printStackTrace();
}
log(msg, LogLevel.ERROR);
return;
}
}
}
log("Bad parameters. Check your code.", LogLevel.ERROR);
}
use of com.badlogic.gdx.utils.Array in project libgdx-inGameConsole by StrongJoshua.
the class CommandCompleter method getAllMethods.
private Array<Method> getAllMethods(CommandExecutor ce) {
Array<Method> methods = new Array<>();
Method[] ms = ClassReflection.getDeclaredMethods(ce.getClass());
for (Method m : ms) {
if (m.isPublic()) {
methods.add(m);
}
}
ms = ClassReflection.getDeclaredMethods(ce.getClass().getSuperclass());
for (Method m : ms) {
if (m.isPublic()) {
methods.add(m);
}
}
return methods;
}
use of com.badlogic.gdx.utils.Array in project nhglib by VoidZombie.
the class GraphicsSystem method rebuildCache.
private void rebuildCache(RenderableProvider... renderableProviders) {
Array<ModelCache> previousModelCaches = new Array<>(staticCaches);
for (int i = 0; i < cameras.size; i++) {
ModelCache previousModelCache = previousModelCaches.get(i);
ModelCache staticCache = staticCaches.get(i);
Camera camera = cameras.get(i);
previousModelCache.begin(camera);
previousModelCache.add(staticCache);
previousModelCache.end();
staticCache.begin(camera);
staticCache.add(previousModelCache);
for (RenderableProvider provider : renderableProviders) {
staticCache.add(provider);
}
staticCache.end();
}
}
use of com.badlogic.gdx.utils.Array in project nhglib by VoidZombie.
the class SceneManager method loadAssets.
private void loadAssets(Integer entity) {
final ModelComponent modelComponent = modelMapper.get(entity);
// Group all assets
final Array<Asset> allAssets = new Array<>();
final Asset modelAsset = modelComponent.asset;
for (PbrMaterial mat : modelComponent.pbrMaterials) {
if (mat.albedoAsset != null) {
allAssets.add(mat.albedoAsset);
}
if (mat.metalnessAsset != null) {
allAssets.add(mat.metalnessAsset);
}
if (mat.roughnessAsset != null) {
allAssets.add(mat.roughnessAsset);
}
if (mat.normalAsset != null) {
allAssets.add(mat.normalAsset);
}
if (mat.ambientOcclusionAsset != null) {
allAssets.add(mat.ambientOcclusionAsset);
}
}
// Start loading them
assets.queueAsset(modelAsset);
// Wait for them
messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {
@Override
public void accept(Message message) throws Exception {
Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
if (asset != null) {
if (asset.is(modelAsset.alias)) {
Model model = assets.get(asset);
modelComponent.model = new ModelInstance(model);
if (modelComponent.model.animations.size > 0) {
modelComponent.animationController = new AnimationController(modelComponent.model);
}
assets.queueAssets(allAssets);
} else {
if (allAssets.contains(asset, false)) {
temporaryLoadedAssets.add(asset);
allAssets.removeValue(asset, false);
Bundle bundle = new Bundle();
bundle.put("size", allAssets.size);
bundle.put("modelComponent", modelComponent);
sizeSubject.onNext(bundle);
}
}
}
}
});
}
Aggregations