com.badlogic.gdx.utils.ObjectMap Java Examples

The following examples show how to use com.badlogic.gdx.utils.ObjectMap. 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: ThesaurusLoader.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, ThesaurusLoader.ThesaurusParameter parameter) {
    Constructor constructor = new Constructor(ThesaurusData.class);
    Yaml yaml = new Yaml(constructor);
    ObjectMap<String, ThesaurusData> data = new ObjectMap<String, ThesaurusData>();
    for (Object o : yaml.loadAll(resolve(fileName).read())) {
        ThesaurusData description = (ThesaurusData) o;
        data.put(description.key, description);
    }
    if (parameter != null && parameter.other.length > 0) {
        for (String depName : parameter.other) {
            Thesaurus dep = manager.get(depName);
            data.putAll(dep.data);
        }
    }
    thesaurus = new Thesaurus(data);
}
 
Example #2
Source File: Art.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private static void loadMeshesGraphics (boolean mipmap) {
	meshTrackWall = newTexture("data/track/wall_4.png", mipmap);
	meshTrackWall.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);

	meshMissing = newTexture("data/3d/textures/missing-mesh.png", mipmap);

	// car textures
	meshCar = new ObjectMap<String, Texture>();
	meshCar.put("car", newTexture("data/3d/textures/car.png", mipmap));
	meshCar.put("car_yellow", newTexture("data/3d/textures/car_yellow.png", mipmap));
	// meshCar.get("car").setFilter(TextureFilter.Linear, TextureFilter.Linear);
	// meshCar.get("car_yellow").setFilter(TextureFilter.Linear, TextureFilter.Linear);

	// trees
	meshTreeTrunk = newTexture("data/3d/textures/trunk_6_col.png", mipmap);
	meshTreeLeavesSpring = new Texture[7];
	for (int i = 0; i < 7; i++) {
		meshTreeLeavesSpring[i] = newTexture("data/3d/textures/leaves_" + (i + 1) + "_spring_1.png", mipmap);
	}
}
 
Example #3
Source File: RootTable.java    From skin-composer with MIT License 6 votes vote down vote up
public RootTable(Main main) {
    super(main.getSkin());
    this.stage = main.getStage();
    this.main = main;
    
    previewProperties = new ObjectMap<>();
    
    scrollPaneListener = new ScrollPaneListener();
    previewFonts = new Array<>();
    
    main.getAtlasData().produceAtlas();
    
    main.getStage().addListener(new ShortcutListener(this));
    
    filesDroppedListener = (Array<FileHandle> files) -> {
        for (FileHandle fileHandle : files) {
            if (fileHandle.extension().toLowerCase(Locale.ROOT).equals("scmp")) {
                fire(new ScmpDroppedEvent(fileHandle));
                break;
            }
        }
    };
    
    main.getDesktopWorker().addFilesDroppedListener(filesDroppedListener);
}
 
Example #4
Source File: CraftingPane.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public CraftingPane(int elementsCount, Array<Ability> recipes) {
        super(Config.skin);
        this.inputs = new ObjectMap<Actor, ItemIcon>(elementsCount);
        this.count = elementsCount;
        this.recipes = recipes;
//        defaults().pad(2);
        for (int i = 0; i < elementsCount; i++) {
            Image image = new Image(Config.skin, "ui-crafting-slot");
            image.setName("slot#" + i);
            inputs.put(image, null);
            add(image).size(26);
            if (i != elementsCount - 1) {
                add(new Tile("ui-plus")).pad(1);
            } else {
                add(new Tile("ui-equals")).pad(1);
            }
        }
        add(output).size(26);
        setTouchable(Touchable.enabled);
    }
 
Example #5
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 #6
Source File: ServerMessageListener.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void initMatch(PvpPlayState state) {
    Logger.debug("server: init match "+this.state.session.getMode().name);
    PvpMode mode = this.state.session.getMode();
    LevelDescription level = mode.levels.random();
    String levelName = level.name;
    Array<Fraction> fractions = new Array<Fraction>(level.fractions.size);
    for (Fraction fraction : level.fractions) {
        fractions.add(fraction);
    }
    Array<String> ids = this.state.session.getAll().keys().toArray();
    ids.shuffle();
    ObjectMap<String, String> fMap = new ObjectMap<String, String>();
    for (int i = 0; i < ids.size; i++) {
        fMap.put(ids.get(i), fractions.get(i).name);
    }
    int seed = MathUtils.random.nextInt();
    awaitSpawning(state);
    sendToAll(new Init(levelName, fMap, seed));
}
 
Example #7
Source File: SeparatedDataFileResolver.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
private ObjectMap<Integer, ByteBuffer> loadBuffers(FileHandle path) {
	
	if(glModel.buffers != null){
		for(int i=0 ; i<glModel.buffers.size ; i++){
			GLTFBuffer glBuffer = glModel.buffers.get(i);
			ByteBuffer buffer = ByteBuffer.allocate(glBuffer.byteLength);
			buffer.order(ByteOrder.LITTLE_ENDIAN);
			if(glBuffer.uri.startsWith("data:")){
				// data:application/octet-stream;base64,
				String [] headerBody = glBuffer.uri.split(",", 2);
				String header = headerBody[0];
				// System.out.println(header);
				String body = headerBody[1];
				byte [] data = Base64Coder.decode(body);
				buffer.put(data);
			}else{
				FileHandle file = path.child(glBuffer.uri);
				buffer.put(file.readBytes());
			}
			bufferMap.put(i, buffer);
		}
	}
	return bufferMap;
}
 
Example #8
Source File: ServerConnection.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public ServerConnection(ServerMaster master, int tcpPort, int udpPort) throws IOException {
	this.master = master;
	this.server = new Server();
	this.queue = new LinkedBlockingQueue<>();
	this.connectedClients = new ObjectMap<>();

	Register.registerAll(server.getKryo());
	server.start();
	server.bind(tcpPort, udpPort);
	server.addListener(new QueuedListener(this) {
		@Override
		protected void queue(Runnable runnable) {
			queue.add(runnable);
		}
	});
}
 
Example #9
Source File: ClientMessageListener.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void init(final PvpPlayState state) {
    Logger.debug("client: wait for server to init");
    register(Init.class, new IMessageProcessor<Init>() {
        @Override public void receive(IParticipant from, Init message) {
            if (message.version > Config.mobileApi.getVersionCode()) {
                sendToWithCallback(state.server, new UpdateNeeded()).addListener(new IFutureListener<Boolean>() {
                    @Override public void onHappened(Boolean aBoolean) {
                        session.disconnect(false, Config.thesaurus.localize("disconnect-server-needs-update"));
                    }
                });
                return;
            } else if (message.version < Config.mobileApi.getVersionCode()) {
                session.disconnect(false, Config.thesaurus.localize("disconnect-update-needed"));
                return;
            }
            LevelDescription level = (LevelDescription) Config.levels.get(message.level);
            ObjectMap<IParticipant, Fraction> fractions = new ObjectMap<IParticipant, Fraction>();
            for (ObjectMap.Entry<String, String> e : message.fractions.entries()) {
                fractions.put(ClientMessageListener.this.state.session.getAll().get(e.key), Fraction.valueOf(e.value));
            }
            ClientMessageListener.this.state.prepare(level, fractions, message.seed);
            unregister(Init.class);
            awaitSpawns(state);
        }
    });
}
 
Example #10
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 #11
Source File: LevelsLoader.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override @SuppressWarnings("unchecked") public void loadAsync(AssetManager manager, String fileName, FileHandle file, AssetLoaderParameters<Levels> parameter) {
    Yaml yaml = new Yaml();
    ObjectMap<String, BaseLevelDescription> data = new ObjectMap<String, BaseLevelDescription>();
    for (Object o : yaml.loadAll(resolve(fileName).read())) {
        HashMap<String, Object> value = (HashMap<String, Object>) o;
        String type = MapHelper.get(value, "type", "level");
        try {
            BaseLevelDescription desc = types.get(type).getConstructor(Map.class).newInstance(value);
            data.put(desc.name, desc);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    levels = new Levels(data);
    Config.levels = levels;
}
 
Example #12
Source File: FileTracker.java    From talos with Apache License 2.0 6 votes vote down vote up
public void addSavedResourcePathsFor (FileTab currentTab, Array<String> savedResourcePaths) {

        if(savedResourcePaths == null) return;

        final ObjectMap<FileHandle, FileEntry> entries = new ObjectMap<>();
        for (String savedResourcePath : savedResourcePaths) {
            FileHandle fileHandle = Gdx.files.absolute(savedResourcePath);
            FileEntry fileEntry = new FileEntry(fileHandle, new Tracker() {
                @Override
                public void updated (FileHandle handle) {

                }
            });
            entries.put(fileHandle, fileEntry);
        }

        tabMaps.put(currentTab, entries);
    }
 
Example #13
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void setCameras(ObjectMap<Node, Camera> cameras) {
	Array<String> cameraNames = new Array<String>();
	cameraNames.add("");
	for(Entry<Node, Camera> e : cameras){
		cameraNames.add(e.key.id);
	}
	cameraSelector.setItems();
	cameraSelector.setItems(cameraNames);
}
 
Example #14
Source File: Dialog9Patch.java    From skin-composer with MIT License 5 votes vote down vote up
public Dialog9Patch(Main main, ObjectMap<DrawableData, Drawable> drawablePairs) {
    super("", main.getSkin(), "dialog");
    previewBGcolor = new Color(Color.WHITE);
    listeners = new Array<>();
    this.main = main;
    this.drawablePairs = drawablePairs;
    
    var cursor = Utils.textureRegionToCursor(main.getSkin().getRegion("cursor_resize_horizontal"), 16, 16);
    horizontalResizeListener = new ResizeFourArrowListener(cursor);

    cursor = Utils.textureRegionToCursor(main.getSkin().getRegion("cursor_resize_vertical"), 16, 16);
    verticalResizeListener = new ResizeFourArrowListener(cursor);

    cursor = Utils.textureRegionToCursor(main.getSkin().getRegion("cursor_resize_nw"), 16, 16);
    nwResizeListener = new ResizeFourArrowListener(cursor);

    cursor = Utils.textureRegionToCursor(main.getSkin().getRegion("cursor_resize_ne"), 16, 16);
    neResizeListener = new ResizeFourArrowListener(cursor);

    filesDroppedListener = (Array<FileHandle> files) -> {
        if (files.size > 0 && files.first().extension().equalsIgnoreCase("png")) {
            Runnable runnable = () -> {
                Gdx.app.postRunnable(() -> {
                    loadImage(files.first());
                });
            };
            
            main.getDialogFactory().showDialogLoading(runnable);
        }
    };
    
    main.getDesktopWorker().addFilesDroppedListener(filesDroppedListener);
    
    populate();
}
 
Example #15
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 #16
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 #17
Source File: RoomController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onRoomConnected(final int statusCode, final Room room) {
    Logger.log("room connected, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK));
    if (statusCode != GamesStatusCodes.STATUS_OK) {
        die(false, Config.thesaurus.localize("disconnect-game-services-error"));
        return;
    }
    RoomController.this.room = room;
    session.setVariant(room.getVariant());
    String playerId = room.getParticipantId(Games.Players.getCurrentPlayerId(multiplayer.client));

    for (Participant participant : room.getParticipants()) {
        if (participant.getStatus() != Participant.STATUS_JOINED)
            continue;
        if (participant.getParticipantId().equals(playerId)) {
            me = new MultiplayerParticipant(participant);
        } else {
            others.add(new MultiplayerParticipant(participant));
        }
    }
    all.put(me.getId(), me);
    for (MultiplayerParticipant p : others) {
        all.put(p.getId(), p);
    }
    publicOthers = new ObjectSet<IParticipant>(others);
    publicAll = new ObjectMap<String, IParticipant>(all);

    multiplayer.updateInvites();
    Logger.log("  - room: " + RoomController.this.toString(room));
}
 
Example #18
Source File: LocLabel.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public void setParams(ObjectMap<String, String> params) {
    if (this.params.equals(params))
        return;
    this.params = params;
    if (getStage() != null) {
        Config.thesaurus.register(this, key, params);
    }
}
 
Example #19
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 #20
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 #21
Source File: NetServer.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public NetServer() {
	clientMap = new ObjectMap<>();
	server = new Server(NetManager.writeBufferSize, NetManager.objectBufferSize);
	NetManager.registerKryoClasses(server.getKryo());
	try {
		server.bind(NetManager.tcpPort, NetManager.udpPort);
		server.start();
		server.addListener(createListener(simulateLag));
		Log.debug("server is listening at: " + NetManager.host + ":" + NetManager.tcpPort);
	} catch (IOException e) {
		Log.error(e.toString());
		throw new GdxRuntimeException(e);
	}
}
 
Example #22
Source File: DiceHeroes.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void playCampaignLevel(LevelDescription level) {

        Player protagonist = PlayerHelper.protagonist();
        for (Die die : userData.dice()) {
            protagonist.addDie(die);
        }
        protagonist.setPotions(userData.potions);
        protagonist.tutorialProvider = new UserDataTutorialProvider(userData);
        Player antagonist = PlayerHelper.antagonist();
        ObjectMap<Fraction, Player> players = new ObjectMap<Fraction, Player>();
        players.put(protagonist.fraction, protagonist);
        players.put(antagonist.fraction, antagonist);
        setState(new PvePlayState(this, protagonist, players, PlayerHelper.defaultColors, level, PvePlayState.GameState.PLACE, new PvePlayStateCallback(this, level)));
    }
 
Example #23
Source File: BehaviorTreeLibrary.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
	private BehaviorTreeLibrary (FileHandleResolver resolver, AssetManager assetManager, int parseDebugLevel) {
		this.resolver = resolver;
//		this.assetManager = assetManager;
		this.repository = new ObjectMap<String, BehaviorTree<?>>();
		this.parser = new BehaviorTreeParser(parseDebugLevel);
	}
 
Example #24
Source File: LevelResult.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public LevelResult(ObjectIntMap<Die> addedExperience,
                   ObjectMap<Fraction, Player> players,
                   Player viewer) {
    this.addedExperience = addedExperience;
    this.players = players;
    this.viewer = viewer;
}
 
Example #25
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 #26
Source File: Thesaurus.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public void register(Localizable localizable, String key, ObjectMap<String, String> params) {
    LocalizationData registration = registrations.get(localizable);
    if (registration != null) {
        if (registration.key.equals(key) && registration.params.equals(params))
            return;
        registration.key = key;
        registration.params = params == null ? EMPTY : params;
        localizable.localize(localize(key, params));
        return;
    }
    registrations.put(localizable, new LocalizationData(key, params == null ? EMPTY : params));
    localizable.localize(localize(key, params));
}
 
Example #27
Source File: World.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public World(Player viewer, ObjectMap<Fraction, Player> players, PlayerColors playerColors, LevelDescription level, Stage stage) {
    this.viewer = viewer;
    this.players = players;
    this.playerColors = playerColors;
    this.level = level;
    this.stage = stage;
    width = level.width;
    height = level.height;
}
 
Example #28
Source File: AreaOfAttackResult.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public AreaOfAttackResult(Ability ability, Creature creature, Array<Creature> targets, AttackType attackType, int level) {
    this.ability = ability;
    this.creature = creature;
    this.targets = targets;
    this.attackType = attackType;
    this.level = level;
    this.effects = new ObjectMap<Creature, CreatureEffect>();
    for (Creature c : targets) {
        CreatureEffect effect = new DelayedAttackBonusEffect(ability, attackType, level);
        effects.put(c, effect);
    }
    casterEffect = new RemoveEffectsEffect(effects);
}
 
Example #29
Source File: PlistReader.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
public ObjectMap<String, Object> dictionaryWithContentsOfFile(FileHandle handle) {
    try {
        this.parse(handle);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return m_pCurDict;
}
 
Example #30
Source File: ResourceLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public ResourceLoader(FileLocation fileLocation, FileHandle resourceXml) throws IOException {
	this.fileLocation = fileLocation;
	regions = new ObjectMap<>();
	anims = new ObjectMap<>();
	skins = new ObjectMap<>();

	Element resources = new XmlReader().parse(resourceXml);
	readResourcesTag(resources);
}