-
Notifications
You must be signed in to change notification settings - Fork 0
@co012/RPG-93 widac lokacje w okienku #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| # | ||
| .gradle/ | ||
| build/ | ||
| bin/ | ||
|
|
||
| # Explicitly specifed as local | ||
| # | ||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "location-1", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 5 }, "type": "collectible" }, | ||
| { "tag": "object-2", "position": { "row": 1, "col": 3 }, "type": "interactive" } | ||
| ] | ||
| } |
5 changes: 5 additions & 0 deletions
5
configurations/config-1/locations/location-1/objects/object-1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "tag": "object-1", | ||
| "assetPath": "/path/to/the/asset", | ||
| "type": "" | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "location-2", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 } }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 } } | ||
| ] | ||
| } |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "GameByConfig1", | ||
| "locations": [ | ||
| "location-1", | ||
| "location-2" | ||
| ] | ||
| } |
7 changes: 7 additions & 0 deletions
7
configurations/unit-test-configuration/locations/location-1/location-1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "location-1", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 5 } }, | ||
| { "tag": "object-2", "position": { "row": 1, "col": 3 } } | ||
| ] | ||
| } |
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions
7
configurations/unit-test-configuration/locations/location-2/location-2.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "location-2", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 } }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 } } | ||
| ] | ||
| } |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "tag": "test-tag", | ||
| "locations": [ | ||
| "location-1", | ||
| "location-2" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Game configuration | ||
|
|
||
| Configuration directory should include: | ||
|
|
||
| 1. `root.json` file | ||
| 2. `locations` subdirectory | ||
|
|
||
| e.g. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,32 @@ | ||
| package io.rpg; | ||
|
|
||
| import io.rpg.config.ConfigLoader; | ||
| import io.rpg.gui.DisplayLayer; | ||
| import io.rpg.model.GameObjectStandIn; | ||
| import javafx.application.Application; | ||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXMLLoader; | ||
| import javafx.scene.Scene; | ||
| import javafx.scene.image.Image; | ||
| import javafx.stage.Stage; | ||
| import javafx.util.Pair; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
|
|
||
| public class HelloApplication extends Application { | ||
| @Override | ||
| public void start(Stage stage) throws IOException { | ||
| FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); | ||
| Scene scene = new Scene(fxmlLoader.load(), 320, 240); | ||
| stage.setTitle("Hello!"); | ||
| stage.setScene(scene); | ||
| stage.show(); | ||
| } | ||
| Image someMap = new Image("C:\\Dev\\rpg-io\\assets\\map.png"); | ||
| Image someMap10x10 = new Image("C:\\Dev\\rpg-io\\assets\\map10x10.png"); | ||
| Image someDude1 = new Image("C:\\Dev\\rpg-io\\assets\\someDude.png"); | ||
| Image someDude2 = new Image("C:\\Dev\\rpg-io\\assets\\someDudeButGreen.png"); | ||
|
|
||
| public static void main(String[] args) { | ||
| launch(); | ||
| } | ||
| DisplayLayer displayLayer = new DisplayLayer(stage); | ||
| displayLayer.showLocation() | ||
| .setBackgroundImage(someMap) | ||
| .addMapObject(new GameObjectStandIn(new Pair<>(0,0), someDude1)) | ||
| .addMapObject(new GameObjectStandIn(new Pair<>(0,5), someDude1)) | ||
| .addMapObject(new GameObjectStandIn(new Pair<>(5,5), someDude2)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package io.rpg.config; | ||
|
|
||
| final public class ConfigConstants { | ||
| public static final String ROOT = "root.json"; | ||
| public static final String LOCATIONS_DIR = "locations"; | ||
| public static final String OBJECTS_DIR = "objects"; | ||
| public static final String ASSETS_DIR = "resources"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| package io.rpg.config; | ||
|
|
||
| import com.google.gson.Gson; | ||
|
|
||
| import io.rpg.model.GameWorldConfig; | ||
| import io.rpg.model.location.LocationConfig; | ||
|
|
||
| import io.rpg.model.object.GameObjectConfig; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.FileReader; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
||
| public class ConfigLoader { | ||
| @NotNull | ||
| private final Gson gson; | ||
|
|
||
| @NotNull | ||
| private final Path pathToConfigDir; | ||
|
|
||
| @NotNull | ||
| private final Path pathToRootFile; | ||
|
|
||
| @NotNull | ||
| private final Path pathToLocationsDir; | ||
|
|
||
| public static final String ERR_INVALID_CFG_DIR_PATH = "Could not resolve config directory." + | ||
| " Make sure that the config dir path is correct"; | ||
|
|
||
| public static final String ERR_ROOT_FNF = ConfigConstants.ROOT + | ||
| " file was not found inside config directory. Make sure that the file exists and is named properly"; | ||
|
|
||
| public static final String ERR_LOCATIONS_DIR_FNF = ConfigConstants.LOCATIONS_DIR + | ||
| " directory was not found inside configuration directory"; | ||
|
|
||
| public static final String ERR_LOCATION_DIR_FNF_FOR_TAG = | ||
| "Directory was not found for location with tag: "; | ||
|
|
||
| public static final String ERR_LOCATION_CFG_NR_FOR_TAG = | ||
| "Configuration file was not found for location: "; | ||
|
|
||
| @NotNull | ||
| private final Logger logger; | ||
|
|
||
| public ConfigLoader(@NotNull String configDirPath) { | ||
| logger = LogManager.getLogger(ConfigLoader.class); | ||
|
|
||
| logger.info("Initializing"); | ||
|
|
||
| pathToConfigDir = Path.of(configDirPath); | ||
| pathToRootFile = pathToConfigDir.resolve(ConfigConstants.ROOT); | ||
| pathToLocationsDir = pathToConfigDir.resolve(ConfigConstants.LOCATIONS_DIR); | ||
| gson = new Gson(); | ||
|
|
||
| validate(); | ||
| } | ||
|
|
||
| public void load() { | ||
| logger.info("Load"); | ||
|
|
||
| GameWorldConfig config; | ||
| try { | ||
| config = loadGameWorldConfig(); | ||
|
|
||
| logger.info("GameWorldConfig loaded"); | ||
| logger.info(config.toString()); | ||
|
|
||
| } catch (FileNotFoundException e) { | ||
| throw new RuntimeException(ERR_ROOT_FNF); | ||
| } | ||
|
|
||
| assert config.getLocations().size() > 0 : "Configuration must specify locations"; | ||
|
|
||
| for (String locationTag : config.getLocations()) { | ||
| try { | ||
| logger.info("Loading location config for tag: " + locationTag); | ||
|
|
||
| LocationConfig locationConfig = loadLocationConfig(locationTag); | ||
|
|
||
| // todo: this should be called in loadLocationConfig method? | ||
| // locationConfig.validate(); | ||
|
|
||
| logger.info("Location config loaded for tag: " + locationTag); | ||
| logger.info(locationConfig.toString()); | ||
|
|
||
|
|
||
| assert locationConfig.getPath() != null : "Path to location dir must be set in its loader"; | ||
| Path objectsDir = locationConfig.getPath().resolve(ConfigConstants.OBJECTS_DIR); | ||
|
|
||
| for (GameObjectConfig gameObjectConfig : locationConfig.getObjects()) { | ||
| try { | ||
| gameObjectConfig.validate(); | ||
| } catch (Exception ex) { | ||
| String exceptionMessage = ex.getMessage(); | ||
|
|
||
| logger.warn("Validation for game object config with tag: " + | ||
| gameObjectConfig.getTag() + " failed." + | ||
| (exceptionMessage != null ? "Reason: " + exceptionMessage : "No reason provided")); | ||
| } | ||
|
|
||
| // Path GameObjectConfig | ||
|
|
||
| } | ||
|
|
||
| } catch (FileNotFoundException e) { | ||
| logger.warn("Failed to load location config for tag: " + locationTag); | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @NotNull | ||
| GameWorldConfig loadGameWorldConfig() throws FileNotFoundException { | ||
| logger.info("Loading game world config"); | ||
| BufferedReader reader = new BufferedReader(new FileReader(pathToRootFile.toString())); | ||
| GameWorldConfig config = gson.fromJson(reader, GameWorldConfig.class); | ||
|
|
||
| // todo: validate input | ||
| // config.validate(); | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| LocationConfig loadLocationConfig(@NotNull String locationTag) throws FileNotFoundException { | ||
| logger.info("Loading location: " + locationTag); | ||
|
|
||
| Path locationDir = pathToLocationsDir.resolve(locationTag); | ||
|
|
||
| if (!Files.isDirectory(locationDir)) { | ||
| logger.error(ERR_LOCATION_DIR_FNF_FOR_TAG + locationTag); | ||
| throw new FileNotFoundException(ERR_LOCATION_DIR_FNF_FOR_TAG + locationTag); | ||
| } | ||
|
|
||
| Path locationConfigJson = locationDir.resolve(locationTag + ".json"); | ||
|
|
||
| if (!Files.isReadable(locationConfigJson)) { | ||
| logger.error(ERR_LOCATION_CFG_NR_FOR_TAG + locationTag); | ||
| throw new RuntimeException(ERR_LOCATION_DIR_FNF_FOR_TAG + locationTag); | ||
| } | ||
|
|
||
| BufferedReader reader = new BufferedReader(new FileReader(locationConfigJson.toString())); | ||
| LocationConfig config = gson.fromJson(reader, LocationConfig.class); | ||
| config.setPath(locationDir); | ||
| return config; | ||
| } | ||
|
|
||
| public void validate() { | ||
| if (!Files.isDirectory(pathToConfigDir)) { | ||
| logger.error(ERR_INVALID_CFG_DIR_PATH); | ||
| throw new IllegalArgumentException(ERR_INVALID_CFG_DIR_PATH); | ||
| } else if (!Files.isReadable(pathToRootFile)) { | ||
| logger.error(ERR_ROOT_FNF); | ||
| throw new IllegalArgumentException(ERR_ROOT_FNF); | ||
| } else if (!Files.isDirectory(pathToLocationsDir)) { | ||
| logger.error(ERR_LOCATIONS_DIR_FNF); | ||
| throw new IllegalArgumentException(ERR_LOCATIONS_DIR_FNF); | ||
| } | ||
| } | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package io.rpg.gui; | ||
|
|
||
| import io.rpg.gui.model.LocationModel; | ||
| import javafx.fxml.Initializable; | ||
| import javafx.scene.Scene; | ||
| import javafx.stage.Stage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.util.ResourceBundle; | ||
|
|
||
| public class DisplayLayer { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pomyślałbym o innej nazwie dla tej klasy, bo nie wiadomo co robi |
||
| private final Stage mainStage; | ||
| private final LocationController locationController; | ||
|
|
||
| public DisplayLayer(Stage mainStage) throws IOException { | ||
| this.mainStage = mainStage; | ||
| mainStage.show(); | ||
| locationController = LocationController.load(); | ||
| } | ||
|
|
||
|
|
||
| public LocationModel showLocation(){ | ||
| // maybe initialize the scene only once | ||
| mainStage.setScene(locationController.getScene()); | ||
| return locationController.getModel() | ||
| .clear(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zmień na ścieżki względne