Skip to content

Commit

Permalink
Remove npc randomization from code
Browse files Browse the repository at this point in the history
Assertations and Validation tests included to keep it out
  • Loading branch information
AceLeft committed Feb 27, 2024
1 parent c37d2f5 commit 046162f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions project/story/demo_stories/year_bound_demo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ extends SimpleStory

var text := "This story will not be shown during the player's freshman year."

var npc_name := "Steven"

var years := Year.not_year(Year.Name.FRESHMAN)

var options := {
Expand Down
15 changes: 10 additions & 5 deletions project/test/integration/simple_story_validity_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ func test_stories_exist():
assert_true(story_paths.size() > 0, "No stories found in %s" % STORY_PATH)


func test_story_has_npc():
_for_each_story(func(story,path):
assert_true("npc_name" in story, "Story %s has an npc" % path)
)


func test_npc_is_in_cast():
var cast := Cast.new()
cast.load_cast(CAST_PATH)

_for_each_story(func(story, path):
if "npc_name" in story:
var npc_name : String = story.npc_name
assert_true(cast.contains(npc_name),
"Cast does not contain an NPC named '%s' in %s" % [story,path])
var npc_name : String = story.npc_name
assert_true(cast.contains(npc_name),
"Cast does not contain an NPC named '%s' in %s" % [story,path])
)


Expand Down
10 changes: 4 additions & 6 deletions project/world/simple_story.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ const _ON_OPTION_SELECTED_NAME := "on_option_selected"
func run(presenter) -> void:
assert("text" in self, "This story must have 'text'")
assert(get("text") is String or get("text") is Array, "The 'text' must be a string or an array")
assert("npc_name" in self, "This story must have 'npc_name'")
assert("options" in self, "This story must have 'options'")

# Clear any old text from the screen first
presenter.show_text("")

# If the npc is specified, load it, and if not, pick one at random.
var npc : Npc
if "npc_name" in self:
npc = presenter.world.cast.get_by_name(get("npc_name"))
else:
npc = presenter.world.cast.pick_random()
var npc : Npc = presenter.world.cast.get_by_name(get("npc_name"))

# If the location is specified, load it, and if not, pick one at random.
var location : Texture
if "location" in self:
location = presenter.world.game_map.get_by_name(get("location"))
Expand Down

0 comments on commit 046162f

Please sign in to comment.