1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-12-07 21:01:33 +00:00

Make the name and description of CS+ mods optional

This commit is contained in:
biroder 2025-09-01 19:36:13 +03:00
parent 8b5406d941
commit 1e776e7d3a
5 changed files with 46 additions and 36 deletions

View file

@ -60,6 +60,10 @@
"replay_last": "Replay Last", "replay_last": "Replay Last",
"delete_replay": "Delete Best Replay" "delete_replay": "Delete Best Replay"
}, },
"challenges_menu": {
"empty_mod_name": "No Mod Name",
"empty_mod_description": "No Description"
},
"options_menu": { "options_menu": {
"graphics": "Graphics...", "graphics": "Graphics...",
"graphics_menu": { "graphics_menu": {

View file

@ -60,6 +60,10 @@
"replay_last": "最後のプレイを再生", "replay_last": "最後のプレイを再生",
"delete_replay": "ベストリプレイを削除" "delete_replay": "ベストリプレイを削除"
}, },
"challenges_menu": {
"empty_mod_name": "モッド名なし",
"empty_mod_description": "描写なし"
},
"options_menu": { "options_menu": {
"graphics": "グラフィック", "graphics": "グラフィック",
"graphics_menu": { "graphics_menu": {

View file

@ -512,10 +512,7 @@ impl SharedGameState {
} }
pub fn reload_stage_table(&mut self, ctx: &mut Context) -> GameResult { pub fn reload_stage_table(&mut self, ctx: &mut Context) -> GameResult {
let stages = StageData::load_stage_table( let stages = StageData::load_stage_table(self, ctx)?;
self,
ctx,
)?;
self.stages = stages; self.stages = stages;
Ok(()) Ok(())
} }
@ -860,12 +857,14 @@ impl SharedGameState {
} }
pub fn get_rec_filename(&self) -> String { pub fn get_rec_filename(&self) -> String {
if let Some(mod_path) = &self.mod_path { let name = &self
let name = self.mod_list.get_name_from_path(mod_path.to_string()); .mod_path
return format!("/{}", name); .clone()
} else { .and_then(|mod_path| self.mod_list.get_info_from_path(mod_path))
return "/290".to_string(); .and_then(|mod_info| mod_info.name.clone().or(Some(mod_info.id.clone())))
} .unwrap_or("290".to_owned());
format!("/{name}")
} }
pub fn has_replay_data(&self, ctx: &mut Context, replay_kind: ReplayKind) -> bool { pub fn has_replay_data(&self, ctx: &mut Context, replay_kind: ReplayKind) -> bool {

View file

@ -15,8 +15,8 @@ pub struct ModInfo {
pub priority: u32, pub priority: u32,
pub save_slot: i32, pub save_slot: i32,
pub path: String, pub path: String,
pub name: String, pub name: Option<String>,
pub description: String, pub description: Option<String>,
pub valid: bool, pub valid: bool,
} }
@ -81,7 +81,7 @@ impl ModList {
} }
consume_spaces(&mut chars); consume_spaces(&mut chars);
id.push_str("csmod_"); id.push_str("cspmod_");
for c in &mut chars { for c in &mut chars {
if c == ' ' { if c == ' ' {
break; break;
@ -150,8 +150,8 @@ impl ModList {
} }
let mut valid = false; let mut valid = false;
let mut name = String::new(); let mut name: Option<String> = None;
let mut description = String::new(); let mut description: Option<String> = None;
let mut save_slot = -1; let mut save_slot = -1;
if let Ok(file) = filesystem::open(ctx, [&path, "/mod.txt"].join("")) { if let Ok(file) = filesystem::open(ctx, [&path, "/mod.txt"].join("")) {
@ -162,15 +162,14 @@ impl ModList {
save_slot = line.unwrap_or("-1".to_string()).parse::<i32>().unwrap_or(-1); save_slot = line.unwrap_or("-1".to_string()).parse::<i32>().unwrap_or(-1);
} }
if let Some(line) = lines.next() { if let Some(line) = lines.next() {
let read_name = line.unwrap_or("No Mod Name".to_string()).to_string(); name = line.ok().and_then(|read_name| {
name = string_table.get(&read_name).unwrap_or(&read_name).to_string(); let name = string_table.get(&read_name).or(Some(&read_name)).cloned();
name.filter(|s| !s.is_empty())
});
} }
if let Some(line) = lines.next() { if let Some(line) = lines.next() {
description = line.unwrap_or("No Description".to_string()).to_string(); description = line.ok().filter(|s| !s.is_empty());
} }
} else {
name = path.clone();
description = "mod.txt not found".to_string();
} }
mods.push(ModInfo { id, requirement, priority, save_slot, path, name, description, valid }) mods.push(ModInfo { id, requirement, priority, save_slot, path, name, description, valid })
@ -182,19 +181,15 @@ impl ModList {
Ok(ModList { mods }) Ok(ModList { mods })
} }
pub fn get_save_from_path(&self, mod_path: String) -> i32 { pub fn get_info_from_path(&self, mod_path: String) -> Option<&ModInfo> {
if let Some(mod_sel) = self.mods.iter().find(|x| x.path == mod_path) { self.mods.iter().find(|x| x.path == mod_path)
mod_sel.save_slot
} else {
-1
}
} }
pub fn get_name_from_path(&self, mod_path: String) -> &str { pub fn get_save_from_path(&self, mod_path: String) -> i32 {
if let Some(mod_sel) = self.mods.iter().find(|x| x.path == mod_path) { self.get_info_from_path(mod_path).and_then(|mod_info| Some(mod_info.save_slot)).unwrap_or(-1)
&mod_sel.name }
} else {
"NoName" pub fn get_name_from_path(&self, mod_path: String) -> Option<&str> {
} self.get_info_from_path(mod_path).and_then(|mod_info| mod_info.name.as_deref())
} }
} }

View file

@ -254,8 +254,15 @@ impl Scene for TitleScene {
continue; continue;
} }
if mod_info.satisfies_requirement(&state.mod_requirements) { if mod_info.satisfies_requirement(&state.mod_requirements) {
self.challenges_menu self.challenges_menu.push_entry(
.push_entry(ChallengesMenuEntry::Challenge(idx), MenuEntry::Active(mod_info.name.clone())); ChallengesMenuEntry::Challenge(idx),
MenuEntry::Active(
mod_info
.name
.clone()
.unwrap_or(state.loc.t("menus.challenges_menu.empty_mod_name").to_string()),
),
);
if mutate_selection { if mutate_selection {
selected = ChallengesMenuEntry::Challenge(idx); selected = ChallengesMenuEntry::Challenge(idx);
@ -387,6 +394,7 @@ impl Scene for TitleScene {
} }
CurrentMenu::ChallengesMenu => match self.challenges_menu.tick(&mut self.controller, state) { CurrentMenu::ChallengesMenu => match self.challenges_menu.tick(&mut self.controller, state) {
MenuSelectionResult::Selected(ChallengesMenuEntry::Challenge(idx), _) => { MenuSelectionResult::Selected(ChallengesMenuEntry::Challenge(idx), _) => {
let fallback_mod_name = state.loc.t("menus.challenges_menu.empty_mod_name").to_owned();
if let Some(mod_info) = state.mod_list.mods.get(idx) { if let Some(mod_info) = state.mod_list.mods.get(idx) {
state.mod_path = Some(mod_info.path.clone()); state.mod_path = Some(mod_info.path.clone());
if mod_info.save_slot >= 0 { if mod_info.save_slot >= 0 {
@ -395,7 +403,7 @@ impl Scene for TitleScene {
self.nikumaru_rec.load_counter(state, ctx)?; self.nikumaru_rec.load_counter(state, ctx)?;
self.current_menu = CurrentMenu::SaveSelectMenu; self.current_menu = CurrentMenu::SaveSelectMenu;
} else { } else {
let mod_name = mod_info.name.clone(); let mod_name = mod_info.name.clone().unwrap_or(fallback_mod_name.clone());
self.confirm_menu.width = self.confirm_menu.width =
(state.font.builder().compute_width(&mod_name).max(50.0) + 32.0) as u16; (state.font.builder().compute_width(&mod_name).max(50.0) + 32.0) as u16;