Skip to content

Commit

Permalink
WIP: other version updates, sorry
Browse files Browse the repository at this point in the history
  • Loading branch information
ozkriff committed Mar 22, 2024
1 parent 9114626 commit f39e0de
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 429 deletions.
499 changes: 204 additions & 295 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assets = "assets/"
[dependencies]
ron = "0.8"
log = "0.4"
env_logger = "0.10"
env_logger = "0.11"
derive_more = { version = "0.99", features = ["from"] } # TODO: https://github.com/ozkriff/zemeroth/issues/251
serde = { version = "1.0", features = ["derive"] }
num = { version = "0.4", default-features = false }
Expand All @@ -27,8 +27,8 @@ zscene = { path = "zscene" }
zcomponents = { path = "zcomponents" }
rand = { version = "0.8", default-features = false, features = ["alloc"] }
quad-rand = { version = "0.2", features = ["rand"] }
mq = { package = "macroquad", version = "0.3" }
heck = "0.4.1"
mq = { package = "macroquad", version = "0.4" }
heck = "0.5"
once_cell = "1.6"

[dev-dependencies]
Expand Down
5 changes: 1 addition & 4 deletions src/core/battle/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use crate::core::{
utils,
};

pub use self::{
apply::apply,
private::{BattleResult, State},
};
pub use self::private::{BattleResult, State};

mod apply;
mod private;
Expand Down
2 changes: 1 addition & 1 deletion src/core/battle/state/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn apply_event_use_ability(state: &mut State, event: &event::UseAbility) {
}
Ability::Summon => {
assert!(parts.summoner.get_opt(id).is_some());
let mut summoner = parts.summoner.get_mut(id);
let summoner = parts.summoner.get_mut(id);
summoner.count += 1;
}
_ => {}
Expand Down
9 changes: 3 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ pub enum ZError {
path: PathBuf,
},
IO(io::Error),
MqFile(mq::file::FileError),
MqFont(mq::text::FontError),
Mq(mq::Error),
}

impl ZError {
Expand All @@ -29,8 +28,7 @@ impl fmt::Display for ZError {
write!(f, "Can't deserialize '{}': {}", s, error)
}
ZError::IO(ref e) => write!(f, "IO Error: {}", e),
ZError::MqFile(ref e) => write!(f, "Macroquad File error: {}", e),
ZError::MqFont(ref e) => write!(f, "Macroquad Font error: {}", e),
ZError::Mq(ref e) => write!(f, "Macroquad error: {}", e),
}
}
}
Expand All @@ -42,8 +40,7 @@ impl error::Error for ZError {
ZError::Scene(ref e) => Some(e),
ZError::RonDeserialize { error, .. } => Some(error),
ZError::IO(ref e) => Some(e),
ZError::MqFile(ref e) => Some(e),
ZError::MqFont(ref e) => Some(e),
ZError::Mq(ref e) => Some(e),
}
}
}
16 changes: 8 additions & 8 deletions src/screen/agent_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn agent_image(typename: &ObjType) -> ZResult<Box<dyn ui::Widget>> {
let h = 0.3;
let assets = &assets::get();
let default_frame = "";
let texture = Drawable::Texture(assets.sprite_frames[typename][default_frame]);
let texture = Drawable::Texture(assets.sprite_frames[typename][default_frame].clone());
let label = ui::Label::new(texture, h)?
.with_color(Color::new(1.0, 1.0, 1.0, 1.0))
.stretchable(true);
Expand All @@ -76,15 +76,15 @@ fn info_panel(
prototypes: &Prototypes,
typename: &ObjType,
) -> ZResult<Box<dyn ui::Widget>> {
let font = assets::get().font;
let font = assets::get().font.clone();
let proto = &prototypes.0[typename];
let info = StaticObjectInfo::new(typename, proto);
let h = utils::line_heights().normal;
let space_between_buttons = h / 8.0;
let mut layout = Box::new(ui::VLayout::new().stretchable(true));
layout.add(agent_image(typename)?);
let mut add = |w| layout.add(w);
let text_ = |s: &str| ui::Drawable::text(s, font);
let text_ = |s: &str| ui::Drawable::text(s, font.clone());
let label_ = |text: &str| -> ZResult<_> { Ok(ui::Label::new(text_(text), h)?) };
let label = |text: &str| -> ZResult<Box<_>> { Ok(Box::new(label_(text)?)) };
let label_s = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?.stretchable(true))) };
Expand Down Expand Up @@ -148,7 +148,7 @@ fn info_panel(
let mut line_layout = ui::HLayout::new().stretchable(true);
line_layout.add(label(&text)?);
line_layout.add(spacer_s());
let icon = Drawable::Texture(assets::get().textures.icons.info);
let icon = Drawable::Texture(assets::get().textures.icons.info.clone());
let message = Message::AbilityInfo(r_ability.ability);
let button = ui::Button::new(icon, h, gui.sender(), message)?;
line_layout.add(Box::new(button));
Expand All @@ -164,7 +164,7 @@ fn info_panel(
let mut line_layout = ui::HLayout::new().stretchable(true);
line_layout.add(label(&ability.title())?);
line_layout.add(spacer_s());
let icon = Drawable::Texture(assets::get().textures.icons.info);
let icon = Drawable::Texture(assets::get().textures.icons.info.clone());
let message = Message::PassiveAbilityInfo(ability);
let button = ui::Button::new(icon, h, gui.sender(), message)?;
line_layout.add(Box::new(button));
Expand All @@ -179,7 +179,7 @@ fn info_panel(
}

fn button_back(gui: &mut ui::Gui<Message>, layout_width: f32) -> ZResult<Box<dyn ui::Widget>> {
let font = assets::get().font;
let font = assets::get().font.clone();
let h = utils::line_heights().normal;
let text = ui::Drawable::text("back", font);
let msg = Message::Back;
Expand Down Expand Up @@ -213,7 +213,7 @@ impl AgentInfo {
from: &ObjType,
to: &ObjType,
) -> ZResult<Self> {
let font = assets::get().font;
let font = assets::get().font.clone();
let mut gui = ui::Gui::new();
let mut layout = ui::VLayout::new();
let h = utils::line_heights().big;
Expand All @@ -226,7 +226,7 @@ impl AgentInfo {
let col = {
let mut col = Box::new(ui::VLayout::new());
col.add(Box::new(ui::Spacer::new_vertical(panel_from_height * 0.5)));
let text = ui::Drawable::text("=>", font);
let text = ui::Drawable::text("=>", font.clone());
col.add(Box::new(ui::Label::new(text, h)?));
col
};
Expand Down
30 changes: 15 additions & 15 deletions src/screen/battle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fn line_with_info_button(
message: Message,
) -> ZResult<Box<dyn ui::Widget>> {
let h = line_heights().normal;
let font = assets::get().font;
let icon = textures().icons.info;
let font = assets::get().font.clone();
let icon = textures().icons.info.clone();
let button = ui::Button::new(ui::Drawable::Texture(icon), h, gui.sender(), message)?;
let mut line = Box::new(ui::HLayout::new().stretchable(true));
line.add(Box::new(ui::Label::new(ui::Drawable::text(text, font), h)?));
Expand All @@ -74,7 +74,7 @@ fn line_with_info_button(

// TODO: consider moving ui `build_*` functions to a sub-module
fn build_panel_agent_info(gui: &mut Gui<Message>, state: &State, id: Id) -> ZResult<ui::RcWidget> {
let font = assets::get().font;
let font = assets::get().font.clone();
let parts = state.parts();
let st = parts.strength.get(id);
let meta = parts.meta.get(id);
Expand All @@ -83,7 +83,7 @@ fn build_panel_agent_info(gui: &mut Gui<Message>, state: &State, id: Id) -> ZRes
let h = line_heights().normal;
let space_between_buttons = h / 8.0;
let mut add = |w| layout.add(w);
let text_ = |s: &str| ui::Drawable::text(s, font);
let text_ = |s: &str| ui::Drawable::text(s, font.clone());
let label_ = |text: &str| -> ZResult<_> { Ok(ui::Label::new(text_(text), h)?) };
let label = |text: &str| -> ZResult<Box<dyn Widget>> { Ok(Box::new(label_(text)?)) };
let label_s = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?.stretchable(true))) };
Expand All @@ -102,7 +102,7 @@ fn build_panel_agent_info(gui: &mut Gui<Message>, state: &State, id: Id) -> ZRes
drawable_k: 0.3,
..Default::default()
};
let label_dot = ui::Label::from_params(ui::Drawable::Texture(textures().dot), h, param)?
let label_dot = ui::Label::from_params(ui::Drawable::Texture(textures().dot.clone()), h, param)?
.with_color(dot_color);
line.add(Box::new(label_dot));
line.add(Box::new(ui::Spacer::new_horizontal(h * 0.1)));
Expand Down Expand Up @@ -185,8 +185,8 @@ fn build_panel_agent_info(gui: &mut Gui<Message>, state: &State, id: Id) -> ZRes
effect::Duration::Rounds(n) => format!("{} ({}t)", s, n),
};
let message = Message::LastingEffectInfo(effect.effect);
let text = ui::Drawable::text(text, font);
let tex_info = ui::Drawable::Texture(textures().icons.info);
let text = ui::Drawable::text(text, font.clone());
let tex_info = ui::Drawable::Texture(textures().icons.info.clone());
let button_info = ui::Button::new(tex_info, h, gui.sender(), message)?;
let icon_effect = visualize::get_effect_icon(&effect.effect);
let param = ui::LabelParam {
Expand Down Expand Up @@ -222,7 +222,7 @@ fn build_panel_agent_abilities(
id: Id,
mode: &SelectionMode,
) -> ZResult<Option<ui::RcWidget>> {
let font = assets::get().font;
let font = &assets::get().font;
let parts = state.parts();
let abilities = match parts.abilities.get_opt(id) {
Some(abilities) => &abilities.0,
Expand All @@ -232,8 +232,8 @@ fn build_panel_agent_abilities(
let h = line_heights().large;
for ability in abilities {
let icons = &assets::get().textures.icons.abilities;
let texture = *icons.get(&ability.ability).expect("No such icon found");
let drawable = ui::Drawable::Texture(texture);
let texture = icons.get(&ability.ability).expect("No such icon found");
let drawable = ui::Drawable::Texture(texture.clone());
let msg = Message::Ability(ability.ability);
let mut button = ui::Button::new(drawable, h, gui.sender(), msg)?;
if !state::can_agent_use_ability(state, id, &ability.ability) {
Expand All @@ -247,7 +247,7 @@ fn build_panel_agent_abilities(
if let ability::Status::Cooldown(n) = ability.status {
let mut layers = ui::LayersLayout::new();
layers.add(Box::new(button));
let text = ui::Drawable::text(format!(" ({})", n).as_str(), font);
let text = ui::Drawable::text(format!(" ({})", n).as_str(), font.clone());
let label = ui::Label::new(text, h / 2.0)?;
layers.add(Box::new(label));
layout.add(Box::new(layers));
Expand All @@ -264,7 +264,7 @@ fn build_panel_agent_abilities(

fn build_panel_end_turn(gui: &mut Gui<Message>) -> ZResult<ui::RcWidget> {
let h = line_heights().large;
let tex = ui::Drawable::Texture(textures().icons.end_turn);
let tex = ui::Drawable::Texture(textures().icons.end_turn.clone());
let button = ui::Button::new(tex, h, gui.sender(), Message::EndTurn)?;
let layout = ui::VLayout::from_widget(Box::new(button));
let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom);
Expand All @@ -279,8 +279,8 @@ fn build_panel_ability_description(
ability: &Ability,
id: Id,
) -> ZResult<ui::RcWidget> {
let font = assets::get().font;
let text = |s: &str| ui::Drawable::text(s, font);
let font = &assets::get().font;
let text = |s: &str| ui::Drawable::text(s, font.clone());
let h = line_heights().normal;
let mut layout = Box::new(ui::VLayout::new().stretchable(true));
let text_title = text(&format!("~~~ {} ~~~", ability.title()));
Expand Down Expand Up @@ -326,7 +326,7 @@ fn build_panel_ability_description(
fn make_gui() -> ZResult<ui::Gui<Message>> {
let mut gui = ui::Gui::new();
let h = line_heights().large;
let icon = textures().icons.main_menu;
let icon = textures().icons.main_menu.clone();
let button = ui::Button::new(ui::Drawable::Texture(icon), h, gui.sender(), Message::Exit)?;
let layout = ui::VLayout::from_widget(Box::new(button));
let anchor = ui::Anchor(ui::HAnchor::Left, ui::VAnchor::Top);
Expand Down
12 changes: 6 additions & 6 deletions src/screen/battle/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl BattleView {
let tile_size = tile_size(map_diameter);
let make_marker_sprite = |color: Color| -> ZResult<Sprite> {
let h = tile_size * 2.0 * geom::FLATNESS_COEFFICIENT;
let mut sprite = Sprite::from_texture(textures().map.selection, h);
let mut sprite = Sprite::from_texture(&textures().map.selection, h);
sprite.set_centered(true);
sprite.set_color(color);
Ok(sprite)
Expand Down Expand Up @@ -470,7 +470,7 @@ impl BattleView {

fn highlight_tile(&mut self, pos: PosHex, color: Color) -> ZResult {
let size = self.tile_size() * 2.0 * geom::FLATNESS_COEFFICIENT;
let mut sprite = Sprite::from_texture(textures().map.white_hex, size);
let mut sprite = Sprite::from_texture(&textures().map.white_hex, size);
let color_from = Color { a: 0.0, ..color };
sprite.set_centered(true);
sprite.set_color(color_from);
Expand All @@ -491,7 +491,7 @@ impl BattleView {
let chances = hit_chance(state, attacker_id, target_id);
let pos = hex_to_point(self.tile_size(), target_pos);
let text = format!("{}%", chances.1 * 10);
let font = assets::get().font;
let font = &assets::get().font;
let mut sprite = Sprite::from_text((text.as_str(), font), 0.1);
sprite.set_pos(pos);
sprite.set_centered(true);
Expand All @@ -506,8 +506,8 @@ impl BattleView {
fn make_action_show_tile(state: &State, view: &BattleView, at: PosHex) -> ZResult<Box<dyn Action>> {
let screen_pos = hex_to_point(view.tile_size(), at);
let texture = match state.map().tile(at) {
TileType::Plain => textures().map.tile,
TileType::Rocks => textures().map.tile_rocks,
TileType::Plain => &textures().map.tile,
TileType::Rocks => &textures().map.tile_rocks,
};
let size = view.tile_size() * 2.0 * geom::FLATNESS_COEFFICIENT;
let mut sprite = Sprite::from_texture(texture, size);
Expand All @@ -518,7 +518,7 @@ fn make_action_show_tile(state: &State, view: &BattleView, at: PosHex) -> ZResul

fn make_action_grass(view: &BattleView, at: PosHex) -> ZResult<Box<dyn Action>> {
let screen_pos = hex_to_point(view.tile_size(), at);
let mut sprite = Sprite::from_texture(textures().map.grass, view.tile_size() * 2.0);
let mut sprite = Sprite::from_texture(&textures().map.grass, view.tile_size() * 2.0);
let v_offset = view.tile_size() * 0.5; // depends on the image
let mut screen_pos_grass = screen_pos + geom::rand_tile_offset(view.tile_size(), 0.5);
screen_pos_grass.y -= v_offset;
Expand Down
Loading

0 comments on commit f39e0de

Please sign in to comment.