Java Code Examples for com.badlogic.gdx.utils.ObjectMap#get()

The following examples show how to use com.badlogic.gdx.utils.ObjectMap#get() . 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: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
private final static void applyNodeAnimationBlending (final NodeAnimation nodeAnim, final ObjectMap<Node, Transform> out,
	final Pool<Transform> pool, final float alpha, final float time) {

	final Node node = nodeAnim.node;
	node.isAnimated = true;
	final Transform transform = getNodeAnimationTransform(nodeAnim, time);

	Transform t = out.get(node, null);
	if (t != null) {
		if (alpha > 0.999999f)
			t.set(transform);
		else
			t.lerp(transform, alpha);
	} else {
		if (alpha > 0.999999f)
			out.put(node, pool.obtain().set(transform));
		else
			out.put(node, pool.obtain().set(node.translation, node.rotation, node.scale, ((NodePlus)node).weights).lerp(transform, alpha));
	}
}
 
Example 2
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
public <T> T get(String name, Class<T> type) {
	if (name == null)
		throw new IllegalArgumentException("name cannot be null.");
	if (type == null)
		throw new IllegalArgumentException("type cannot be null.");

	if (type == Drawable.class)
		return (T) getDrawable(name);
	if (type == TextureRegion.class)
		return (T) getRegion(name);
	if (type == NinePatch.class)
		return (T) getPatch(name);
	if (type == Sprite.class)
		return (T) getSprite(name);

	ObjectMap<String, Object> typeResources = resources.get(type);
	if (typeResources == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	Object resource = typeResources.get(name);
	if (resource == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	return (T) resource;
}
 
Example 3
Source File: ProjectData.java    From talos with Apache License 2.0 5 votes vote down vote up
public void setFrom (ModuleBoardWidget moduleBoardWidget) {
	final ObjectMap<ParticleEmitterWrapper, Array<ModuleWrapper>> moduleWrappers = moduleBoardWidget.moduleWrappers;
	final ObjectMap<ParticleEmitterWrapper, Array<ModuleBoardWidget.NodeConnection>> nodeConnections = moduleBoardWidget.nodeConnections;

	emitters.clear();

	for (ParticleEmitterWrapper key : moduleWrappers.keys()) {
		final EmitterData emitterData = new EmitterData();
		emitterData.name = key.getName();
		emitterData.sortPosition = key.getEmitter().getSortPosition();
		emitterData.modules.addAll(moduleWrappers.get(key));

		final Array<ModuleBoardWidget.NodeConnection> nodeConns = nodeConnections.get(key);
		if(nodeConns != null) {
			for (ModuleBoardWidget.NodeConnection nodeConn : nodeConns) {
				emitterData.connections.add(new ConnectionData(nodeConn.fromModule.getId(), nodeConn.toModule.getId(), nodeConn.fromSlot, nodeConn.toSlot));
			}
		}

		// add groups
		for(ModuleWrapperGroup group: moduleBoardWidget.getGroups(key)) {
			GroupData groupData = new GroupData();
			groupData.text = group.getText();
			groupData.modules = new Array<>();
			groupData.color = group.getFrameColor().toFloatBits();
			for(ModuleWrapper wrapper: group.getModuleWrappers()) {
				groupData.modules.add(wrapper.getId());
			}
			emitterData.groups.add(groupData);
		}

		emitters.add(emitterData);
	}
}
 
Example 4
Source File: TextureResolver.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public TextureDescriptor<Texture> getTexture(GLTFTextureInfo glMap) {
	GLTFTexture glTexture = glTextures.get(glMap.index);
	
	TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<Texture>();

	boolean useMipMaps;
	if(glTexture.sampler != null){
		GLTFSampler glSampler = glSamplers.get(glTexture.sampler);
		GLTFTypes.mapTextureSampler(textureDescriptor, glSampler);
		useMipMaps = GLTFTypes.isMipMapFilter(glSampler);
	}else{
		// default sampler options.
		// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#texture
		textureDescriptor.minFilter = TextureFilter.Linear;
		textureDescriptor.magFilter = TextureFilter.Linear;
		textureDescriptor.uWrap = TextureWrap.Repeat;
		textureDescriptor.vWrap = TextureWrap.Repeat;
		useMipMaps = false;
	}
	
	ObjectMap<Integer, Texture> textureMap = useMipMaps ? texturesMipmap : texturesSimple;
	
	Texture texture = textureMap.get(glTexture.source);
	if(texture == null){
		throw new GdxRuntimeException("texture not loaded");
	}
	textureDescriptor.texture = texture;
	return textureDescriptor;
}
 
Example 5
Source File: LR2SkinCSVLoader.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
protected S loadSkin(S skin, Path f, MainState state, SkinHeader header, IntIntMap option,
		ObjectMap<String, Object> property) throws IOException {
	this.skin = skin;
	this.state = state;
	for (String key : property.keys()) {
		if (property.get(key) != null) {
			if (property.get(key) instanceof Integer) {
				op.put((Integer) property.get(key), 1);
			}
			if (property.get(key) instanceof String) {
				for (CustomFile file : header.getCustomFiles()) {
					if (file.name.equals(key)) {
						filemap.put(file.path, (String) property.get(key));
						break;
					}
				}
			}
		}
	}

	IntMap<SkinConfig.Offset> offset = new IntMap<>();
	for (CustomOffset of : header.getCustomOffsets()) {
		final Object o = property.get(of.name);
		if(o instanceof Offset) {
			offset.put(of.id, (Offset)o);				
		}
	}
	skin.setOffset(offset);

	op.putAll(option);
	this.loadSkin0(skin, f, state, op);

	return skin;
}
 
Example 6
Source File: Thesaurus.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public String localize(String key, ObjectMap<String, String> params) {
    if (params == null)
        params = EMPTY;
    ThesaurusData thesaurusData = data.get(key);
    String localized = getLocalized(thesaurusData);
    if (localized == null) {
        if (!key.contains(" ") && key.contains(".") && !key.contains("{")) {
            String fallback = key.split("\\.")[0];
            return localize(fallback);
        }
        localized = key;
    }
    while (localized.contains("{")) {
        int end = localized.indexOf('}');
        if (end == -1)
            return localized;
        int start = localized.indexOf('{');
        String replaceKey = localized.substring(start + 1, end);
        String replaceValue = params.get(replaceKey);
        if (replaceValue == null) {
            replaceValue = localize(replaceKey, params);
        } else {
            replaceValue = localize(replaceValue, params);
        }
        localized = localized.substring(0, start) + replaceValue + localized.substring(end + 1);
    }
    return localized;
}
 
Example 7
Source File: CCTextureAtlasLoader.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, TextureAtlasLoader.TextureAtlasParameter parameter) {
    FileHandle imgDir = file.parent();
    map = LyU.createDictionaryWithContentsOfFile(file);
    ObjectMap<String, Object> metadata = (ObjectMap<String, Object>) map.get("metadata");
    String dependFile = (String) metadata.get("textureFileName");
    Array<AssetDescriptor> res = new Array<AssetDescriptor>();
    TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
    params.magFilter = Texture.TextureFilter.Linear;
    params.minFilter = Texture.TextureFilter.Linear;
    params.format = Pixmap.Format.RGBA8888;
    texture = new Texture(imgDir.child(dependFile));
    res.add(new AssetDescriptor(imgDir.child(dependFile), Texture.class, params));
    return res;
}
 
Example 8
Source File: DistributionAdapters.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Distribution> T toDistribution (String value, Class<T> clazz) {
	StringTokenizer st = new StringTokenizer(value, ", \t\f");
	if (!st.hasMoreTokens()) throw new DistributionFormatException("Missing ditribution type");
	String type = st.nextToken();
	ObjectMap<String, Adapter<?>> categories = typeMap.get(clazz);
	Adapter<T> converter = (Adapter<T>)categories.get(type);
	if (converter == null)
		throw new DistributionFormatException("Cannot create a '" + clazz.getSimpleName() + "' of type '" + type + "'");
	String[] args = new String[st.countTokens()];
	for (int i = 0; i < args.length; i++)
		args[i] = st.nextToken();
	return converter.toDistribution(args);
}
 
Example 9
Source File: ColorPickerDialog.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the color is already in use somewhere else in the skin
 */
public boolean isColorInUse(Color color) {

	try {
		// Check if it is already in use somewhere!
		for (String widget : SkinEditorGame.widgets) {
			String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
			Class<?> style = Class.forName(widgetStyle);
			ObjectMap<String, ?> styles = game.skinProject.getAll(style);
			Iterator<String> it = styles.keys().iterator();
			while (it.hasNext()) {
				Object item = styles.get((String) it.next());
				Field[] fields = ClassReflection.getFields(item.getClass());
				for (Field field : fields) {

					if (field.getType() == Color.class) {

						Color c = (Color) field.get(item);
						if (color.equals(c)) {
							return true;
						}

					}

				}

			}

		}
	} catch (Exception e) {
		e.printStackTrace();

	}

	return false;
}
 
Example 10
Source File: FontPickerDialog.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Is font is already in use somewhere else?
 */
public boolean isFontInUse(BitmapFont font) {

	try {
		// Check if it is already in use somewhere!
		for (String widget : SkinEditorGame.widgets) {
			String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
			Class<?> style = Class.forName(widgetStyle);
			ObjectMap<String, ?> styles = game.skinProject.getAll(style);
			Iterator<String> it = styles.keys().iterator();
			while (it.hasNext()) {
				Object item = styles.get((String) it.next());
				Field[] fields = ClassReflection.getFields(item.getClass());
				for (Field field : fields) {

					if (field.getType() == BitmapFont.class) {

						BitmapFont f = (BitmapFont) field.get(item);
						if (font.equals(f)) {
							return true;
						}

					}

				}

			}

		}
	} catch (Exception e) {
		e.printStackTrace();

	}

	return false;
}
 
Example 11
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
public <T> T optional(String name, Class<T> type) {
	if (name == null)
		throw new IllegalArgumentException("name cannot be null.");
	if (type == null)
		throw new IllegalArgumentException("type cannot be null.");
	ObjectMap<String, Object> typeResources = resources.get(type);
	if (typeResources == null)
		return null;
	return (T) typeResources.get(name);
}