aboutsummaryrefslogtreecommitdiff
path: root/go/game/cardParsing.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-31 22:19:28 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-01-31 22:19:28 +0100
commitdd341b1472d65fb658f53d4d8aa1ca855df0b3bf (patch)
tree9d9fb3a704b8992b26ac2f41d4cb8663b1617956 /go/game/cardParsing.go
parent1b1a6d4bc8e4a16de40f7a6cebaaacb8939d0691 (diff)
downloadmuhqs-game-dd341b1472d65fb658f53d4d8aa1ca855df0b3bf.tar.gz
muhqs-game-dd341b1472d65fb658f53d4d8aa1ca855df0b3bf.zip
intermediate commit
Diffstat (limited to 'go/game/cardParsing.go')
-rw-r--r--go/game/cardParsing.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go
index af8e1560..3a316c4f 100644
--- a/go/game/cardParsing.go
+++ b/go/game/cardParsing.go
@@ -2,6 +2,7 @@ package game
import (
"log"
+ "regexp"
"strconv"
"strings"
)
@@ -39,6 +40,11 @@ func newParsedCardImplementation(c *Card) *parsedCardImplementation {
for _, effect := range c.getEffects() {
impl.parseEffect(effect)
}
+
+ for _, fullAction := range c.getCanonicalValues("full_action") {
+ impl.parseFullAction(fullAction)
+ }
+
return impl
}
@@ -48,6 +54,38 @@ func (impl *parsedCardImplementation) parseEffect(effect string) {
}
}
+func (impl *parsedCardImplementation) parseFullAction(fullAction string) {
+ var resolveProtos []func(*State, *Unit) func(*State)
+ gainRessourceRegex := regexp.MustCompile(`gain [1-9][0-9]* resource`)
+
+ if find := gainRessourceRegex.Find([]byte(fullAction)); find != nil {
+ tokens := strings.SplitN(string(find), " ", 3)
+ gain, err := strconv.Atoi(tokens[1])
+ if err != nil {
+ log.Fatalf("Failed to parse resource gain full action: %s", err)
+ }
+
+ resolveProto := func(_ *State, u *Unit) func(*State) {
+ return func(*State) {
+ u.controller.gainResource(gain)
+ }
+ }
+ resolveProtos = append(resolveProtos, resolveProto)
+ }
+
+ if resolveProtos != nil {
+ impl.genFullActionPrototypes = func(u *Unit) []*FullActionPrototype {
+ fullActionPrototypes := make([]*FullActionPrototype, 0, len(resolveProtos))
+
+ for _, proto := range resolveProtos {
+ fullActionPrototypes = append(fullActionPrototypes, NewFullActionPrototype(u, proto))
+ }
+
+ return fullActionPrototypes
+ }
+ }
+}
+
func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool {
enemy := strings.Contains(constrain, "enemy")
if enemy {