-
Notifications
You must be signed in to change notification settings - Fork 0
BREAKING: Arch proposal #13
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
34 commits
Select commit
Hold shift + click to select a range
f909673
chore: Massive update...
kkafar 97168b4
BREAKING CHANGES: Arch proposal
kkafar eb85cb5
chore: rename io.rpg.torefract -> io.rpg.torefact
kkafar b5a0c8a
refact: rename PointsPopupController -> PointsPopupViewModel
kkafar b69f869
refact: add comments & change method names in ConfigLoader
kkafar 8eb9b59
refact: add comments tgo GameObjectConfig
kkafar 25a08a5
refact: add comments to GameWorldConfig
kkafar de086eb
chore: make ConfigLoader#{loadGameWorldConfig,loadLocationConfig}
kkafar a958a33
chore: add generic class describing operation result
kkafar f1219eb
chore: add Optional returning getters to Result
kkafar 211f928
fix: revert changes from #de086eb
kkafar 7fe4bd6
chore: update configuration files
kkafar e774cfb
chore: improve error handlign in config module via Result class
kkafar 04292a5
feat: add helper methods to Result class
kkafar 77279ff
chore: add builder to the Game class
kkafar 2223fa0
refact: adapt Main to new Result based interface
kkafar 4a27c40
feat: add builder to the Controller
kkafar 41f013f
chore: update unit test configuration
kkafar a9d9c92
fix: make unit tests pass
kkafar f85525c
chore: Update observer schema before refractoring
kkafar 58ed78f
Merge branch 'master' into @kkafar/arch-proposal
kkafar 1af5380
docs: add more comments to GameWorldConfig
kkafar 8f82497
chore: make GameObjectConfig#valide method return Result
kkafar 8af785a
chore: Cleanup ConfigLoader
kkafar 9f65d92
chore: minor fixes & apply linter
kkafar c900f2d
refact: apply style suggestions
kkafar 52cc4f6
Merge branch 'master' into @kkafar/arch-proposal
kkafar 640720c
chore: improve observer model
kkafar d798479
refact: move event types to model package
kkafar 9441e46
refact: small style change
kkafar 0f33369
chore: add GameObjectStateChange event interface
kkafar ebdde50
chore: add LocationModelStateChange event interface
kkafar ccd3281
chore: add LocattionModelStateChange event interface
kkafar ac69662
fix: update interface implementations
kkafar 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
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| { | ||
| "tag": "location-2", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 } }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 } } | ||
| ] | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 }, "type": "collectible" }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 }, "type": "navigable" } | ||
| ], | ||
| "backgroundPath": "file:assets/map.png" | ||
| } |
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": "" | ||
| } |
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-3", | ||
| "assetPath": "/path/to/the/asset", | ||
| "type": "" | ||
| } |
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,7 +1,8 @@ | ||
| { | ||
| "tag": "GameByConfig1", | ||
| "locations": [ | ||
| "locationTags": [ | ||
| "location-1", | ||
| "location-2" | ||
| ] | ||
| ], | ||
| "rootLocation": "location-1" | ||
| } |
9 changes: 5 additions & 4 deletions
9
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| { | ||
| "tag": "location-1", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 5 } }, | ||
| { "tag": "object-2", "position": { "row": 1, "col": 3 } } | ||
| ] | ||
| } | ||
| { "tag": "object-1", "position": { "row": 0, "col": 5 }, "type": "collectible" }, | ||
| { "tag": "object-2", "position": { "row": 1, "col": 3 }, "type": "interactive" } | ||
| ], | ||
| "backgroundPath": "file:assets/map.png" | ||
| } |
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": "" | ||
| } |
7 changes: 4 additions & 3 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| { | ||
| "tag": "location-2", | ||
| "objects": [ | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 } }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 } } | ||
| ] | ||
| { "tag": "object-1", "position": { "row": 0, "col": 0 }, "type": "collectible" }, | ||
| { "tag": "object-3", "position": { "row": 0, "col": 1 }, "type": "navigable" } | ||
| ], | ||
| "backgroundPath": "file:assets/map.png" | ||
| } |
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 removed
0
configurations/unit-test-configuration/locations/location-2/objects/object-2.json
Empty file.
5 changes: 5 additions & 0 deletions
5
configurations/unit-test-configuration/locations/location-2/objects/object-3.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-3", | ||
| "assetPath": "/path/to/the/asset", | ||
| "type": "" | ||
| } |
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,7 +1,8 @@ | ||
| { | ||
| "tag": "test-tag", | ||
| "locations": [ | ||
| "locationTags": [ | ||
| "location-1", | ||
| "location-2" | ||
| ] | ||
| ], | ||
| "rootLocation": "location-1" | ||
| } |
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,44 @@ | ||
| package io.rpg; | ||
|
|
||
| import io.rpg.controller.Controller; | ||
| import javafx.scene.Scene; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public class Game { | ||
| private Controller controller; | ||
|
|
||
| private Game() { | ||
|
|
||
| } | ||
|
|
||
| public void setLocationControllerForLocationTag(String tag) { | ||
| // tutaj przyda sie hashmapa: nazwa lokacji -> kontroller | ||
| } | ||
|
|
||
| public Scene getWorldView() { | ||
| return controller.getView(); | ||
| } | ||
|
|
||
| public void setController(Controller controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private final Game game; | ||
|
|
||
| public Builder() { | ||
| game = new Game(); | ||
| } | ||
|
|
||
| public Game build() { | ||
| assert game.controller != null : "Attempt to build Game object without controller"; | ||
| return game; | ||
| } | ||
|
|
||
| public Builder setController(Controller controller) { | ||
| assert controller != null : "Attempt to set null controller"; | ||
| game.setController(controller); | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,106 @@ | ||
| package io.rpg; | ||
|
|
||
| import io.rpg.config.ConfigLoader; | ||
| import io.rpg.controller.Controller; | ||
| import io.rpg.config.model.GameWorldConfig; | ||
| import io.rpg.config.model.LocationConfig; | ||
| import io.rpg.model.location.LocationModel; | ||
| import io.rpg.model.object.GameObject; | ||
| import io.rpg.config.model.GameObjectConfig; | ||
| import io.rpg.util.Result; | ||
| import io.rpg.view.LocationView; | ||
| import javafx.stage.Stage; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
|
|
||
| public class Initializer { | ||
| private Path pathToConfigDir; | ||
| private ConfigLoader configLoader; | ||
| private Stage mainStage; | ||
|
|
||
| private final Logger logger; | ||
|
|
||
| public Initializer(@NotNull String pathToConfigDir, Stage mainStage) { | ||
| this.configLoader = new ConfigLoader(pathToConfigDir); | ||
| this.mainStage = mainStage; | ||
| this.logger = LogManager.getLogger(Initializer.class); | ||
| } | ||
|
|
||
| public Result<Game, Exception> initialize() { | ||
| Result<GameWorldConfig, Exception> gameWorldConfigLoadResult = configLoader.load(); | ||
|
|
||
| if (gameWorldConfigLoadResult.isError()) { | ||
| gameWorldConfigLoadResult.getErrorValueOpt().ifPresentOrElse( | ||
| ex -> logger.error(ex.getMessage()), | ||
| () -> logger.error("Unknown error returned from config loader") | ||
| ); | ||
| return Result.error(gameWorldConfigLoadResult.getErrorValue()); | ||
| } else if (gameWorldConfigLoadResult.isOkValueNull()) { | ||
| logger.error("ConfigLoader fetched null GameWorldConfig"); | ||
| return Result.error(new RuntimeException("ConfigLoader fetched null GameWorldConfig")); | ||
| } | ||
|
|
||
| GameWorldConfig worldConfig = gameWorldConfigLoadResult.getOkValue(); | ||
|
|
||
| Controller.Builder controllerBuilder = new Controller.Builder(); | ||
|
|
||
| assert worldConfig.getLocationConfigs() != null; | ||
| assert worldConfig.getLocationConfigs().size() > 0 : "There must be at least one location config specified"; | ||
|
|
||
| for (LocationConfig locationConfig : worldConfig.getLocationConfigs()) { | ||
| LocationModel model = loadLocationModelFromConfig(locationConfig); | ||
| LocationView view = loadLocationViewFromConfig(locationConfig); | ||
|
|
||
| assert view != null; | ||
|
|
||
| if (locationConfig.getTag().equals(worldConfig.getRootLocation())) { | ||
| controllerBuilder | ||
| .setModel(model) | ||
| .setView(view); | ||
| } | ||
|
|
||
| model.addOnLocationModelStateChangeObserver(view); | ||
|
|
||
| controllerBuilder | ||
| .addViewForTag(locationConfig.getTag(), view) | ||
| .addModelForTag(locationConfig.getTag(), model); | ||
| } | ||
|
|
||
| Game.Builder gameBuilder = new Game.Builder(); | ||
| gameBuilder.setController(controllerBuilder.build()); | ||
|
|
||
| return Result.ok(gameBuilder.build()); | ||
| } | ||
|
|
||
| @Nullable | ||
| public static LocationView loadLocationViewFromConfig(LocationConfig config) { | ||
| try { | ||
| return LocationView.fromConfig(config); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public static LocationModel loadLocationModelFromConfig(LocationConfig config) { | ||
| List<GameObjectConfig> gameObjectConfigs = config.getObjects(); | ||
| List<GameObject> gameObjects = new LinkedList<>(); | ||
|
|
||
| for (GameObjectConfig goconfig : gameObjectConfigs) { | ||
| gameObjects.add(GameObject.fromConfig(goconfig)); | ||
| } | ||
|
|
||
| return new LocationModel( | ||
| config.getTag(), | ||
| gameObjects | ||
| ); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.