Skip to content

Commit

Permalink
I think the text parser components went wrong, corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Oct 20, 2024
1 parent dc0c75f commit 80b0353
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 66 deletions.
3 changes: 2 additions & 1 deletion src/toniarts/openkeeper/game/state/MainMenuState.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import toniarts.openkeeper.view.PlayerEntityViewState;
import toniarts.openkeeper.view.map.MapViewController;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.TextParserService;
import toniarts.openkeeper.world.room.control.FrontEndLevelControl;

/**
Expand Down Expand Up @@ -161,7 +162,7 @@ protected void updateProgress(float progress) {
if (loadingScreen != null) {
loadingScreen.setProgress(1.0f);
}
mainMenuEntityViewState = new MainMenuEntityViewState(kwdFile, assetManager, mainMenuEntityData, Player.KEEPER1_ID, null, menuNode);
mainMenuEntityViewState = new MainMenuEntityViewState(kwdFile, assetManager, mainMenuEntityData, Player.KEEPER1_ID, new TextParserService(gameController.getGameWorldController().getMapController()), menuNode);
mainMenuEntityViewState.setEnabled(false);
app.getStateManager().attach(mainMenuEntityViewState);

Expand Down
8 changes: 4 additions & 4 deletions src/toniarts/openkeeper/view/PlayerEntityViewState.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private Spatial createObjectModel(Entity e) {
if (objectViewState != null) {
result = objectLoader.load(assetManager, objectViewState);
if (result != null) {
EntityViewControl control = new ObjectViewControl(e.getId(), entityData, kwdFile.getObject(objectViewState.objectId), objectViewState, assetManager, textParser);
EntityViewControl control = new ObjectViewControl(e.getId(), entityData, kwdFile.getObject(objectViewState.objectId), objectViewState, assetManager, textParser.getObjectTextParser());
result.addControl(control);

result.setCullHint(objectViewState.visible ? Spatial.CullHint.Inherit : Spatial.CullHint.Always);
Expand Down Expand Up @@ -222,7 +222,7 @@ private Spatial createCreatureModel(Entity e) {
Creature creature = kwdFile.getCreature(creatureViewState.creatureId);
result = creatureLoader.load(assetManager, creatureViewState);
if (result != null) {
EntityViewControl control = new CreatureViewControl(e.getId(), entityData, creature, creatureViewState.state, assetManager, textParser);
EntityViewControl control = new CreatureViewControl(e.getId(), entityData, creature, creatureViewState.state, assetManager, textParser.getCreatureTextParser());
result.addControl(control);

CreatureFlowerControl flowerControl = new CreatureFlowerControl(e.getId(), entityData, creature, assetManager);
Expand Down Expand Up @@ -253,7 +253,7 @@ private Spatial createDoorModel(Entity e) {
if (doorViewState != null) {
Door door = kwdFile.getDoorById(doorViewState.doorId);
result = doorLoader.load(assetManager, doorViewState);
EntityViewControl control = new DoorViewControl(e.getId(), entityData, door, doorViewState, assetManager, textParser, kwdFile.getObject(door.getKeyObjectId()));
EntityViewControl control = new DoorViewControl(e.getId(), entityData, door, doorViewState, assetManager, textParser.getDoorTextParser(), kwdFile.getObject(door.getKeyObjectId()));
result.addControl(control);

DoorFlowerControl flowerControl = new DoorFlowerControl(e.getId(), entityData, door, assetManager);
Expand Down Expand Up @@ -283,7 +283,7 @@ private Spatial createTrapModel(Entity e) {
if (trapViewState != null) {
Trap trap = kwdFile.getTrapById(trapViewState.trapId);
result = trapLoader.load(assetManager, trapViewState);
EntityViewControl control = new TrapViewControl(e.getId(), entityData, trap, trapViewState, assetManager, textParser);
EntityViewControl control = new TrapViewControl(e.getId(), entityData, trap, trapViewState, assetManager, textParser.getTrapTextParser());
result.addControl(control);

TrapFlowerControl flowerControl = new TrapFlowerControl(e.getId(), entityData, trap, assetManager);
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/view/PlayerInteractionState.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private boolean isInteractable() {
//tooltip.setText(room.getTooltip(player.getPlayerId()));
tooltip.setText("");
} else {
tooltip.setText(textParser.parseText(Utils.getMainTextResourceBundle().getString(Integer.toString(terrain.getTooltipStringId())), tile));
tooltip.setText(textParser.getMapTileTextParser().parseText(Utils.getMainTextResourceBundle().getString(Integer.toString(terrain.getTooltipStringId())), tile));
}
} else {
tooltip.setText("");
Expand Down
4 changes: 2 additions & 2 deletions src/toniarts/openkeeper/view/control/CreatureViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import toniarts.openkeeper.tools.convert.map.Creature;
import toniarts.openkeeper.utils.Utils;
import toniarts.openkeeper.view.animation.AnimationLoader;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.EntityTextParser;

/**
* View control that is intended specifically for creatures
Expand All @@ -40,7 +40,7 @@
public class CreatureViewControl extends EntityViewControl<Creature, Creature.AnimationType> {

public CreatureViewControl(EntityId entityId, EntityData entityData, Creature data, Creature.AnimationType animation,
AssetManager assetManager, TextParser textParser) {
AssetManager assetManager, EntityTextParser<Creature> textParser) {
super(entityId, entityData, data, animation, assetManager, textParser);
}

Expand Down
4 changes: 2 additions & 2 deletions src/toniarts/openkeeper/view/control/DoorViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import toniarts.openkeeper.utils.AssetUtils;
import toniarts.openkeeper.utils.Utils;
import toniarts.openkeeper.view.animation.AnimationLoader;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.EntityTextParser;

/**
* View control that is intended specifically for doors
Expand All @@ -45,7 +45,7 @@ public class DoorViewControl extends EntityViewControl<Door, DoorViewState> {
private boolean initialized = false;

public DoorViewControl(EntityId entityId, EntityData entityData, Door data, DoorViewState viewState, AssetManager assetManager,
TextParser textParser, GameObject lockObject) {
EntityTextParser<Door> textParser, GameObject lockObject) {
super(entityId, entityData, data, viewState, assetManager, textParser);

this.lockObject = lockObject;
Expand Down
6 changes: 3 additions & 3 deletions src/toniarts/openkeeper/view/control/EntityViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import toniarts.openkeeper.utils.AssetUtils;
import toniarts.openkeeper.view.animation.AnimationControl;
import static toniarts.openkeeper.view.map.MapViewController.COLOR_FLASH;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.EntityTextParser;

/**
* General entity controller, a bridge between entities and view
Expand All @@ -58,14 +58,14 @@ public abstract class EntityViewControl<T, S> extends AbstractControl implements
protected S currentState;
protected S targetState;
protected final AssetManager assetManager;
protected final TextParser textParser;
protected final EntityTextParser<T> textParser;
protected boolean isAnimationPlaying = false;

private static final Collection<Class<? extends EntityComponent>> WATCHED_COMPONENTS = Arrays.asList(Interaction.class, Owner.class);

private boolean active = false;

public EntityViewControl(EntityId entityId, EntityData entityData, T data, S state, AssetManager assetManager, TextParser textParser) {
public EntityViewControl(EntityId entityId, EntityData entityData, T data, S state, AssetManager assetManager, EntityTextParser<T> textParser) {
this.entityId = entityId;
this.currentState = state;
this.targetState = state;
Expand Down
4 changes: 2 additions & 2 deletions src/toniarts/openkeeper/view/control/ObjectViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import toniarts.openkeeper.tools.convert.map.GameObject;
import toniarts.openkeeper.utils.Utils;
import toniarts.openkeeper.view.animation.AnimationLoader;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.EntityTextParser;

/**
* View control that is intended specifically for objects
Expand All @@ -39,7 +39,7 @@ public class ObjectViewControl extends EntityViewControl<GameObject, ObjectViewS
private boolean initialized = false;

public ObjectViewControl(EntityId entityId, EntityData entityData, GameObject data, ObjectViewState state,
AssetManager assetManager, TextParser textParser) {
AssetManager assetManager, EntityTextParser<GameObject> textParser) {
super(entityId, entityData, data, state, assetManager, textParser);
}

Expand Down
4 changes: 2 additions & 2 deletions src/toniarts/openkeeper/view/control/TrapViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import toniarts.openkeeper.tools.convert.map.Trap;
import toniarts.openkeeper.utils.AssetUtils;
import toniarts.openkeeper.utils.Utils;
import toniarts.openkeeper.view.text.TextParser;
import toniarts.openkeeper.view.text.EntityTextParser;

/**
* View control that is intended specifically for traps
Expand All @@ -40,7 +40,7 @@ public class TrapViewControl extends EntityViewControl<Trap, TrapViewState> {
private boolean initialized = false;

public TrapViewControl(EntityId entityId, EntityData entityData, Trap data, TrapViewState viewState,
AssetManager assetManager, TextParser textParser) {
AssetManager assetManager, EntityTextParser<Trap> textParser) {
super(entityId, entityData, data, viewState, assetManager, textParser);
}

Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/view/text/CreatureTextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static String getTaskTooltip(TaskComponent taskComponent, IMapInformatio
}

@Override
protected Collection<Class<? extends EntityComponent>> getWatchedComponents() {
public Collection<Class<? extends EntityComponent>> getWatchedComponents() {
Collection<Class<? extends EntityComponent>> components = super.getWatchedComponents();

components.add(TaskComponent.class);
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/view/text/DoorTextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected String getReplacement(int index, Entity entity, Door door) {
}

@Override
protected Collection<Class<? extends EntityComponent>> getWatchedComponents() {
public Collection<Class<? extends EntityComponent>> getWatchedComponents() {
Collection<Class<? extends EntityComponent>> components = super.getWatchedComponents();

components.add(DoorComponent.class);
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/view/text/EntityTextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected String getReplacement(int index, Entity entity, T dataObject) {
return "Parameter " + index + " not implemented!";
}

protected Collection<Class<? extends EntityComponent>> getWatchedComponents() {
public Collection<Class<? extends EntityComponent>> getWatchedComponents() {
List<Class<? extends EntityComponent>> components = new ArrayList<>();
components.add(Health.class);
components.add(Gold.class);
Expand Down
21 changes: 5 additions & 16 deletions src/toniarts/openkeeper/view/text/TextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,21 @@
*/
package toniarts.openkeeper.view.text;

import com.simsilica.es.Entity;
import com.simsilica.es.EntityComponent;
import java.util.Collection;
import toniarts.openkeeper.game.map.IMapTileInformation;
import toniarts.openkeeper.tools.convert.map.Creature;
import toniarts.openkeeper.tools.convert.map.Door;
import toniarts.openkeeper.tools.convert.map.GameObject;
import toniarts.openkeeper.tools.convert.map.Trap;

/**
* Provides text parsing services for users
*
* @author Toni Helenius <[email protected]>
*/
public interface TextParser {

String parseText(String text, Entity entity, Creature creature);

String parseText(String text, Entity entity, Trap trap);
CreatureTextParser getCreatureTextParser();

String parseText(String text, Entity entity, Door door);
TrapTextParser getTrapTextParser();

String parseText(String text, Entity entity, GameObject gameObject);
DoorTextParser getDoorTextParser();

String parseText(String text, IMapTileInformation mapTile);
ObjectTextParser getObjectTextParser();

Collection<Class<? extends EntityComponent>> getWatchedComponents();
MapTileTextParser getMapTileTextParser();

}
40 changes: 10 additions & 30 deletions src/toniarts/openkeeper/view/text/TextParserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@
*/
package toniarts.openkeeper.view.text;

import com.simsilica.es.Entity;
import com.simsilica.es.EntityComponent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import toniarts.openkeeper.game.map.IMapInformation;
import toniarts.openkeeper.game.map.IMapTileInformation;
import toniarts.openkeeper.tools.convert.map.Creature;
import toniarts.openkeeper.tools.convert.map.Door;
import toniarts.openkeeper.tools.convert.map.GameObject;
import toniarts.openkeeper.tools.convert.map.Trap;

/**
* A kind of facade to the different kind of parsers. Many of them share the
Expand All @@ -51,37 +41,27 @@ public TextParserService(IMapInformation mapInformation) {
}

@Override
public String parseText(String text, Entity entity, Creature creature) {
return creatureTextParser.parseText(text, entity, creature);
public CreatureTextParser getCreatureTextParser() {
return creatureTextParser;
}

@Override
public String parseText(String text, Entity entity, Trap trap) {
return trapTextParser.parseText(text, entity, trap);
public TrapTextParser getTrapTextParser() {
return trapTextParser;
}

@Override
public String parseText(String text, Entity entity, Door door) {
return doorTextParser.parseText(text, entity, door);
public DoorTextParser getDoorTextParser() {
return doorTextParser;
}

@Override
public String parseText(String text, Entity entity, GameObject gameObject) {
return objectTextParser.parseText(text, entity, gameObject);
public ObjectTextParser getObjectTextParser() {
return objectTextParser;
}

@Override
public String parseText(String text, IMapTileInformation mapTile) {
return mapTileTextParser.parseText(text, mapTile);
public MapTileTextParser getMapTileTextParser() {
return mapTileTextParser;
}

@Override
public Collection<Class<? extends EntityComponent>> getWatchedComponents() {
List<Class<? extends EntityComponent>> components = new ArrayList<>();

components.addAll(creatureTextParser.getWatchedComponents());

return components;
}

}

0 comments on commit 80b0353

Please sign in to comment.