-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: RPG-129 conditional actions (#67)
- Loading branch information
Showing
24 changed files
with
324 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
...ocations/location-1/objects/object-3.json → .../locations/location-1/objects/bandit.json
This file contains 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,5 +1,5 @@ | ||
{ | ||
"tag": "object-3", | ||
"tag": "bandit", | ||
"assetPath": "assets/bandit.png", | ||
"type": "dialog", | ||
"onLeftClick": { | ||
|
2 changes: 1 addition & 1 deletion
2
...ocations/location-1/objects/object-2.json → ...g-1/locations/location-1/objects/key.json
This file contains 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,4 +1,4 @@ | ||
{ | ||
"tag": "object-2", | ||
"tag": "key", | ||
"onLeftClick": {"tag": "dialogue-action", "type": "dialogue", "statements": ["A key.,A, keyA, key.A, key.A, key.A, key.A, key.A, key.A key."], "assetPath": "assets/key.png"} | ||
} |
4 changes: 0 additions & 4 deletions
4
configurations/demo-config-1/locations/location-1/objects/object-1.json
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
configurations/demo-config-1/locations/location-1/objects/tp-bunny.json
This file contains 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,13 @@ | ||
{ | ||
"tag": "tp-bunny", | ||
"onLeftClick": { | ||
"tag": "change-location", | ||
"type": "location-change", | ||
"target-location": "location-2", | ||
"target-position": {"row": 9, "col": 0}, | ||
"condition": { | ||
"type": "item-required", | ||
"item-tag": "key" | ||
} | ||
} | ||
} |
This file contains 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 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
55 changes: 55 additions & 0 deletions
55
src/main/java/io/rpg/config/model/ConditionConfigBundle.java
This file contains 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,55 @@ | ||
package io.rpg.config.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import com.kkafara.rt.Result; | ||
import io.rpg.model.actions.ConditionType; | ||
import io.rpg.util.ErrorMessageBuilder; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ConditionConfigBundle implements ConfigWithValidation { | ||
|
||
@Nullable | ||
private ConditionType type; | ||
|
||
@Nullable | ||
@SerializedName(value = "item-tag", alternate = {"itemTag"}) | ||
private String itemTag; | ||
|
||
@Nullable | ||
public ConditionType getType() { | ||
return type; | ||
} | ||
|
||
@Nullable | ||
public String getItemTag() { | ||
return itemTag; | ||
} | ||
|
||
Result<Void, Exception> validateItemRequired() { | ||
ErrorMessageBuilder builder = new ErrorMessageBuilder(); | ||
|
||
if (itemTag == null || itemTag.isBlank()) { | ||
builder.append("No or invalid item tag provided"); | ||
} | ||
|
||
return builder.isEmpty() ? Result.ok() : Result.err(new Exception(builder.toString())); | ||
} | ||
|
||
@Override | ||
public Result<Void, Exception> validate() { | ||
ErrorMessageBuilder builder = new ErrorMessageBuilder(); | ||
|
||
if (type == null) { | ||
builder.append("No or invalid type provided"); | ||
} | ||
|
||
if (!builder.isEmpty()) { | ||
return Result.err(new Exception(builder.toString())); | ||
} | ||
|
||
switch (type) { | ||
case ITEM_REQUIRED -> { return validateItemRequired(); } | ||
default -> throw new IllegalArgumentException("Not implemented condition type!"); | ||
} | ||
} | ||
} |
This file contains 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 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 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.model.actions; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public enum ConditionType { | ||
@SerializedName("item-required") | ||
ITEM_REQUIRED | ||
} |
This file contains 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,18 @@ | ||
package io.rpg.model.actions; | ||
|
||
import io.rpg.model.actions.condition.Condition; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public abstract class ConditionalAction implements Action { | ||
@Nullable | ||
private final Condition condition; | ||
|
||
public ConditionalAction(@Nullable Condition condition) { | ||
this.condition = condition; | ||
} | ||
|
||
@Nullable | ||
public Condition getCondition() { | ||
return condition; | ||
} | ||
} |
Oops, something went wrong.