Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f909673
chore: Massive update...
kkafar Apr 11, 2022
97168b4
BREAKING CHANGES: Arch proposal
kkafar Apr 12, 2022
eb85cb5
chore: rename io.rpg.torefract -> io.rpg.torefact
kkafar Apr 12, 2022
b5a0c8a
refact: rename PointsPopupController -> PointsPopupViewModel
kkafar Apr 13, 2022
b69f869
refact: add comments & change method names in ConfigLoader
kkafar Apr 13, 2022
8eb9b59
refact: add comments tgo GameObjectConfig
kkafar Apr 13, 2022
25a08a5
refact: add comments to GameWorldConfig
kkafar Apr 13, 2022
de086eb
chore: make ConfigLoader#{loadGameWorldConfig,loadLocationConfig}
kkafar Apr 13, 2022
a958a33
chore: add generic class describing operation result
kkafar Apr 13, 2022
f1219eb
chore: add Optional returning getters to Result
kkafar Apr 13, 2022
211f928
fix: revert changes from #de086eb
kkafar Apr 13, 2022
7fe4bd6
chore: update configuration files
kkafar Apr 13, 2022
e774cfb
chore: improve error handlign in config module via Result class
kkafar Apr 13, 2022
04292a5
feat: add helper methods to Result class
kkafar Apr 13, 2022
77279ff
chore: add builder to the Game class
kkafar Apr 13, 2022
2223fa0
refact: adapt Main to new Result based interface
kkafar Apr 13, 2022
4a27c40
feat: add builder to the Controller
kkafar Apr 13, 2022
41f013f
chore: update unit test configuration
kkafar Apr 13, 2022
a9d9c92
fix: make unit tests pass
kkafar Apr 13, 2022
f85525c
chore: Update observer schema before refractoring
kkafar Apr 13, 2022
58ed78f
Merge branch 'master' into @kkafar/arch-proposal
kkafar Apr 13, 2022
1af5380
docs: add more comments to GameWorldConfig
kkafar Apr 13, 2022
8f82497
chore: make GameObjectConfig#valide method return Result
kkafar Apr 13, 2022
8af785a
chore: Cleanup ConfigLoader
kkafar Apr 13, 2022
9f65d92
chore: minor fixes & apply linter
kkafar Apr 13, 2022
c900f2d
refact: apply style suggestions
kkafar Apr 13, 2022
52cc4f6
Merge branch 'master' into @kkafar/arch-proposal
kkafar Apr 13, 2022
640720c
chore: improve observer model
kkafar Apr 16, 2022
d798479
refact: move event types to model package
kkafar Apr 16, 2022
9441e46
refact: small style change
kkafar Apr 16, 2022
0f33369
chore: add GameObjectStateChange event interface
kkafar Apr 16, 2022
ebdde50
chore: add LocationModelStateChange event interface
kkafar Apr 16, 2022
ccd3281
chore: add LocattionModelStateChange event interface
kkafar Apr 16, 2022
ac69662
fix: update interface implementations
kkafar Apr 16, 2022
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks.withType(JavaCompile) {

application {
mainModule = 'io.rpg'
mainClass = 'io.rpg.HelloApplication'
mainClass = 'io.rpg.Main'
}

javafx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"objects": [
{ "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"
}
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tag": "object-1",
"assetPath": "/path/to/the/asset",
"type": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tag": "object-3",
"assetPath": "/path/to/the/asset",
"type": ""
}
5 changes: 3 additions & 2 deletions configurations/config-1/root.json
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"
}
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tag": "object-1",
"assetPath": "/path/to/the/asset",
"type": ""
}
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tag": "object-1",
"assetPath": "/path/to/the/asset",
"type": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tag": "object-3",
"assetPath": "/path/to/the/asset",
"type": ""
}
5 changes: 3 additions & 2 deletions configurations/unit-test-configuration/root.json
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"
}
44 changes: 44 additions & 0 deletions src/main/java/io/rpg/Game.java
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;
}
}
}
66 changes: 0 additions & 66 deletions src/main/java/io/rpg/HelloApplication.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/io/rpg/HelloController.java

This file was deleted.

106 changes: 106 additions & 0 deletions src/main/java/io/rpg/Initializer.java
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
);
}
}
Loading