Skip to content

Commit

Permalink
wip: create events and sub-event categories
Browse files Browse the repository at this point in the history
A bunch of pandora entities and more implementation in place.
  • Loading branch information
russmatney committed Jan 29, 2024
1 parent f91b2a1 commit 4eb262a
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 18 deletions.
72 changes: 71 additions & 1 deletion data.pandora
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
"_index": 0,
"_name": "PuzzleTheme",
"_script_path": "res://src/themes/DotHopTheme.gd"
},
{
"_category_id": "",
"_icon_color": "49e5caff",
"_id": "28",
"_index": 0,
"_name": "Event"
},
{
"_category_id": "28",
"_icon_color": "ffffff00",
"_id": "32",
"_index": 0,
"_name": "PuzzleSetCompleted"
},
{
"_category_id": "28",
"_icon_color": "ffffff00",
"_id": "33",
"_index": 0,
"_name": "PuzzleSetUnlocked"
},
{
"_category_id": "28",
"_icon_color": "ffffff00",
"_id": "34",
"_index": 0,
"_name": "ThemeUnlocked"
}
],
"_entities": [
Expand Down Expand Up @@ -433,12 +461,54 @@
"_id": "21",
"_name": "next_set",
"_type": "reference"
},
{
"_category_id": "28",
"_default_value": "",
"_id": "29",
"_name": "display_name",
"_type": "string"
},
{
"_category_id": "28",
"_default_value": "",
"_id": "30",
"_name": "timestamp_string",
"_type": "string"
},
{
"_category_id": "32",
"_default_value": null,
"_id": "35",
"_name": "puzzle_set",
"_type": "reference"
},
{
"_category_id": "33",
"_default_value": null,
"_id": "36",
"_name": "puzzle_set",
"_type": "reference"
},
{
"_category_id": "34",
"_default_value": null,
"_id": "37",
"_name": "theme",
"_type": "reference"
},
{
"_category_id": "28",
"_default_value": 0,
"_id": "38",
"_name": "timestamp_float",
"_type": "float"
}
]
},
"_id_generator": {
"_ids_by_context": {
"default": 27
"default": 38
}
}
}
10 changes: 10 additions & 0 deletions src/State.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ func _init(events=[]):
Log.pr("Creating game state with %d events" % len(events))
puzzle_sets = initial_puzzle_sets()
themes = initial_themes()
apply_events(events)

## apply events #######################################################

func apply_events(events):
for event in events:
apply_event(event)

func apply_event(event):
pass

## initial states #######################################################

Expand Down
16 changes: 15 additions & 1 deletion src/Store.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,34 @@ func get_events() -> Array:

func complete_puzzle_set(puz: PuzzleSet):
# TODO create, apply, and save puzzle_set_unlocked event
var event_cat = Pandora.get_category("PuzzleSetCompleted")
var event_ent = Pandora.create_entity("%s complete!" % puz.get_display_name(), event_cat)
var event = event_ent.instantiate()
# TODO event.set_* puzzle, timestamps, display_name, etc
events.append(event)
save_game()

if puz.get_next_puzzle_set():
unlock_next_puzzle_set(puz)

func unlock_next_puzzle_set(puz: PuzzleSet):
# TODO create, apply, and save puzzle_set_unlocked event

# move this logic to GameState and make it a result of applying the event
if puz.get_next_puzzle_set():
var to_unlock = state.puzzle_sets.filter(func(ps):
return ps.get_entity_id() == puz.get_next_puzzle_set().get_entity_id())
if len(to_unlock) > 0:
var next = to_unlock[0]

var event_cat = Pandora.get_category("PuzzleSetUnlocked")
var event_ent = Pandora.create_entity("%s unlocked!" % next.get_display_name(), event_cat)
var event = event_ent.instantiate()
events.append(event)
# TODO event.set_* puzzle, timestamps, display_name, etc

# TODO unlock for immediate use
next.unlock()
# save update events for later reloading
save_game()
else:
Log.warn("No next puzzle to unlock!", puz)
17 changes: 17 additions & 0 deletions src/events/Event.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@tool
extends PandoraEntity
class_name Event

func get_display_name() -> String:
return get_string("display_name")

func get_timestamp_string() -> String:
return get_string("timestamp_string")

func get_timestamp_float() -> float:
return get_float("timestamp_float")

func data():
return {
name=get_display_name(),
}
11 changes: 11 additions & 0 deletions src/events/PuzzleSetCompleted.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@tool
extends Event
class_name PuzzleSetCompleted

func get_puzzle_set() -> PuzzleSet:
return get_resource("puzzle_set")

func data():
var d = super.data()
d.merge({puzzle_set=get_puzzle_set(),})
return d
11 changes: 11 additions & 0 deletions src/events/PuzzleSetUnlocked.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@tool
extends Event
class_name PuzzleSetUnlocked

func get_puzzle_set() -> PuzzleSet:
return get_resource("puzzle_set")

func data():
var d = super.data()
d.merge({puzzle_set=get_puzzle_set(),})
return d
11 changes: 11 additions & 0 deletions src/events/ThemeUnlocked.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@tool
extends Event
class_name ThemeUnlocked

func get_theme() -> DotHopTheme:
return get_resource("theme")

func data():
var d = super.data()
d.merge({theme=get_theme()})
return d
17 changes: 11 additions & 6 deletions src/puzzle/GameScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func _ready():

hud = get_node_or_null("HUD")

func nav_to_world_map():
# TODO better navigation (string-less, path-less)
Navi.nav_to("res://src/menus/worldmap/WorldMapMenu.tscn")


## rebuild puzzle #####################################################################

func rebuild_puzzle():
Expand All @@ -50,8 +55,8 @@ func rebuild_puzzle():
})

if puzzle_node == null:
Log.pr("Failed to create puzzle_node, probably a win?")
Navi.nav_to_main_menu()
Log.warn("built puzzle_node is nil, returning to world map", puzzle_set)
nav_to_world_map()
return

puzzle_node.win.connect(on_puzzle_win)
Expand Down Expand Up @@ -81,8 +86,9 @@ func update_hud():
}
if message != null:
data["level_message"] = message
data["level_number"] = puzzle_num + 1
data["level_number_total"] = len(game_def.levels)
var total_levels = len(game_def.levels)
data["level_number"] = clamp(puzzle_num + 1, 1, total_levels)
data["level_number_total"] = total_levels
hud.update_state(data)

## load theme #####################################################################
Expand Down Expand Up @@ -125,8 +131,7 @@ func on_puzzle_win():

# function call, or emit event ?
Store.complete_puzzle_set(puzzle_set)
# TODO better navigation (string-less, path-less)
Navi.nav_to("res://src/menus/worldmap/WorldMapMenu.tscn")
nav_to_world_map()
else:
if puzzle_node.has_method("animate_exit"):
await puzzle_node.animate_exit()
Expand Down
8 changes: 4 additions & 4 deletions src/themes/space/SpacePuzzle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ script = ExtResource("5_3250r")
type = 1
square_size = 32

[node name="@Node2D@29905" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
[node name="@Node2D@18084" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
position = Vector2(64, 32)
script = ExtResource("5_3250r")
square_size = 32

[node name="@Node2D@29906" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
[node name="@Node2D@18085" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
position = Vector2(96, 32)
script = ExtResource("5_3250r")
square_size = 32

[node name="@Node2D@29907" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
[node name="@Node2D@18086" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
position = Vector2(128, 32)
script = ExtResource("5_3250r")
square_size = 32

[node name="@Node2D@29908" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
[node name="@Node2D@18087" type="Node2D" parent="." groups=["generated"] instance=ExtResource("4_sim88")]
position = Vector2(160, 32)
script = ExtResource("5_3250r")
type = 2
Expand Down
18 changes: 12 additions & 6 deletions test/store/store_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ extends GdUnitTestSuite

# probably want to update SaveGame to point to some test save file

#########################################################################
## initial data

func test_initial_store_puzzle_data():
Store.reset_game_data()
Expand Down Expand Up @@ -40,6 +42,9 @@ func test_initial_store_theme_data():
# TODO theme unlocking!
assert_that(len(unlocked)).is_equal(len(theme_ents))

#########################################################################
## completing and unlocking puzzle sets

func test_unlocking_puzzle_set():
Store.reset_game_data()

Expand All @@ -51,8 +56,11 @@ func test_unlocking_puzzle_set():
# ensure it's not unlocked already!
assert_that(next.is_unlocked()).is_false()

# unlock the 'next' puzzle
Store.unlock_next_puzzle_set(first)
# complete the current (which for now also unlocks the 'next' puzzle)
Store.complete_puzzle_set(first)

# should have two events created
assert_that(len(Store.events)).is_equal(2)

# in-place entity updates
assert_that(next.is_unlocked()).is_true()
Expand All @@ -61,10 +69,8 @@ func test_unlocking_puzzle_set():
var _next = Store.get_puzzle_sets().filter(func(e): return e.get_entity_id() == next_id)[0]
assert_that(_next.is_unlocked()).is_true()

####################

# unlock the 'next-next' puzzle
Store.unlock_next_puzzle_set(next)
# do it again, unlocking the 'next-next' puzzle
Store.complete_puzzle_set(next)
var third = Store.get_puzzle_sets().filter(func(e):
return e.get_entity_id() == next.get_next_puzzle_set().get_entity_id())[0]
assert_that(third.is_unlocked()).is_true()

0 comments on commit 4eb262a

Please sign in to comment.