Java Code Examples for com.badlogic.gdx.utils.reflect.ClassReflection#forName()
The following examples show how to use
com.badlogic.gdx.utils.reflect.ClassReflection#forName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformDistributor.java From gdx-fireapp with Apache License 2.0 | 6 votes |
/** * Creates platform specific object by reflection. * <p> * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()} * <p> * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object. * * @throws PlatformDistributorException Throws when something is wrong with environment */ @SuppressWarnings("unchecked") protected PlatformDistributor() { String className = null; if (Gdx.app.getType() == Application.ApplicationType.Android) { className = getAndroidClassName(); } else if (Gdx.app.getType() == Application.ApplicationType.iOS) { className = getIOSClassName(); } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) { className = getWebGLClassName(); } else { return; } try { Class objClass = ClassReflection.forName(className); platformObject = (T) ClassReflection.getConstructor(objClass).newInstance(); } catch (ReflectionException e) { throw new PlatformDistributorException("Something wrong with environment", e); } }
Example 2
Source File: StyleProperty.java From skin-composer with MIT License | 6 votes |
@Override public void read(Json json, JsonValue jsonValue) { try { name = jsonValue.getString("name"); optional = jsonValue.getBoolean("optional"); if (jsonValue.get("value").isNumber()) { type = Float.TYPE; value = Double.parseDouble(jsonValue.getString("value")); } else { type = ClassReflection.forName(jsonValue.getString("type")); if (jsonValue.get("value").isNull()) { value = null; } else { value = jsonValue.getString("value"); } } } catch (ReflectionException ex) { Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex); DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?"); } }
Example 3
Source File: AndroidGDXDialogs.java From gdx-dialogs with Apache License 2.0 | 6 votes |
@Override public <T> T newDialog(Class<T> cls) { String className = cls.getName(); if (registeredDialogs.containsKey(className)) { try { final Class<T> dialogClazz = ClassReflection.forName(registeredDialogs.get(className)); Object dialogObject = ClassReflection.getConstructor(dialogClazz, Activity.class).newInstance(activity); return dialogClazz.cast(dialogObject); } catch (Exception e) { e.printStackTrace(); } } throw new RuntimeException(cls.getName() + "is not registered."); }
Example 4
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 6 votes |
private void installDesktopGDXDialogs() { if (Gdx.app.getType() != ApplicationType.Desktop) { showDebugSkipInstall(ApplicationType.Desktop.name()); return; } try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.desktop.DesktopGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.Desktop.name()); } catch (ReflectionException e) { showErrorInstall(ApplicationType.Desktop.name(), "desktop"); e.printStackTrace(); } }
Example 5
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 6 votes |
private void installHTMLGDXDialogs() { if (Gdx.app.getType() != ApplicationType.WebGL) { showDebugSkipInstall(ApplicationType.WebGL.name()); return; } try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.html.HTMLGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.WebGL.name()); } catch (ReflectionException e) { showErrorInstall(ApplicationType.WebGL.name(), "html"); e.printStackTrace(); } }
Example 6
Source File: GLTFBinaryExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static void savePNG(FileHandle file, Pixmap pixmap){ if(Gdx.app.getType() == ApplicationType.WebGL){ throw new GdxRuntimeException("saving pixmap not supported for WebGL"); }else{ // call PixmapIO.writePNG(file, pixmap); via reflection to // avoid compilation error with GWT. try { Class pixmapIO = ClassReflection.forName("com.badlogic.gdx.graphics.PixmapIO"); Method pixmapIO_writePNG = ClassReflection.getMethod(pixmapIO, "writePNG", FileHandle.class, Pixmap.class); pixmapIO_writePNG.invoke(null, file, pixmap); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } } }
Example 7
Source File: Reflection.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public static Class forName( String name ){ try { return ClassReflection.forName( name ); } catch (ReflectionException e) { Game.reportException(e); return null; } }
Example 8
Source File: BehaviorTreeParser.java From gdx-ai with Apache License 2.0 | 5 votes |
void addImport (String alias, String task) { if (task == null) throw new GdxRuntimeException("import: missing task class name."); if (alias == null) { Class<?> clazz = null; try { clazz = ClassReflection.forName(task); } catch (ReflectionException e) { throw new GdxRuntimeException("import: class not found '" + task + "'"); } alias = clazz.getSimpleName(); } String className = getImport(alias); if (className != null) throw new GdxRuntimeException("import: alias '" + alias + "' previously defined already."); userImports.put(alias, task); }
Example 9
Source File: Reflection.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public static Class forName( String name ){ try { return ClassReflection.forName( name ); } catch (ReflectionException e) { Game.reportException(e); return null; } }
Example 10
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 5 votes |
private static Class<?> findClass(String name) { try { return ClassReflection.forName(name); } catch (Exception e) { return null; } }
Example 11
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 5 votes |
private void installGdxReflections() { try { gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx"); gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null); } catch (ReflectionException e) { e.printStackTrace(); throw new RuntimeException("No libGDX environment. \n"); } }
Example 12
Source File: GDXDialogs.java From gdx-dialogs with Apache License 2.0 | 5 votes |
public <T> T newDialog(Class<T> cls) { String className = cls.getName(); if (registeredDialogs.containsKey(className)) { try { final Class<T> dialogClazz = ClassReflection.forName(registeredDialogs.get(className)); Object dialogObject = ClassReflection.getConstructor(dialogClazz).newInstance(); return (T) dialogObject; } catch (Exception e) { e.printStackTrace(); } } throw new RuntimeException(cls.getName() + "is not registered."); }
Example 13
Source File: ModuleListPopup.java From talos with Apache License 2.0 | 5 votes |
private void registerModule(XmlReader.Element module) { try { Class moduleClazz = ClassReflection.forName("com.talosvfx.talos.runtime.modules." + module.getText()); Class wrapperClazz =ClassReflection.forName("com.talosvfx.talos.editor.wrappers." + module.getAttribute("wrapper")); WrapperRegistry.reg(moduleClazz, wrapperClazz); TalosMain.Instance().moduleNames.put(wrapperClazz, module.getAttribute("name")); } catch (ReflectionException e) { e.printStackTrace(); } WrapperRegistry.reg(EmitterModule.class, EmitterModuleWrapper.class); }
Example 14
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 4 votes |
private void installAndroidGDXDialogs() { if (Gdx.app.getType() != ApplicationType.Android) { showDebugSkipInstall(ApplicationType.Android.name()); return; } if (Gdx.app.getType() == ApplicationType.Android) { try { Class<?> activityClazz = ClassReflection.forName("android.app.Activity"); Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.android.AndroidGDXDialogs"); Object activity = null; if (ClassReflection.isAssignableFrom(activityClazz, gdxAppObject.getClass())) { activity = gdxAppObject; } else { Class<?> supportFragmentClass = findClass("android.support.v4.app.Fragment"); // { if (supportFragmentClass != null && ClassReflection.isAssignableFrom(supportFragmentClass, gdxAppObject.getClass())) { activity = ClassReflection.getMethod(supportFragmentClass, "getActivity").invoke(gdxAppObject); } else { Class<?> fragmentClass = findClass("android.app.Fragment"); if (fragmentClass != null && ClassReflection.isAssignableFrom(fragmentClass, gdxAppObject.getClass())) { activity = ClassReflection.getMethod(fragmentClass, "getActivity").invoke(gdxAppObject); } } } if (activity == null) { throw new RuntimeException("Can't find your gdx activity to instantiate gdx-dialogs. " + "Looks like you have implemented AndroidApplication without using " + "Activity or Fragment classes or Activity is not available at the moment"); } Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz, activityClazz).newInstance(activity); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.Android.name()); } catch (Exception e) { showErrorInstall(ApplicationType.Android.name(), "android"); e.printStackTrace(); } } }
Example 15
Source File: Reflection.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public static Class forNameUnhandled( String name ) throws Exception { return ClassReflection.forName( name ); }
Example 16
Source File: Reflection.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
public static Class forNameUnhandled( String name ) throws Exception { return ClassReflection.forName( name ); }
Example 17
Source File: GdxReflection.java From Cardshifter with Apache License 2.0 | 4 votes |
@Override public Class<?> forName(String s) throws Exception { return ClassReflection.forName(s); }