Minor style changes[ci skip]
This commit is contained in:
parent
f4b1fa39dc
commit
cb9a9f3736
|
@ -73,15 +73,15 @@ pub enum TextScriptEncoding {
|
|||
GB18030,
|
||||
GBK,
|
||||
BIG5,
|
||||
WINDOWS_1250,
|
||||
WINDOWS_1251,
|
||||
WINDOWS_1252,
|
||||
WINDOWS_1253,
|
||||
WINDOWS_1254,
|
||||
WINDOWS_1255,
|
||||
WINDOWS_1256,
|
||||
WINDOWS_1257,
|
||||
WINDOWS_1258,
|
||||
Win1250,
|
||||
Win1251,
|
||||
Win1252,
|
||||
Win1253,
|
||||
Win1254,
|
||||
Win1255,
|
||||
Win1256,
|
||||
Win1257,
|
||||
Win1258,
|
||||
}
|
||||
|
||||
impl From<&str> for TextScriptEncoding {
|
||||
|
@ -116,15 +116,15 @@ impl From<&str> for TextScriptEncoding {
|
|||
"gbk" => Self::GBK,
|
||||
"big5" => Self::BIG5,
|
||||
|
||||
"windows-1250" => Self::WINDOWS_1250,
|
||||
"windows-1251" => Self::WINDOWS_1251,
|
||||
"windows-1252" => Self::WINDOWS_1252,
|
||||
"windows-1253" => Self::WINDOWS_1253,
|
||||
"windows-1254" => Self::WINDOWS_1254,
|
||||
"windows-1255" => Self::WINDOWS_1255,
|
||||
"windows-1256" => Self::WINDOWS_1256,
|
||||
"windows-1257" => Self::WINDOWS_1257,
|
||||
"windows-1258" => Self::WINDOWS_1258,
|
||||
"windows-1250" => Self::Win1250,
|
||||
"windows-1251" => Self::Win1251,
|
||||
"windows-1252" => Self::Win1252,
|
||||
"windows-1253" => Self::Win1253,
|
||||
"windows-1254" => Self::Win1254,
|
||||
"windows-1255" => Self::Win1255,
|
||||
"windows-1256" => Self::Win1256,
|
||||
"windows-1257" => Self::Win1257,
|
||||
"windows-1258" => Self::Win1258,
|
||||
|
||||
"utf-16be" => Self::UTF16BE,
|
||||
"utf-16le" => Self::UTF16LE,
|
||||
|
@ -163,24 +163,25 @@ impl From<TextScriptEncoding> for &'static encoding_rs::Encoding {
|
|||
TextScriptEncoding::GB18030 => encoding_rs::GB18030,
|
||||
TextScriptEncoding::GBK => encoding_rs::GBK,
|
||||
TextScriptEncoding::BIG5 => encoding_rs::BIG5,
|
||||
TextScriptEncoding::WINDOWS_1250 => encoding_rs::WINDOWS_1250,
|
||||
TextScriptEncoding::WINDOWS_1251 => encoding_rs::WINDOWS_1251,
|
||||
TextScriptEncoding::WINDOWS_1252 => encoding_rs::WINDOWS_1252,
|
||||
TextScriptEncoding::WINDOWS_1253 => encoding_rs::WINDOWS_1253,
|
||||
TextScriptEncoding::WINDOWS_1254 => encoding_rs::WINDOWS_1254,
|
||||
TextScriptEncoding::WINDOWS_1255 => encoding_rs::WINDOWS_1255,
|
||||
TextScriptEncoding::WINDOWS_1256 => encoding_rs::WINDOWS_1256,
|
||||
TextScriptEncoding::WINDOWS_1257 => encoding_rs::WINDOWS_1257,
|
||||
TextScriptEncoding::WINDOWS_1258 => encoding_rs::WINDOWS_1258,
|
||||
TextScriptEncoding::Win1250 => encoding_rs::WINDOWS_1250,
|
||||
TextScriptEncoding::Win1251 => encoding_rs::WINDOWS_1251,
|
||||
TextScriptEncoding::Win1252 => encoding_rs::WINDOWS_1252,
|
||||
TextScriptEncoding::Win1253 => encoding_rs::WINDOWS_1253,
|
||||
TextScriptEncoding::Win1254 => encoding_rs::WINDOWS_1254,
|
||||
TextScriptEncoding::Win1255 => encoding_rs::WINDOWS_1255,
|
||||
TextScriptEncoding::Win1256 => encoding_rs::WINDOWS_1256,
|
||||
TextScriptEncoding::Win1257 => encoding_rs::WINDOWS_1257,
|
||||
TextScriptEncoding::Win1258 => encoding_rs::WINDOWS_1258,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextScriptEncoding {
|
||||
pub fn invalid_encoding(encoding: TextScriptEncoding, state: &SharedGameState) -> bool {
|
||||
if state.loc.encoding.as_ref().is_some_and(|s| TextScriptEncoding::from(s.as_str()) == encoding) {
|
||||
if state.loc.encoding.is_some_and(|e| e == encoding) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let required_encoding = if (state.loc.code == "jp" || state.loc.code == "en") && state.constants.is_base() {
|
||||
TextScriptEncoding::ShiftJIS
|
||||
} else {
|
||||
|
|
|
@ -577,8 +577,8 @@ impl SharedGameState {
|
|||
locale: &Locale,
|
||||
ctx: &mut Context,
|
||||
) -> GameResult<BMFont> {
|
||||
if let Some(encoding) = locale.encoding.as_ref() {
|
||||
constants.textscript.encoding = TextScriptEncoding::from(encoding.as_str())
|
||||
if let Some(encoding) = locale.encoding {
|
||||
constants.textscript.encoding = encoding
|
||||
} else {
|
||||
if (locale.code == "jp" || locale.code == "en") && constants.is_base() {
|
||||
constants.textscript.encoding = TextScriptEncoding::ShiftJIS
|
||||
|
@ -586,9 +586,8 @@ impl SharedGameState {
|
|||
constants.textscript.encoding = TextScriptEncoding::UTF8
|
||||
}
|
||||
}
|
||||
if let Some(state_encoding) = locale.stage_encoding.as_ref() {
|
||||
constants.stage_encoding = Some(state_encoding.as_str().into());
|
||||
}
|
||||
|
||||
constants.stage_encoding = locale.stage_encoding;
|
||||
|
||||
let font = BMFont::load(&constants.base_paths, &locale.font.path, ctx, locale.font.scale).or_else(|e| {
|
||||
log::warn!("Failed to load font, using built-in: {}", e);
|
||||
|
|
|
@ -3,7 +3,6 @@ use std::str::from_utf8;
|
|||
|
||||
use byteorder::ReadBytesExt;
|
||||
use byteorder::LE;
|
||||
use log::info;
|
||||
|
||||
use crate::common::Color;
|
||||
use crate::engine_constants::EngineConstants;
|
||||
|
@ -12,9 +11,7 @@ use crate::framework::error::GameError::ResourceLoadError;
|
|||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::filesystem;
|
||||
use crate::game::map::{Map, NPCData};
|
||||
use crate::game::scripting::tsc::text_script::TextScript;
|
||||
|
||||
use super::scripting::tsc::text_script::TextScriptEncoding;
|
||||
use crate::game::scripting::tsc::text_script::{TextScript, TextScriptEncoding};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub struct NpcType {
|
||||
|
@ -271,7 +268,7 @@ impl StageData {
|
|||
|
||||
for path in roots.iter().rev() {
|
||||
if let Ok(mut file) = filesystem::open(ctx, [path, stage_tbl_path].join("")) {
|
||||
info!("Loading Cave Story+ stage table from {}", &path);
|
||||
log::info!("Loading Cave Story+ stage table from {}", &path);
|
||||
|
||||
let mut new_stages = Vec::new();
|
||||
|
||||
|
@ -337,7 +334,7 @@ impl StageData {
|
|||
// Cave Story freeware executable dump.
|
||||
let mut stages = Vec::new();
|
||||
|
||||
info!("Loading Cave Story freeware exe dump stage table from {}", &stage_sect_path);
|
||||
log::info!("Loading Cave Story freeware exe dump stage table from {}", &stage_sect_path);
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
@ -394,7 +391,7 @@ impl StageData {
|
|||
// Moustache Rider stage table
|
||||
let mut stages = Vec::new();
|
||||
|
||||
info!("Loading Moustache Rider stage table from {}", &mrmap_bin_path);
|
||||
log::info!("Loading Moustache Rider stage table from {}", &mrmap_bin_path);
|
||||
|
||||
let mut data = Vec::new();
|
||||
|
||||
|
@ -452,7 +449,7 @@ impl StageData {
|
|||
} else if let Ok(mut file) = filesystem::open_find(ctx, roots, stage_dat_path) {
|
||||
let mut stages = Vec::new();
|
||||
|
||||
info!("Loading NXEngine stage table from {}", &stage_dat_path);
|
||||
log::info!("Loading NXEngine stage table from {}", &stage_dat_path);
|
||||
|
||||
let mut data = Vec::new();
|
||||
|
||||
|
|
19
src/i18n.rs
19
src/i18n.rs
|
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::filesystem;
|
||||
use crate::game::scripting::tsc::text_script::TextScriptEncoding;
|
||||
use crate::game::shared_game_state::FontData;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -9,8 +10,8 @@ pub struct Locale {
|
|||
pub code: String,
|
||||
pub name: String,
|
||||
pub font: FontData,
|
||||
pub encoding: Option<String>,
|
||||
pub stage_encoding: Option<String>,
|
||||
pub encoding: Option<TextScriptEncoding>,
|
||||
pub stage_encoding: Option<TextScriptEncoding>,
|
||||
strings: HashMap<String, String>,
|
||||
}
|
||||
|
||||
|
@ -40,10 +41,18 @@ impl Locale {
|
|||
let font_scale = strings["font_scale"].parse::<f32>().unwrap_or(1.0);
|
||||
let font = FontData::new(font_name, font_scale, 0.0);
|
||||
|
||||
let encoding = strings.get("encoding").cloned();
|
||||
let stage_encoding = strings.get("stage_encoding").cloned();
|
||||
let encoding = if let Some(enc) = strings.get("encoding").clone() {
|
||||
Some(TextScriptEncoding::from(enc.as_str()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let stage_encoding = if let Some(enc) = strings.get("stage_encoding").clone() {
|
||||
Some(TextScriptEncoding::from(enc.as_str()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Locale { code: code.to_string(), name, font, encoding, strings, stage_encoding }
|
||||
Locale { code: code.to_string(), name, font, encoding, stage_encoding, strings }
|
||||
}
|
||||
|
||||
fn flatten(json: &serde_json::Value) -> HashMap<String, String> {
|
||||
|
|
Loading…
Reference in New Issue