From 6c4a5571895ea1d7c6f42f0605dcb0d995a28c2e Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Sun, 24 Apr 2022 14:21:59 +0200 Subject: [PATCH] chore: update before merging --- .../config-1/locations/location-1/location-1.json | 6 +++--- .../config-1/locations/location-2/location-2.json | 8 ++++---- src/main/java/io/rpg/Initializer.java | 1 - src/main/java/io/rpg/config/ConfigLoader.java | 3 +++ src/main/java/io/rpg/view/GameObjectView.java | 8 +++++++- src/main/java/io/rpg/view/LocationView.java | 7 ++++++- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/configurations/config-1/locations/location-1/location-1.json b/configurations/config-1/locations/location-1/location-1.json index ad57e860..94025965 100644 --- a/configurations/config-1/locations/location-1/location-1.json +++ b/configurations/config-1/locations/location-1/location-1.json @@ -1,8 +1,8 @@ { "tag": "location-1", "objects": [ - { "tag": "object-1", "position": { "row": 0, "col": 5 }, "type": "collectible" }, - { "tag": "object-2", "position": { "row": 1, "col": 3 }, "type": "dialog" } + { "tag": "object-1", "position": { "row": 0, "col": 5 }, "type": "collectible", "assetPath": "assets/someDude.png" }, + { "tag": "object-2", "position": { "row": 1, "col": 3 }, "type": "dialog", "assetPath": "assets/someDude.png" } ], - "backgroundPath": "file:assets/map.png" + "backgroundPath": "assets/map.png" } diff --git a/configurations/config-1/locations/location-2/location-2.json b/configurations/config-1/locations/location-2/location-2.json index dc949d25..2d5eae12 100644 --- a/configurations/config-1/locations/location-2/location-2.json +++ b/configurations/config-1/locations/location-2/location-2.json @@ -1,8 +1,8 @@ { "tag": "location-2", "objects": [ - { "tag": "object-1", "position": { "row": 0, "col": 0 }, "type": "collectible" }, - { "tag": "object-3", "position": { "row": 0, "col": 1 }, "type": "navigable" } + { "tag": "object-1", "position": { "row": 0, "col": 5 }, "type": "collectible", "assetPath": "assets/someDude.png" }, + { "tag": "object-2", "position": { "row": 1, "col": 3 }, "type": "dialog", "assetPath": "assets/someDude.png" } ], - "backgroundPath": "file:assets/map.png" -} \ No newline at end of file + "backgroundPath": "assets/map.png" +} diff --git a/src/main/java/io/rpg/Initializer.java b/src/main/java/io/rpg/Initializer.java index 34a84293..77e325bc 100644 --- a/src/main/java/io/rpg/Initializer.java +++ b/src/main/java/io/rpg/Initializer.java @@ -117,7 +117,6 @@ public static void registerGameObjectViewsToModel(List gameObjects, } } - @Nullable public static LocationView loadLocationViewFromConfig(LocationConfig config) { try { diff --git a/src/main/java/io/rpg/config/ConfigLoader.java b/src/main/java/io/rpg/config/ConfigLoader.java index 2ee4bce1..6919cf26 100644 --- a/src/main/java/io/rpg/config/ConfigLoader.java +++ b/src/main/java/io/rpg/config/ConfigLoader.java @@ -201,6 +201,9 @@ LocationConfig loadLocationConfig(@NotNull String locationTag) throws FileNotFou BufferedReader reader = new BufferedReader(new FileReader(locationConfigJson.toString())); LocationConfig config = gson.fromJson(reader, LocationConfig.class); config.setPath(locationDir); + + logger.info("Path to background for location"); + logger.info(config.getBackgroundPath()); return config; } diff --git a/src/main/java/io/rpg/view/GameObjectView.java b/src/main/java/io/rpg/view/GameObjectView.java index b55aaad7..0ee8ae55 100644 --- a/src/main/java/io/rpg/view/GameObjectView.java +++ b/src/main/java/io/rpg/view/GameObjectView.java @@ -18,7 +18,8 @@ public class GameObjectView extends ImageView public GameObjectView(@NotNull Path assetPath, @NotNull Position position) { this.path = assetPath; - this.setImage(new Image(path.toString())); +// String xdpath = + this.setImage(new Image(resolvePathToJFXFormat(path.toString()))); // todo: better position class this.setX(position.col); this.setY(position.row); @@ -26,6 +27,11 @@ public GameObjectView(@NotNull Path assetPath, @NotNull Position position) { this.setOnMouseClicked(event -> emitOnMouseClickedEvent(new MouseClickedEvent(this, event))); } + public static String resolvePathToJFXFormat(String path) { + return "file:" + path; + } + + @Override public void emitOnMouseClickedEvent(MouseClickedEvent event) { onClickedObservers.forEach(listener -> listener.onMouseClickedEvent(event)); diff --git a/src/main/java/io/rpg/view/LocationView.java b/src/main/java/io/rpg/view/LocationView.java index a3d0b55a..332536fd 100644 --- a/src/main/java/io/rpg/view/LocationView.java +++ b/src/main/java/io/rpg/view/LocationView.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.net.URL; +import java.nio.file.Path; import java.util.HashSet; import java.util.Set; @@ -60,11 +61,15 @@ public static LocationView fromConfig(LocationConfig config) throws IOException LocationView view = loadFromFXML(FXML_URL); System.out.println("BACKGROUND PATH"); System.out.println(config.getBackgroundPath()); - view.getViewModel().setBackground(new Image(config.getBackgroundPath())); + view.getViewModel().setBackground(new Image(resolvePathToJFXFormat(config.getBackgroundPath()))); // todo: na podstawie configu ustawić pola korzystając z view modelu return view; } + public static String resolvePathToJFXFormat(String path) { + return "file:" + path; + } + @Override public void addKeyboardEventObserver(KeyboardEvent.Observer observer) { onKeyPressedObservers.add(observer);