generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92f6366
commit c5a1eac
Showing
11 changed files
with
348 additions
and
50 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
27 changes: 0 additions & 27 deletions
27
packages/backend/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/BuildingCard.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...d/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/BuildingCard/BuildingCard.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,14 @@ | ||
package tw.waterballsa.gaas.citadels.domain.BuildingCard; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import tw.waterballsa.gaas.citadels.domain.BuildingCard.BuildingCardFactory.Color; | ||
|
||
|
||
@Data | ||
@AllArgsConstructor | ||
public class BuildingCard { | ||
String name; | ||
int coins; | ||
Color color; | ||
} |
81 changes: 81 additions & 0 deletions
81
...n/src/main/java/tw/waterballsa/gaas/citadels/domain/BuildingCard/BuildingCardFactory.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,81 @@ | ||
package tw.waterballsa.gaas.citadels.domain.BuildingCard; | ||
|
||
import java.util.Optional; | ||
|
||
public interface BuildingCardFactory { | ||
|
||
public enum Type { | ||
TEMPLE, | ||
CHURCH, | ||
MONASTERY, | ||
CATHEDRAL, | ||
WATCHTOWER, | ||
PRISON, | ||
BATTLEFIELD, | ||
FORTRESS, | ||
MANOR, | ||
CASTLE, | ||
PALACE, | ||
TAVERN, | ||
INN, | ||
MARKET, | ||
BOATHOUSE, | ||
HARBOR, | ||
TOWN_HALL, | ||
LIBRARY, | ||
DRAGON_GATE, | ||
GRAVEYARD, | ||
GHOST_TOWN, | ||
SCHOOL_OF_MAGIC, | ||
LABORATORY, | ||
SMITHY, | ||
OBSERVATORY, | ||
UNIVERSITY, | ||
BASTION, | ||
GREAT_WALL; | ||
|
||
public static Optional<Type> fromInt(int value) { | ||
for(Type type : Type.values()) { | ||
if(type.ordinal() == value) { | ||
return Optional.ofNullable(type); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public static Optional<Type> fromString(String str) { | ||
for (Type type : Type.values()) { | ||
if(str.equals(type.toString())) { | ||
return Optional.ofNullable(type); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
public enum Color { | ||
PURPLE("特別地區"), | ||
GOLD("貴族地區"), | ||
RED("軍事地區"), | ||
BLUE("商業地區"), | ||
GREEN("宗教地區"); | ||
private final String area; | ||
|
||
Color(String area) { | ||
this.area = area; | ||
} | ||
|
||
public static Optional<Color> fromString(String str) { | ||
for (Color color : Color.values()) { | ||
if(str.equalsIgnoreCase(color.toString())) { | ||
return Optional.ofNullable(color); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
public Optional<BuildingCard> createBuildingCard(Type 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
31 changes: 31 additions & 0 deletions
31
...end/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/BuildingCardFactoryImpl.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,31 @@ | ||
package tw.waterballsa.gaas.citadels.spring; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.SneakyThrows; | ||
import org.springframework.stereotype.Component; | ||
import tw.waterballsa.gaas.citadels.domain.BuildingCard.BuildingCard; | ||
import tw.waterballsa.gaas.citadels.domain.BuildingCard.BuildingCardFactory; | ||
import tw.waterballsa.gaas.citadels.exceptions.NotFoundException; | ||
|
||
import javax.inject.Named; | ||
import java.io.File; | ||
import java.util.Optional; | ||
|
||
@Named | ||
public class BuildingCardFactoryImpl implements BuildingCardFactory { | ||
@SneakyThrows | ||
@Override | ||
public Optional<BuildingCard> createBuildingCard(Type type) { | ||
String path = "src/main/resources/CardInfo.json"; | ||
ObjectMapper mapper = new ObjectMapper(); | ||
JsonNode nodes = mapper.readTree(new File(path)); | ||
BuildingCard buildingCard = null; | ||
for(JsonNode node : nodes) { | ||
if(type == BuildingCardFactory.Type.fromString(node.get("name").asText()).orElseThrow()) { | ||
buildingCard = new BuildingCard(node.get("name").asText(), node.get("cost").asInt(), BuildingCardFactory.Color.fromString(node.get("color").asText()).orElseThrow(() -> new NotFoundException("NO SUCH COLOR, COLOR=" + node.get("color").asText()))); | ||
} | ||
} | ||
return Optional.ofNullable(buildingCard); | ||
} | ||
} |
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
Oops, something went wrong.