Java Code Examples for com.badlogic.gdx.utils.ObjectMap#Entry

The following examples show how to use com.badlogic.gdx.utils.ObjectMap#Entry . 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: HeadlessModelLoader.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, P parameters) {
	final Array<AssetDescriptor> deps = new Array();
	ModelData data = loadModelData(file, parameters);
	if (data == null) return deps;

	ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
	item.key = fileName;
	item.value = data;
	synchronized (items) {
		items.add(item);
	}

	/*TextureLoader.TextureParameter textureParameter = (parameters != null)
			? parameters.textureParameter
			: defaultParameters.textureParameter;

	for (final ModelMaterial modelMaterial : data.materials) {
		if (modelMaterial.textures != null) {
			for (final ModelTexture modelTexture : modelMaterial.textures)
				deps.add(new AssetDescriptor(modelTexture.fileName, Texture.class, textureParameter));
		}
	}*/
	return deps;
}
 
Example 2
Source File: Ragdoll.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the rigid body parts to follow nodes of the model instance
 */
private void updateBodiesToArmature() {
	// Ragdoll parts should follow the model animation.
	// Loop over each part and set it to the global transform of the armature node it should follow.
	capsuleTransform.set(modelTransform);
	for (Iterator<ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection>> iterator
		 = bodyPartMap.iterator(); iterator.hasNext(); ) {
		ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection> entry = iterator.next();
		RigidBodyNodeConnection data = entry.value;
		btRigidBody body = entry.key;
		Node followNode = data.followNode;
		Vector3 offset = data.bodyNodeOffsets.get(followNode);

		body.proceedToTransform(tmpMatrix.set(capsuleTransform)
				.mul(followNode.globalTransform).translate(offset));
	}
}
 
Example 3
Source File: MusicEventManager.java    From gdx-soundboard with MIT License 6 votes vote down vote up
/**
 * Remove an event.
 * 
 * @param stateName
 *            The name of the event.
 */
public void remove(String stateName) {
    final MusicState event = this.states.remove(stateName);
    if (event != null) {

        for (final ObjectMap.Entry<String, MusicState> entry : this.states) {
            entry.value.removeEnterTransition(stateName);
            entry.value.removeExitTransition(stateName);
        }

        event.dispose();

        if (currentState == event) {
            currentState = null;
        }
        for (int i = 0; i < listeners.size; i++) {
            final MusicEventListener observer = listeners.get(i);
            observer.stateRemoved(event);
        }
    }
}
 
Example 4
Source File: Ragdoll.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the nodes of the model instance to follow the rigid body parts
 */
private void updateArmatureToBodies() {
	// Let dynamicsworld control ragdoll. Loop over all ragdoll part collision shapes
	// and their node connection data.
	for (Iterator<ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection>> iterator1
		 = bodyPartMap.iterator(); iterator1.hasNext(); ) {
		ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection> bodyEntry = iterator1.next();
		btRigidBody partBody = bodyEntry.key;
		RigidBodyNodeConnection connection = bodyEntry.value;
		capsuleTransform.getTranslation(capsuleTranslation);

		// Loop over each node connected to this collision shape
		for (Iterator<ObjectMap.Entry<Node, Vector3>> iterator2
			 = connection.bodyNodeOffsets.iterator(); iterator2.hasNext(); ) {
			ObjectMap.Entry<Node, Vector3> nodeEntry = iterator2.next();
			// A node which is to follow this collision shape
			Node node = nodeEntry.key;
			// The offset of this node from the untranslated collision shape origin
			Vector3 offset = nodeEntry.value;
			// Set the node to the transform of the collision shape it follows
			partBody.getWorldTransform(node.localTransform);
			// Calculate difference in translation between the node/ragdoll part and the
			// base capsule shape.
			node.localTransform.getTranslation(nodeTranslation);
			// Calculate the final node transform
			node.localTransform.setTranslation(nodeTranslation.sub(capsuleTranslation)).translate(tmpVec.set(offset).scl(-1));
		}
	}
	// Calculate the final transform of the model.
	modelInstance.calculateTransforms();
}
 
Example 5
Source File: TransitionOutPanel.java    From gdx-soundboard with MIT License 5 votes vote down vote up
public void setMusicState(MusicState musicEvent) {
    this.musicEvent = musicEvent;

    outTransitions.getItems().clear();

    ObjectMap<String, StopEffect> effects = musicEvent.getExitTransitions();

    for(ObjectMap.Entry<String, StopEffect> entry : effects){
        outTransitions.getItems().add(new EffectDecorator(entry.key, entry.value));
    }
    remove.setDisabled(effects.size == 0 || outTransitions.getSelected() == null);
}
 
Example 6
Source File: TransitionInPanel.java    From gdx-soundboard with MIT License 5 votes vote down vote up
public void setMusicState(MusicState musicEvent) {
    this.musicEvent = musicEvent;

    inTransitions.getItems().clear();

    ObjectMap<String, StartEffect> effects = musicEvent.getEnterTransitions();

    for(ObjectMap.Entry<String, StartEffect> entry : effects){
        inTransitions.getItems().add(new EffectDecorator(entry.key, entry.value));
    }
    remove.setDisabled(effects.size == 0 || inTransitions.getSelected() == null);
}
 
Example 7
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void loadNodes (Iterable<ModelNode> modelNodes) {
	nodePartBones.clear();
	for (ModelNode node : modelNodes) {
		nodes.add(loadNode(null, node));
	}
	for (ObjectMap.Entry<NodePart, ArrayMap<String, Matrix4>> e : nodePartBones.entries()) {
		if (e.key.invBoneBindTransforms == null)
			e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(Node.class, Matrix4.class);
		e.key.invBoneBindTransforms.clear();
		for (ObjectMap.Entry<String, Matrix4> b : e.value.entries())
			e.key.invBoneBindTransforms.put(getNode(b.key), new Matrix4(b.value).inv());
	}
}
 
Example 8
Source File: BladeJson.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public BladeJson(World w, Mode mode, boolean init) {
	super();

	this.w = w;
	this.mode = mode;
	this.init = init;

	// Add tags for known classes to reduce .json size.
	addClassTag(SpineAnimationDesc.class);
	addClassTag(AtlasAnimationDesc.class);

	addClassTag(CharacterActor.class);
	addClassTag(AnchorActor.class);
	addClassTag(ObstacleActor.class);
	addClassTag(InteractiveActor.class);
	addClassTag(SpriteActor.class);
	addClassTag(WalkZoneActor.class);

	addClassTag(AtlasRenderer.class);
	addClassTag(ImageRenderer.class);
	addClassTag(ParticleRenderer.class);
	addClassTag(Sprite3DRenderer.class);
	addClassTag(TextRenderer.class);

	ObjectMap<String, Class<? extends Action>> classTags = ActionFactory.getClassTags();

	for (ObjectMap.Entry<String, Class<? extends Action>> e : classTags.entries()) {
		addClassTag(e.key, e.value);
	}

}
 
Example 9
Source File: BlenderAssetManager.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public <S extends Array<T>, T extends BlenderObject> S getAllPlaceholders(Class<T> type, S out) {
	BlenderObjectMap<T> map = getTypeMap(type);
	for (ObjectMap.Entry<String, Array<T>> entry : map) {
		out.addAll(entry.value);
	}
	return out;
}
 
Example 10
Source File: BlenderAssetManager.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
	for (ObjectMap.Entry<Class<T>, ObjectMap<String, T>> entryClass : map) {
		for (ObjectMap.Entry<String, T> entryId : entryClass.value) {
			entryId.value.dispose();
		}
	}
	map.clear();
}
 
Example 11
Source File: GDXFacebookGraphRequest.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
public String getJavascriptObjectString() {
    StringBuffer convertedParameters = new StringBuffer();

    for (ObjectMap.Entry<String, String> entry : fields) {
        convertedParameters.append(entry.key);
        convertedParameters.append(":\"");
        convertedParameters.append(entry.value.replace("\"", "\\\""));
        convertedParameters.append("\",");
    }
    if (convertedParameters.length() > 0)
        convertedParameters.deleteCharAt(convertedParameters.length() - 1);


    return convertedParameters.toString();
}
 
Example 12
Source File: GDXFacebookGraphRequest.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
public String getContent() {
    StringBuffer convertedParameters = new StringBuffer();

    for (ObjectMap.Entry<String, String> entry : fields) {
        convertedParameters.append(encode(entry.key, defaultEncoding));
        convertedParameters.append(nameValueSeparator);
        convertedParameters.append(encode(entry.value, defaultEncoding));
        convertedParameters.append(parameterSeparator);
    }

    if (convertedParameters.length() > 0)
        convertedParameters.deleteCharAt(convertedParameters.length() - 1);
    return convertedParameters.toString();

}
 
Example 13
Source File: PvpPlayStateCallback.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onWin(BaseLevelDescription level, LevelResult result, ObjectMap<Player, IParticipant> playersToParticipants, final PvpPlayState.RestartCallback callback) {
    Array<RewardResult> rewards = app.applyLevelResult(level, result, true);
    Array<IParticipant> opponents = new Array<IParticipant>();
    for (ObjectMap.Entry<Player, IParticipant> e : playersToParticipants.entries()) {
        if (e.key.inRelation(result.viewer, PlayerRelation.enemy)) {
            opponents.add(e.value);
        }
    }
    String shareText = Config.thesaurus.localize(
        "pvp-share",
        Thesaurus.params()
            .with("opponents", Thesaurus.Util.enumerate(Config.thesaurus, opponents, IParticipant.STRINGIFIER))
            .with("pvp-cant-stop-me", opponents.size > 1 ? "pvp-cant-stop-me.many" : "pvp-cant-stop-me.one")
    );
    Config.mobileApi.services().incrementScore("CgkIsNnQ2ZcKEAIQFw", 1).addListener(new IFutureListener<Boolean>() {
        @Override public void onHappened(Boolean success) {
            Logger.debug("todo");
        }
    });
    winWindow = new PvpWinWindow();
    winWindow.show(new PvpWinWindow.Params(rewards, shareText, result, new PvpWinWindow.Callback() {

        @Override public void onClose() {
            winWindow = null;
            app.setState(app.gameMapState);
        }

        @Override public void onRestart() {
            winWindow = null;
            callback.onRestart();
        }
    }, app.userData));
}
 
Example 14
Source File: JamepadTest.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
private void updateStateOfButtons() {
    for (ObjectMap.Entry<ControllerButton, Label> entry : buttonToLabel.entries()) {
        if (selectedController == null) {
            entry.value.setColor(Color.DARK_GRAY);
        } else {
            boolean pressed = selectedController.getButton(entry.key.ordinal());
            entry.value.setColor(pressed ? RED : WHITE);
        }
    }
}
 
Example 15
Source File: FileTracker.java    From talos with Apache License 2.0 5 votes vote down vote up
public void update() {
    Array<FileHandle> filesToRemove = new Array<>();

    final FileTab currentTab = TalosMain.Instance().ProjectController().currentTab;

    for (ObjectMap.Entry<FileTab, ObjectMap<FileHandle, FileEntry>> tabMapEntry : tabMaps) {
        boolean isCurrentTab = tabMapEntry.key == currentTab;

        final ObjectMap<FileHandle, FileEntry> files = tabMapEntry.value;


        for (ObjectMap.Entry<FileHandle, FileEntry> entry : files) {
            final FileEntry fileEntry = entry.value;
            if(!fileEntry.fileHandle.exists()) {
                filesToRemove.add(fileEntry.fileHandle);
            }
            if(fileEntry.lastModified < fileEntry.fileHandle.lastModified()) {
                if (isCurrentTab) {
                    fileEntry.callback.updated(fileEntry.fileHandle);
                }
                fileEntry.lastModified = fileEntry.fileHandle.lastModified();
            }
        }


        for (FileHandle handle: filesToRemove) {
            files.remove(handle);
        }
    }


}
 
Example 16
Source File: InterpolationMappings.java    From talos with Apache License 2.0 5 votes vote down vote up
public static String getNameForInterpolation (Interpolation interpolation) {
	for (ObjectMap.Entry<String, Interpolation> name : names) {
		if (name.value == interpolation) {
			return name.key;
		}
	}
	return "fade";
}
 
Example 17
Source File: CCTextureAtlasLoader.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
@Override
public TextureAtlas load(AssetManager assetManager, String fileName, FileHandle file, TextureAtlasLoader.TextureAtlasParameter parameter) {
    TextureAtlas atlas = new TextureAtlas();
    atlas.getTextures().add(texture);
    ObjectMap<String, Object> frames = (ObjectMap<String, Object>) map.get("frames");
    for (ObjectMap.Entry<String, Object> entry : frames.entries()) {
        String pageName = entry.key;
        ObjectMap<String, Object> params = (ObjectMap<String, Object>) entry.value;
        Rectangle frame = LyU.parseRect((String) params.get("frame"));
        GridPoint2 offset = LyU.parsePoint((String) params.get("offset"));
        boolean rotated = Boolean.parseBoolean((String) params.get("rotated"));
        GridPoint2 sourceSize = LyU.parsePoint((String) params.get("sourceSize"));
        Rectangle sourceColorRect = LyU.parseRect((String) params.get("sourceColorRect"));
        TextureAtlas.TextureAtlasData.Region region = new TextureAtlas.TextureAtlasData.Region();
        region.name = pageName.substring(0, pageName.lastIndexOf('.'));
        region.rotate = rotated;
        region.offsetX = offset.x;
        region.offsetY = offset.y;
        region.originalWidth = sourceSize.x;
        region.originalHeight = sourceSize.y;
        region.left = (int) frame.x;
        region.top = (int) frame.y;
        region.width = (int) frame.getWidth();
        region.height = (int) frame.getHeight();
        int width = region.width;
        int height = region.height;
        TextureAtlas.AtlasRegion atlasRegion = new TextureAtlas.AtlasRegion(texture, region.left, region.top,
            region.rotate ? height : width, region.rotate ? width : height);
        atlasRegion.index = region.index;
        atlasRegion.name = region.name;
        atlasRegion.offsetX = region.offsetX;
        atlasRegion.offsetY = region.offsetY;
        atlasRegion.originalHeight = region.originalHeight;
        atlasRegion.originalWidth = region.originalWidth;
        atlasRegion.rotate = region.rotate;
        atlasRegion.splits = region.splits;
        atlasRegion.pads = region.pads;
        if (region.flip) {
            atlasRegion.flip(false, true);
        }
        atlas.getRegions().add(atlasRegion);
    }
    texture = null;
    map = null;
    return atlas;
}
 
Example 18
Source File: DistributionAdapters.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public DistributionAdapters () {
	this.map = new ObjectMap<Class<?>, Adapter<?>>();
	this.typeMap = new ObjectMap<Class<?>, ObjectMap<String, Adapter<?>>>();
	for (ObjectMap.Entry<Class<?>, Adapter<?>> e : ADAPTERS.entries())
		add(e.key, e.value);
}
 
Example 19
Source File: ClassFinderCache.java    From libgdx-snippets with MIT License 4 votes vote down vote up
public void writeToFile(FileHandle file) throws IOException {

		try (Writer writer = file.writer(false, "UTF-8")) {

			for (ObjectMap.Entry<String, Array<String>> group : classNames) {

				writer.append(':').append(group.key).append('\n');

				for (String name : group.value) {
					writer.append(name).append('\n');
				}
			}

			writer.flush();
		}
	}
 
Example 20
Source File: MetaData.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Json json) {
    json.writeArrayStart("scopeDefaults");
    for(int i = 0; i < 10; i++) {
        NumericalValue val = TalosMain.Instance().globalScope.getDynamicValue(i);
        float[] arr = new float[4];
        for(int j = 0; j < 4; j++) {
            arr[j] = val.get(j);
        }
        json.writeValue(arr);
    }
    json.writeArrayEnd();

    // now sync preview widget stuff
    float camX = TalosMain.Instance().UIStage().PreviewWidget().getCameraPosX();
    float camY = TalosMain.Instance().UIStage().PreviewWidget().getCameraPosY();

    json.writeValue("previewCamPos", new Vector2(camX, camY));
    json.writeValue("previewCamZoom", TalosMain.Instance().UIStage().PreviewWidget().getCameraZoom());

    json.writeValue("bgImagePath", TalosMain.Instance().UIStage().PreviewWidget().getBackgroundImagePath());
    json.writeValue("bgImageIsInBack", TalosMain.Instance().UIStage().PreviewWidget().isBackgroundImageInBack());
    json.writeValue("bgImageSize", TalosMain.Instance().UIStage().PreviewWidget().getBgImageSize());
    json.writeValue("gridSize", TalosMain.Instance().UIStage().PreviewWidget().getGridSize());

    // particle position
    ParticleEffectInstance particleEffect = TalosMain.Instance().TalosProject().getParticleEffect();
    if(particleEffect != null) {
        json.writeValue("particlePositionX", particleEffect.getPosition().x);
        json.writeValue("particlePositionY", particleEffect.getPosition().y);
    }

    final ObjectMap<FileHandle, FileTracker.FileEntry> currentTabFiles = TalosMain.Instance().FileTracker().getCurrentTabFiles();

    if(currentTabFiles != null) {
        json.writeArrayStart("resourcePaths");
        for (ObjectMap.Entry<FileHandle, FileTracker.FileEntry> currentTabFile : currentTabFiles) {
            json.writeValue(currentTabFile.key.path());
        }
        json.writeArrayEnd();
    }
}