Add campaign chapter metadata
This commit is contained in:
@@ -11,6 +11,10 @@ var start_scenario_id := ""
|
||||
var scenario_order: Array[String] = []
|
||||
var scenario_paths := {}
|
||||
var scenario_titles := {}
|
||||
var chapter_order: Array[String] = []
|
||||
var chapter_titles := {}
|
||||
var chapter_scenario_ids := {}
|
||||
var scenario_chapter_ids := {}
|
||||
var initial_joined_officers: Array[String] = []
|
||||
var current_scenario_id := ""
|
||||
var completed_scenarios: Array[String] = []
|
||||
@@ -35,6 +39,10 @@ func load_campaign(path: String) -> bool:
|
||||
scenario_order.clear()
|
||||
scenario_paths.clear()
|
||||
scenario_titles.clear()
|
||||
chapter_order.clear()
|
||||
chapter_titles.clear()
|
||||
chapter_scenario_ids.clear()
|
||||
scenario_chapter_ids.clear()
|
||||
initial_joined_officers.clear()
|
||||
|
||||
for officer_id in parsed.get("initial_joined_officers", []):
|
||||
@@ -54,11 +62,51 @@ func load_campaign(path: String) -> bool:
|
||||
scenario_paths[scenario_id] = scenario_path
|
||||
scenario_titles[scenario_id] = str(scenario.get("title", scenario_id))
|
||||
|
||||
_load_chapters(parsed.get("chapters", []))
|
||||
if start_scenario_id.is_empty() and not scenario_order.is_empty():
|
||||
start_scenario_id = scenario_order[0]
|
||||
return not scenario_order.is_empty()
|
||||
|
||||
|
||||
func _load_chapters(chapters) -> void:
|
||||
if typeof(chapters) != TYPE_ARRAY:
|
||||
push_error("Campaign chapters must be an array.")
|
||||
return
|
||||
for chapter in chapters:
|
||||
if typeof(chapter) != TYPE_DICTIONARY:
|
||||
push_error("Skipping malformed campaign chapter.")
|
||||
continue
|
||||
var chapter_id := str(chapter.get("id", ""))
|
||||
var start_scenario := str(chapter.get("start_scenario", ""))
|
||||
var end_scenario := str(chapter.get("end_scenario", ""))
|
||||
var start_index := scenario_order.find(start_scenario)
|
||||
var end_index := scenario_order.find(end_scenario)
|
||||
if chapter_id.is_empty():
|
||||
push_error("Skipping campaign chapter with empty id.")
|
||||
continue
|
||||
if chapter_order.has(chapter_id):
|
||||
push_error("Skipping duplicate campaign chapter: %s." % chapter_id)
|
||||
continue
|
||||
if start_index == -1 or end_index == -1 or end_index < start_index:
|
||||
push_error("Skipping campaign chapter with invalid scenario range: %s." % chapter_id)
|
||||
continue
|
||||
var scenario_ids: Array[String] = []
|
||||
var overlaps_existing_chapter := false
|
||||
for index in range(start_index, end_index + 1):
|
||||
var scenario_id := scenario_order[index]
|
||||
scenario_ids.append(scenario_id)
|
||||
if scenario_chapter_ids.has(scenario_id):
|
||||
push_error("Skipping campaign chapter %s because it overlaps scenario %s." % [chapter_id, scenario_id])
|
||||
overlaps_existing_chapter = true
|
||||
if overlaps_existing_chapter:
|
||||
continue
|
||||
for scenario_id in scenario_ids:
|
||||
scenario_chapter_ids[scenario_id] = chapter_id
|
||||
chapter_order.append(chapter_id)
|
||||
chapter_titles[chapter_id] = str(chapter.get("title", chapter_id))
|
||||
chapter_scenario_ids[chapter_id] = scenario_ids
|
||||
|
||||
|
||||
func load_or_start(scenario_id: String) -> void:
|
||||
var loaded_save := load_game()
|
||||
if not loaded_save:
|
||||
@@ -560,6 +608,48 @@ func get_scenario_count() -> int:
|
||||
return scenario_order.size()
|
||||
|
||||
|
||||
func get_chapter_count() -> int:
|
||||
return chapter_order.size()
|
||||
|
||||
|
||||
func get_chapter_id_for_scenario(scenario_id: String) -> String:
|
||||
return str(scenario_chapter_ids.get(scenario_id, ""))
|
||||
|
||||
|
||||
func get_chapter_title_for_scenario(scenario_id: String) -> String:
|
||||
var chapter_id := get_chapter_id_for_scenario(scenario_id)
|
||||
if chapter_id.is_empty():
|
||||
return ""
|
||||
return str(chapter_titles.get(chapter_id, chapter_id))
|
||||
|
||||
|
||||
func get_chapter_position_for_scenario(scenario_id: String) -> int:
|
||||
var chapter_id := get_chapter_id_for_scenario(scenario_id)
|
||||
var index := chapter_order.find(chapter_id)
|
||||
if index == -1:
|
||||
return 0
|
||||
return index + 1
|
||||
|
||||
|
||||
func get_scenario_position_in_chapter(scenario_id: String) -> int:
|
||||
var chapter_id := get_chapter_id_for_scenario(scenario_id)
|
||||
if chapter_id.is_empty() or not chapter_scenario_ids.has(chapter_id):
|
||||
return 0
|
||||
var scenario_ids: Array = chapter_scenario_ids[chapter_id]
|
||||
var index := scenario_ids.find(scenario_id)
|
||||
if index == -1:
|
||||
return 0
|
||||
return index + 1
|
||||
|
||||
|
||||
func get_scenario_count_in_chapter(scenario_id: String) -> int:
|
||||
var chapter_id := get_chapter_id_for_scenario(scenario_id)
|
||||
if chapter_id.is_empty() or not chapter_scenario_ids.has(chapter_id):
|
||||
return 0
|
||||
var scenario_ids: Array = chapter_scenario_ids[chapter_id]
|
||||
return scenario_ids.size()
|
||||
|
||||
|
||||
func get_next_scenario_id(scenario_id: String) -> String:
|
||||
var index := scenario_order.find(scenario_id)
|
||||
if index == -1 or index + 1 >= scenario_order.size():
|
||||
|
||||
@@ -1841,6 +1841,13 @@ func _format_briefing_title(briefing: Dictionary) -> String:
|
||||
var title := str(briefing.get("title", state.battle_name))
|
||||
if title.is_empty():
|
||||
title = campaign_state.get_scenario_title(active_scenario_id)
|
||||
var chapter_title := campaign_state.get_chapter_title_for_scenario(active_scenario_id)
|
||||
if not chapter_title.is_empty():
|
||||
var chapter_position := campaign_state.get_chapter_position_for_scenario(active_scenario_id)
|
||||
var chapter_count := campaign_state.get_chapter_count()
|
||||
if chapter_position > 0 and chapter_count > 0:
|
||||
return "Chapter %02d/%02d - %s" % [chapter_position, chapter_count, chapter_title]
|
||||
return chapter_title
|
||||
var position := campaign_state.get_scenario_position(active_scenario_id)
|
||||
var count := campaign_state.get_scenario_count()
|
||||
if position > 0 and count > 0:
|
||||
@@ -1850,6 +1857,12 @@ func _format_briefing_title(briefing: Dictionary) -> String:
|
||||
|
||||
func _format_briefing_location(briefing: Dictionary) -> String:
|
||||
var location := str(briefing.get("location", ""))
|
||||
var chapter_title := campaign_state.get_chapter_title_for_scenario(active_scenario_id)
|
||||
if not chapter_title.is_empty():
|
||||
var battle_text := _format_briefing_chapter_battle_text(briefing)
|
||||
if location.is_empty():
|
||||
return battle_text
|
||||
return "%s | %s" % [battle_text, location]
|
||||
if campaign_state.campaign_title.is_empty():
|
||||
return location
|
||||
if location.is_empty():
|
||||
@@ -1857,6 +1870,17 @@ func _format_briefing_location(briefing: Dictionary) -> String:
|
||||
return "%s | %s" % [campaign_state.campaign_title, location]
|
||||
|
||||
|
||||
func _format_briefing_chapter_battle_text(briefing: Dictionary) -> String:
|
||||
var title := str(briefing.get("title", state.battle_name))
|
||||
if title.is_empty():
|
||||
title = campaign_state.get_scenario_title(active_scenario_id)
|
||||
var position := campaign_state.get_scenario_position_in_chapter(active_scenario_id)
|
||||
var count := campaign_state.get_scenario_count_in_chapter(active_scenario_id)
|
||||
if position > 0 and count > 0:
|
||||
return "Battle %02d/%02d: %s" % [position, count, title]
|
||||
return title
|
||||
|
||||
|
||||
func _format_briefing_objectives() -> String:
|
||||
var text := ""
|
||||
var victory := str(state.objectives.get("victory", ""))
|
||||
|
||||
Reference in New Issue
Block a user