edgedb: move Calculations into own type
This commit is contained in:
+11
-1
@@ -63,8 +63,9 @@ module default {
|
||||
required type: str {
|
||||
readonly := true;
|
||||
}
|
||||
calculations: array<json> {
|
||||
required multi calculations: Calculations {
|
||||
readonly := true;
|
||||
on source delete delete target;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +81,13 @@ module default {
|
||||
}
|
||||
}
|
||||
|
||||
type Calculations {
|
||||
required turn: int32 {
|
||||
readonly := true;
|
||||
}
|
||||
required data: array<json> {
|
||||
readonly := true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,14 @@ class EdgeDB:
|
||||
snake := (
|
||||
insert Snake {
|
||||
type := <str>$snake_type,
|
||||
calculations := <array<json>>$calculations
|
||||
calculations := (
|
||||
with input_data := <array <tuple <turn: int32, data: array<json>>> >$calculations
|
||||
for tupel_data in array_unpack(input_data)
|
||||
insert Calculations {
|
||||
turn := tupel_data.turn,
|
||||
data := tupel_data.data
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}""",
|
||||
@@ -76,7 +83,7 @@ class EdgeDB:
|
||||
settings=json.dumps(game_board.ruleset["settings"]),
|
||||
|
||||
snake_type=game_board.snake_class.__class__.__name__,
|
||||
calculations=[ json.dumps(ele) for ele in game_board.snake_class.get_history() ],
|
||||
calculations=[ tuple([ele["turn"], [json.dumps(calc) for calc in ele["data"]]]) for ele in game_board.snake_class.get_history() ],
|
||||
)
|
||||
|
||||
def save(self, game_board:GameBoard):
|
||||
|
||||
Reference in New Issue
Block a user