diff --git a/project/common/year.gd b/project/common/year.gd index 9d3ee0b..9ff1116 100644 --- a/project/common/year.gd +++ b/project/common/year.gd @@ -1,10 +1,10 @@ class_name Year enum { - Freshman = 0, - Sophomore = 1, - Junior = 2, - Senior = 3, + Freshman, + Sophomore, + Junior, + Senior, } diff --git a/project/story/starting_stories/big_vs_small.gd b/project/story/starting_stories/big_vs_small.gd index eb625eb..6686b64 100644 --- a/project/story/starting_stories/big_vs_small.gd +++ b/project/story/starting_stories/big_vs_small.gd @@ -2,6 +2,8 @@ extends SimpleStory var text := '"I\'ve been thinking about college. Do you think it\'s better for me to go a [u]big[/u] school or [u]small[/u] school?"' +var years := Year.not_in([ Year.Freshman ]) + var options := { "Bigger is better": { "text": '"Yeah, more people, more clubs, more opportunities. Thanks!"', diff --git a/project/story/starting_stories/liberal_arts.gd b/project/story/starting_stories/liberal_arts.gd index 6bd81d5..802ad91 100644 --- a/project/story/starting_stories/liberal_arts.gd +++ b/project/story/starting_stories/liberal_arts.gd @@ -7,6 +7,8 @@ var text := [ '"I liked some of the smaller liberal arts schools I visited, but I also liked the engineering program at the big state university."' ] +var years := [ Year.Junior, Year.Senior ] + var options := { "Study liberal arts!": { "text": [ diff --git a/project/test/integration/simple_story_validity_test.gd b/project/test/integration/simple_story_validity_test.gd index a5b7c91..ae15df2 100644 --- a/project/test/integration/simple_story_validity_test.gd +++ b/project/test/integration/simple_story_validity_test.gd @@ -170,7 +170,7 @@ func test_all_story_year_constraints_are_valid(): if "years" in story: for year in story.years: assert_true(year is int, "Story %s year %s is an integer" % [story_path, year]) - assert_true(Year.keys().has(year), "Story %s year %s is a valid year" % [story_path, year]) + assert_true(Year.values().has(year), "Story %s year %s is a valid year" % [story_path, year]) func test_locations(): diff --git a/project/ui/main_scene.gd b/project/ui/main_scene.gd index 1ea05ca..bae64c7 100644 --- a/project/ui/main_scene.gd +++ b/project/ui/main_scene.gd @@ -83,7 +83,7 @@ func _run_next_story() -> void: func _draw_random_story() -> String: - var story_path : String = world.available_stories.pick_random() + var story_path : String = world.get_active_stories().pick_random() world.available_stories.erase(story_path) return story_path diff --git a/project/ui/year_indicator.gd b/project/ui/year_indicator.gd index 2b9b01c..5410246 100644 --- a/project/ui/year_indicator.gd +++ b/project/ui/year_indicator.gd @@ -4,31 +4,16 @@ var world: World: set(value): if world != null: if world != value: - world.turns_changed.disconnect(_update_display) - + world.years_changed.disconnect(_update_display) + world = value - world.turns_changed.connect(_update_display) - _update_display(world.turns) + world.years_changed.connect(_update_display) + _update_display(world.years) @onready var _year_name: Label = %YearName @onready var _year_circles : Array[ProgressCircle] = [%Year1, %Year2, %Year3, %Year4 ] -func _lookup_year_name(percent_complete: float) -> String: - if percent_complete < 0.25: - _year_circles[0].year_passed = true - return Year.keys()[0] - elif percent_complete < 0.5: - _year_circles[1].year_passed = true - return Year.keys()[1] - elif percent_complete < 0.75: - _year_circles[2].year_passed = true - return Year.keys()[2] - else: - _year_circles[3].year_passed = true - return Year.keys()[3] - - -func _update_display(turns: int) -> void: - var percent_complete: float = turns / (world.turns_per_year * 4.0) - _year_name.text = _lookup_year_name(percent_complete) +func _update_display(years: int) -> void: + _year_circles[years].year_passed = true + _year_name.text = Year.keys()[years] diff --git a/project/world/simple_story.gd b/project/world/simple_story.gd index 1d029db..dabc4c9 100644 --- a/project/world/simple_story.gd +++ b/project/world/simple_story.gd @@ -76,6 +76,13 @@ func run(presenter) -> void: presenter.world.end_stories.append(new_ending_possibility) +func is_active(world: World) -> bool: + if "years" in self and not get("years").has(world.years): + return false + + return true + + func _apply_effects(effects:Dictionary, world:World) -> void: for attribute_name in effects.keys(): world.character[attribute_name].value += effects[attribute_name] diff --git a/project/world/world.gd b/project/world/world.gd index 85a6db5..d6af281 100644 --- a/project/world/world.gd +++ b/project/world/world.gd @@ -1,10 +1,11 @@ ## The state of the game world class_name World extends RefCounted -signal turns_changed(new_turn : int) +signal turns_changed(new_turn: int) +signal years_changed(new_year: int) ## The maximum number of turns that can be taken in a year -const MAX_TURNS_PER_YEAR = 3 +const MAX_TURNS_PER_YEAR := 3 ## The current character whose story is being played var character := Character.new() @@ -12,10 +13,10 @@ var character := Character.new() ## The stories that are available to draw from when a new one is needed ## ## The values are resource paths. -var available_stories : Array[String] = [] +var available_stories: Array[String] = [] ## The end stories that have been added to the world -var end_stories : Array[String] = [] +var end_stories: Array[String] = [] ## The cast of characters as a map from name to npc object var cast := Cast.new() @@ -32,8 +33,20 @@ var turns_per_year := MAX_TURNS_PER_YEAR var turns := 0: set(value): turns = value + + if turns >= turns_per_year: + turns = 0 + years += 1 + turns_changed.emit(turns) +var years := 0: + set(value): + years = value + + if years < 4: + years_changed.emit(years) + ## Add all the stories in the given directory to the list ## of available stories @@ -65,3 +78,14 @@ func remove_stories(dir:DirAccess) -> Array[String]: else: push_error("Tried to remove non-existing story path: %s" % file_path) return results + + +func get_active_stories() -> Array[String]: + return available_stories.filter(func(story_path: String) -> bool: + var story = (load(story_path) as RefCounted).new() + + if not "is_active" in story: + return true + + return story.is_active(self) + )