public EntityConfig getEntityConfig(String name) { if (entityConfigs.containsKey(name)) return entityConfigs.get(name); else if (entityConfigs.containsKey("entities/" + name)) return entityConfigs.get("entities/" + name); logger.error("Entity config not found: " + name); return null; }
protected void processDir(Entry inputDir, ArrayList<Entry> files) throws Exception { // Start with a copy of a parent dir's settings or the default settings. Settings settings = null; File parent = inputDir.inputFile; while (true) { if (parent.equals(root)) break; parent = parent.getParentFile(); settings = dirToSettings.get(parent); if (settings != null) { settings = new Settings(settings); break; } } if (settings == null) settings = new Settings(defaultSettings); dirToSettings.put(inputDir.inputFile, settings); // Merge settings from pack.json file. File settingsFile = new File(inputDir.inputFile, "pack.json"); if (settingsFile.exists()) json.readFields(settings, new JsonReader().parse(new FileReader(settingsFile))); // Pack. TexturePacker2 packer = new TexturePacker2(root, settings); for (Entry file : files) packer.addImage(file.inputFile); packer.pack(inputDir.outputDir, packFileName); }
public TiledMap load(String fileName, AtlasTiledMapLoaderParameters parameter) { try { if (parameter != null) { yUp = parameter.yUp; } else { yUp = true; } FileHandle tmxFile = resolve(fileName); root = xml.parse(tmxFile); ObjectMap<String, TextureAtlas> atlases = new ObjectMap<String, TextureAtlas>(); FileHandle atlasFile = loadAtlas(root, tmxFile); if (atlasFile == null) { throw new GdxRuntimeException("Couldn't load atlas"); } TextureAtlas atlas = new TextureAtlas(atlasFile); atlases.put(atlasFile.path(), atlas); AtlasResolver.DirectAtlasResolver atlasResolver = new AtlasResolver.DirectAtlasResolver(atlases); TiledMap map = loadMap(root, tmxFile, atlasResolver, parameter); map.setOwnedResources(atlases.values().toArray()); setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter); return map; } catch (IOException e) { throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e); } }
public void destrueix() { Iterator<String> claus = imatges.keys(); while (claus.hasNext()) { String clau = claus.next(); imatges.get(clau).dispose(); } }
public WeaponConfig getWeaponConfig(String name) { if (weaponConfigs.containsKey(name)) return weaponConfigs.get(name); else if (weaponConfigs.containsKey("weapons/" + name)) return weaponConfigs.get("weapons/" + name); logger.error("Weapon config not found: " + name); return null; }
@Override public <T> T sendHttpRequest(HttpRequest httpRequest, Class<T> type) throws IOException { Object ret = httpResponses.get(httpRequest.getUrl()); if (ret == null) { ret = httpResponses.get(DEFAULT_RESPONSE); } return (T) ret; }
@Override public Preferences getPreferences(String name) { Preferences pref = prefs.get(name); if (pref == null) { pref = new GwtPreferences(name); prefs.put(name, pref); } return pref; }
@Override public void shutdown() { Application app = Gdx.app; if (instances.get(app) == this) { instances.remove(app); listenerTexture.dispose(); speakerTexture.dispose(); EventService.unsubscribe(this); } }
@Override public Preferences getPreferences(String name) { if (preferences.containsKey(name)) { return preferences.get(name); } else { Preferences prefs = new LwjglPreferences(name); preferences.put(name, prefs); return prefs; } }
/** End applying multiple animations to the instance and update it to reflect the changes. */ protected void end() { if (!applying) throw new GdxRuntimeException("You must call begin() first"); for (Entry<Node, Transform> entry : transforms.entries()) { entry.value.toMatrix4(entry.key.localTransform); transformPool.free(entry.value); } transforms.clear(); target.calculateTransforms(); applying = false; }
public RMESettings(FileHandle file) { keys = new ObjectMap<String, int[]>(); keys.put("left", new int[] {Keys.A, Keys.LEFT}); keys.put("up", new int[] {Keys.W, Keys.UP}); keys.put("right", new int[] {Keys.D, Keys.RIGHT}); keys.put("down", new int[] {Keys.S, Keys.DOWN}); Json json = new Json(); json.toJson(this, file); }
@Override public void cancelHttpRequest(HttpRequest httpRequest) { HttpResponseListener httpResponseListener = listeners.get(httpRequest); Request request = requests.get(httpRequest); if (httpResponseListener != null && request != null) { request.cancel(); httpResponseListener.cancelled(); requests.remove(httpRequest); listeners.remove(httpRequest); } }
private Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider) { Material result = new Material(); result.id = mtl.id; if (mtl.ambient != null) result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient)); if (mtl.diffuse != null) result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse)); if (mtl.specular != null) result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular)); if (mtl.emissive != null) result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive)); if (mtl.reflection != null) result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection)); if (mtl.shininess > 0f) result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess)); if (mtl.opacity != 1.f) result.set( new BlendingAttribute(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity)); ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>(); // FIXME mipmapping totally ignored, filters totally ignored, uvScaling/uvTranslation totally // ignored if (mtl.textures != null) { for (ModelTexture tex : mtl.textures) { Texture texture; if (textures.containsKey(tex.fileName)) { texture = textures.get(tex.fileName); } else { texture = textureProvider.load(tex.fileName); textures.put(tex.fileName, texture); disposables.add(texture); } TextureDescriptor descriptor = new TextureDescriptor(texture); descriptor.minFilter = Texture.TextureFilter.Linear; descriptor.magFilter = Texture.TextureFilter.Linear; descriptor.uWrap = Texture.TextureWrap.Repeat; descriptor.vWrap = Texture.TextureWrap.Repeat; switch (tex.usage) { case ModelTexture.USAGE_DIFFUSE: result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor)); break; case ModelTexture.USAGE_SPECULAR: result.set(new TextureAttribute(TextureAttribute.Specular, descriptor)); break; case ModelTexture.USAGE_BUMP: result.set(new TextureAttribute(TextureAttribute.Bump, descriptor)); break; case ModelTexture.USAGE_NORMAL: result.set(new TextureAttribute(TextureAttribute.Normal, descriptor)); break; } } } return result; }
@Override public Preferences getPreferences(String name) { if (preferences.containsKey(name)) { return preferences.get(name); } else { Preferences prefs = new Lwjgl3Preferences( new Lwjgl3FileHandle( new File(config.preferencesDirectory, name), config.preferencesFileType)); preferences.put(name, prefs); return prefs; } }
public void updateBinding(int keycode) { ObjectMap<String, Binding> bindings = game.getBindings(); Binding binding = bindings.get(this.focusedAction); String character = game.map.get(keycode); if (character != null) { binding.character = character; binding.keyCode = keycode; System.out.println( "Updating action: " + this.focusedAction + " to " + keycode + " " + binding.character); bindings.put(focusedAction, binding); } else { System.out.println("Couldnt map character: " + keycode); } }
public static void render(DebugRenderContext context, AudioSourceComponent sourceComponent) { Application app = Gdx.app; if (app == null) { return; } AudioDebugRenderer renderer = instances.get(app); if (renderer == null) { renderer = new AudioDebugRenderer(); instances.put(app, renderer); } renderer.renderSource(context, sourceComponent); }
private TextureRegion getCachedGfxRegion(TextureRegionAsset asset) { String relativePath = asset.getPath(); String regionName = FileUtils.removeFirstSeparator(FilenameUtils.removeExtension(relativePath)); TextureRegion region = regions.get(regionName); if (region == null) { if (cache != null) region = cache.findRegion(regionName); if (region == null) region = new TextureRegion(loadingRegion); regions.put(relativePath, region); } return region; }
private void continueConversation(DialogBox last) { DialogBox next; currentDialog++; if (currentDialog == conversation.length) { for (DialogBox value : people.values().toArray()) value.setCallback(null); if (callback != null) callback.onCompleted(); return; } next = people.get(speakingOrder[currentDialog]); next.setText(conversation[currentDialog]); last.setVisible(false); next.setVisible(true); }
private void updateAtlas(FileHandle file) { String relativePath = fileAccess.relativizeToAssetsFolder(file); TextureAtlas atlas = atlases.get(relativePath); if (atlas != null) { atlases.remove(relativePath); atlas.dispose(); } if (file.exists()) { atlases.put(relativePath, new TextureAtlas(file)); App.eventBus.post(new ResourceReloadedEvent(ResourceReloadedEvent.RESOURCE_TEXTURES)); App.eventBus.post(new ResourceReloadedEvent(ResourceReloadedEvent.RESOURCE_TEXTURE_ATLASES)); } }
public float getMix(Animation from, Animation to) { tempKey.a1 = from; tempKey.a2 = to; Float time = animationToMixTime.get(tempKey); if (time == null) return 0; return time; }
public TiledMap load(String fileName) { try { FileHandle tideFile = resolve(fileName); root = xml.parse(tideFile); ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>(); for (FileHandle textureFile : loadTileSheets(root, tideFile)) { textures.put(textureFile.path(), new Texture(textureFile)); } DirectImageResolver imageResolver = new DirectImageResolver(textures); TiledMap map = loadMap(root, tideFile, imageResolver); map.setOwnedResources(textures.values().toArray()); return map; } catch (IOException e) { throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e); } }
@Override public void render(float arg0) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { if (focused) { focused = false; } else { goBack(); } } if (focused) { shapeRenderer.begin(ShapeType.FilledRectangle); Color c = new Color(0.15f, 0.4f, 0.15f, 1f); shapeRenderer.setColor(c); shapeRenderer.filledRect(focusedBox.x, focusedBox.y, focusedBox.width, focusedBox.height); shapeRenderer.end(); } batch.begin(); ObjectMap.Entries<String, Rectangle> it = bindingButtons.entries(); // draw back button text font.draw(batch, "Back", backButton.x, backButton.y + backButton.height); // draw option texts while (it.hasNext()) { ObjectMap.Entry<String, Rectangle> entry = it.next(); Rectangle bounds = entry.value; font.draw(batch, entry.key, bounds.x, bounds.y + bounds.height); Binding binding = game.getBindings().get(entry.key); font.draw(batch, binding.character, bounds.x + 200.0f, bounds.y + bounds.height); } batch.end(); }
public void addAttachment(int slotIndex, String name, Attachment attachment) { if (attachment == null) throw new IllegalArgumentException("attachment cannot be null."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); Key key = new Key(); key.set(slotIndex, name); attachments.put(key, attachment); }
@Override public boolean touchDown(int x, int y, int arg2, int arg3) { camera.unproject(mousePos.set(x, y, 0)); if (backButton.contains(mousePos.x, mousePos.y)) { goBack(); } ObjectMap.Entries<String, Rectangle> entries = bindingButtons.entries(); boolean focusedAnOption = false; while (entries.hasNext()) { ObjectMap.Entry<String, Rectangle> entry = entries.next(); Rectangle bounds = entry.value; camera.unproject(mousePos.set(x, y, 0)); if (bounds.contains(mousePos.x, mousePos.y)) { this.focused = true; focusedAnOption = true; this.focusedBox.setY(bounds.y); this.focusedBox.setX(bounds.x); BitmapFont.TextBounds b = font.getBounds(entry.key); this.focusedBox.setHeight(b.height); this.focusedBox.setWidth(b.width); this.focusedAction = entry.key; } } if (!focusedAnOption) { this.focused = false; } return false; }
@Override public void show() { font = new BitmapFont( Gdx.files.internal("assets/font.fnt"), Gdx.files.internal("assets/font.png"), false); batch = new SpriteBatch(); shapeRenderer = new ShapeRenderer(); bindingButtons = new ObjectMap<String, Rectangle>(); backButton = new Rectangle(40.0f, 730.0f, 100.0f, 32.0f); // setup interface ObjectMap.Entries<String, Binding> it = game.getBindings().entries(); float y = 700.0f; while (it.hasNext()) { ObjectMap.Entry<String, Binding> entry = it.next(); Rectangle button = new Rectangle(300.0f, y, 150.0f, 32); y -= 40; bindingButtons.put(entry.key, button); } mousePos = new Vector3(); camera = new OrthographicCamera(); camera.setToOrtho(false); Gdx.input.setInputProcessor(this); focusedBox = new Rectangle(); }
@Override public void dispose() { if (cache != null) cache.dispose(); for (TextureAtlas atlas : atlases.values()) atlas.dispose(); watcher.removeListener(this); }
@Override public void createUI(ATVector2Array annotation, Field field, Class<?> fieldType) { Vector2ArrayView view = new Vector2ArrayView(); views.put(field, view); uiTable.add(annotation.fieldName()).spaceBottom(3).row(); uiTable.add(view).expandX().fillX().row(); }
public void setMix(Animation from, Animation to, float duration) { if (from == null) throw new IllegalArgumentException("from cannot be null."); if (to == null) throw new IllegalArgumentException("to cannot be null."); Key key = new Key(); key.a1 = from; key.a2 = to; animationToMixTime.put(key, duration); }
@Override protected void next(final ObjectMap<String, String> arguments) { for (int arrayId = 0, length = indexes.size; arrayId < length; arrayId++) { arguments.put(argumentNames.get(arrayId), values.get(arrayId)[indexes.get(arrayId)]); } incrementIndex(indexes.size - 1); currentIndex++; }
@Override public void updateUIFromEntities( ImmutableArray<EntityProxy> proxies, Field field, Class<?> fieldType) throws ReflectiveOperationException { StringStringMapView view = views.get(field); if (proxies.size() > 1) view.multipleSelected(); else view.setMap(EntityUtils.getFirstEntityComponent(proxies, Variables.class)); }