mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-12-08 05:05:40 +00:00
This commit is contained in:
parent
d96f7054e3
commit
7b588f0222
|
|
@ -262,6 +262,7 @@ pub struct EngineConstants {
|
|||
pub npc: NPCConsts,
|
||||
pub weapon: WeaponConsts,
|
||||
pub tex_sizes: CaseInsensitiveHashMap<(u16, u16)>,
|
||||
pub ignore_ogph_textures: Vec<String>,
|
||||
pub textscript: TextScriptConsts,
|
||||
pub title: TitleConsts,
|
||||
pub inventory_dim_color: Color,
|
||||
|
|
@ -1423,6 +1424,10 @@ impl EngineConstants {
|
|||
"Title" => (320, 48),
|
||||
"triangles" => (20, 5),
|
||||
},
|
||||
ignore_ogph_textures: vec![
|
||||
// All in lowercase
|
||||
"title".to_owned(),
|
||||
],
|
||||
textscript: TextScriptConsts {
|
||||
encoding: TextScriptEncoding::ShiftJIS,
|
||||
encrypted: true,
|
||||
|
|
|
|||
|
|
@ -1888,7 +1888,7 @@ impl TextScriptVM {
|
|||
|
||||
for path in &state.constants.credit_illustration_paths {
|
||||
let path = format!("{}Credit{:02}", path, number);
|
||||
if state.texture_set.find_texture(ctx, &state.constants.base_paths, &path).is_some() {
|
||||
if state.texture_set.find_texture(ctx, &state.constants.base_paths, &path, false).is_some() {
|
||||
state.textscript_vm.current_illustration = Some(path);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -516,8 +516,35 @@ impl TextureSet {
|
|||
create_texture(ctx, width as u16, height as u16, &img)
|
||||
}
|
||||
|
||||
pub fn find_texture(&self, ctx: &mut Context, roots: &Vec<String>, name: &str) -> Option<String> {
|
||||
FILE_TYPES.iter().map(|ext| [name, ext].join("")).find(|path| filesystem::exists_find(ctx, roots, path))
|
||||
pub fn find_texture(&self, ctx: &mut Context, roots: &Vec<String>, name: &str, ignore_ogph: bool) -> Option<String> {
|
||||
let mut file_path: Option<String> = None;
|
||||
|
||||
let path = FILE_TYPES.iter().map(|ext| [name, ext].join("")).find(|path| {
|
||||
for root in roots {
|
||||
if ignore_ogph && root.contains("ogph/") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut full_path = root.to_string();
|
||||
full_path.push_str(path);
|
||||
|
||||
if ctx.filesystem.exists(&full_path) {
|
||||
// We assume the first and last character in the root path is /
|
||||
file_path = Some(full_path.split_off(1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
});
|
||||
|
||||
if path.is_some() && ignore_ogph {
|
||||
// Return full path for "always hi-res" textures,
|
||||
// otherwise the ogph version of the texture will be loaded by `Self::load_image`.
|
||||
return file_path;
|
||||
}
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
pub fn load_texture(
|
||||
|
|
@ -526,15 +553,17 @@ impl TextureSet {
|
|||
constants: &EngineConstants,
|
||||
name: &str,
|
||||
) -> GameResult<Box<dyn SpriteBatch>> {
|
||||
let ignore_ogph = constants.ignore_ogph_textures.contains(&(name.to_lowercase()));
|
||||
|
||||
let path = self
|
||||
.find_texture(ctx, &constants.base_paths, name)
|
||||
.find_texture(ctx, &constants.base_paths, name, ignore_ogph)
|
||||
.ok_or_else(|| GameError::ResourceLoadError(format!("Texture \"{}\" is missing.", name)))?;
|
||||
|
||||
let glow_path = self.find_texture(ctx, &constants.base_paths, &[name, ".glow"].join(""));
|
||||
let glow_path = self.find_texture(ctx, &constants.base_paths, &[name, ".glow"].join(""), ignore_ogph);
|
||||
|
||||
info!("Loading texture: {} -> {}", name, path);
|
||||
|
||||
fn make_batch(name: &str, constants: &EngineConstants, batch: Box<dyn BackendTexture>) -> SubBatch {
|
||||
fn make_batch(name: &str, constants: &EngineConstants, batch: Box<dyn BackendTexture>, ignore_ogph: bool) -> SubBatch {
|
||||
let size = batch.dimensions();
|
||||
|
||||
let orig_dimensions = constants.tex_sizes.get(name).unwrap_or(&size);
|
||||
|
|
@ -544,7 +573,7 @@ impl TextureSet {
|
|||
<= f32::EPSILON
|
||||
{
|
||||
orig_dimensions.0 as f32 / size.0 as f32
|
||||
} else if constants.is_cs_plus && constants.base_paths.iter().any(|p| p.contains("/ogph")) {
|
||||
} else if constants.is_cs_plus && constants.base_paths.iter().any(|p| p.contains("/ogph")) && !ignore_ogph {
|
||||
1.0
|
||||
} else if constants.is_cs_plus {
|
||||
0.5
|
||||
|
|
@ -566,9 +595,9 @@ impl TextureSet {
|
|||
}
|
||||
}
|
||||
|
||||
let main_batch = make_batch(name, constants, self.load_image(ctx, &constants.base_paths, &path)?);
|
||||
let main_batch = make_batch(name, constants, self.load_image(ctx, &constants.base_paths, &path)?, ignore_ogph);
|
||||
let glow_batch = if let Some(glow_path) = glow_path {
|
||||
self.load_image(ctx, &constants.base_paths, &glow_path).ok().map(|b| make_batch(name, constants, b))
|
||||
self.load_image(ctx, &constants.base_paths, &glow_path).ok().map(|b| make_batch(name, constants, b, ignore_ogph))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
|||
|
|
@ -488,11 +488,9 @@ impl Scene for TitleScene {
|
|||
|
||||
if self.current_menu == CurrentMenu::MainMenu {
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "Title")?;
|
||||
let logo_x_offset =
|
||||
if state.settings.original_textures && state.constants.supports_og_textures { 20.0 } else { 0.0 };
|
||||
|
||||
batch.add_rect(
|
||||
((state.canvas_size.0 - state.constants.title.logo_rect.width() as f32) / 2.0).floor() + logo_x_offset,
|
||||
((state.canvas_size.0 - state.constants.title.logo_rect.width() as f32) / 2.0).floor(),
|
||||
40.0,
|
||||
&state.constants.title.logo_rect,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue