Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions configurations/config-1/locations/location-1/location-1.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 4 additions & 4 deletions configurations/config-1/locations/location-2/location-2.json
Original file line number Diff line number Diff line change
@@ -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"
}
"backgroundPath": "assets/map.png"
}
1 change: 0 additions & 1 deletion src/main/java/io/rpg/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public static void registerGameObjectViewsToModel(List<GameObject> gameObjects,
}
}


@Nullable
public static LocationView loadLocationViewFromConfig(LocationConfig config) {
try {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/rpg/config/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/rpg/view/GameObjectView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ 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);
this.onClickedObservers = new HashSet<>();
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));
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/io/rpg/view/LocationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down