diff options
| -rw-r--r-- | Cargo.lock | 16 | ||||
| -rw-r--r-- | crates/teleia/Cargo.toml | 14 | ||||
| -rw-r--r-- | crates/teleia/src/shader.rs | 9 | ||||
| -rw-r--r-- | crates/teleia/src/state.rs | 32 | ||||
| -rw-r--r-- | crates/teleia_macros/src/lib.rs | 2 |
5 files changed, 27 insertions, 46 deletions
@@ -810,21 +810,11 @@ dependencies = [ ] [[package]] -name = "fontconfig-parser" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646" -dependencies = [ - "roxmltree", -] - -[[package]] name = "fontdb" version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" dependencies = [ - "fontconfig-parser", "log", "memmap2", "slotmap", @@ -1845,12 +1835,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30" [[package]] -name = "roxmltree" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" - -[[package]] name = "rstar" version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/crates/teleia/Cargo.toml b/crates/teleia/Cargo.toml index bc17d9c..5382630 100644 --- a/crates/teleia/Cargo.toml +++ b/crates/teleia/Cargo.toml @@ -8,18 +8,18 @@ authors.workspace = true crate-type = ["cdylib", "rlib"] [dependencies] -strum = {version = "*", features = ["derive"]} # utility macros for enums -glow = {version = "=0.13.1", features = []} # rendering +strum = { version = "*", features = ["derive"] } # utility macros for enums +glow = { version = "=0.13.1", features = [] } # rendering tobj = "*" # loader for .obj meshes loader -gltf = {git = "https://github.com/lcolonq/gltf", features = ["extras", "import", "names", "utils"]} # loader for .gltf scenes +gltf = { git = "https://github.com/lcolonq/gltf", features = ["extras", "import", "names", "utils"] } # loader for .gltf scenes image = { version = "0.25", default-features = false, features = ["jpeg", "png"] } # texture loader -cosmic-text = "*" # advanced text rendering +cosmic-text = { version = "*", default-features = false, features = ["std", "swash"] } # advanced text rendering glam = "0.29" # linear algebra log = "*" # logging -rand = {version = "=0.8.5", features = ["small_rng"]} # rng -serde = {version = "*", features = ["derive"]} # serialization +rand = { version = "=0.8.5", features = ["small_rng"] } # rng +serde = { version = "*", features = ["derive"] } # serialization serde_json = "*" # serialize JSON -bincode = {version = "*", features = ["serde"]} # binary serialization +bincode = { version = "*", features = ["serde"] } # binary serialization enum-map = "*" # fast maps with enums as keys bimap = "*" # bijective maps # reqwest = "*" # http requests diff --git a/crates/teleia/src/shader.rs b/crates/teleia/src/shader.rs index 5a343ef..610e1ba 100644 --- a/crates/teleia/src/shader.rs +++ b/crates/teleia/src/shader.rs @@ -236,15 +236,6 @@ impl Shader { self.set_position_2d_helper(ctx, st, pos, dims, &glam::Quat::IDENTITY) } - pub fn set_texture_offset(&self, ctx: &context::Context, inc: i32, x: i32, y: i32) { - let count = inc as f32; - let ratio = 1.0 / count; - self.set_vec3( - ctx, "texture_offset", - &glam::Vec3::new((x % inc) as f32 * ratio, (y % inc) as f32 * ratio, count) - ); - } - pub fn bind(&self, ctx: &context::Context) { unsafe { ctx.gl.use_program(Some(self.program)); diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs index 270ea8c..76be948 100644 --- a/crates/teleia/src/state.rs +++ b/crates/teleia/src/state.rs @@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Display}; use bimap::BiHashMap; use enum_map::{enum_map, Enum, EnumMap}; use serde::{Serialize, Deserialize}; +use strum::EnumIter; use crate::{audio, context, framebuffer, mesh, shader, utils}; @@ -39,17 +40,12 @@ pub trait Game { fn render(&mut self, ctx: &context::Context, st: &mut State) -> utils::Erm<()> { Ok(()) } } -#[derive(Debug, Enum, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Debug, Enum, EnumIter, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Key { Up, Down, Left, Right, - A, B, L, R, + A, B, X, Y, L, R, Start, Select, } -pub const KEYS: [Key; 10] = [ - Key::Up, Key::Down, Key::Left, Key::Right, - Key::A, Key::B, Key::L, Key::R, - Key::Start, Key::Select, -]; pub struct Keys { pub pressed: EnumMap<Key, bool>, pub new: EnumMap<Key, bool>, @@ -59,12 +55,14 @@ impl Keys { Self { pressed: enum_map! { Key::Up => false, Key::Down => false, Key::Left => false, Key::Right => false, - Key::A => false, Key::B => false, Key::L => false, Key::R => false, + Key::A => false, Key::B => false, Key::X => false, Key::Y => false, + Key::L => false, Key::R => false, Key::Start => false, Key::Select => false, }, new: enum_map! { Key::Up => false, Key::Down => false, Key::Left => false, Key::Right => false, - Key::A => false, Key::B => false, Key::L => false, Key::R => false, + Key::A => false, Key::B => false, Key::X => false, Key::Y => false, + Key::L => false, Key::R => false, Key::Start => false, Key::Select => false, }, } @@ -75,6 +73,8 @@ impl Keys { pub fn right(&self) -> bool { self.pressed[Key::Right] } pub fn a(&self) -> bool { self.pressed[Key::A] } pub fn b(&self) -> bool { self.pressed[Key::B] } + pub fn x(&self) -> bool { self.pressed[Key::X] } + pub fn y(&self) -> bool { self.pressed[Key::Y] } pub fn l(&self) -> bool { self.pressed[Key::L] } pub fn r(&self) -> bool { self.pressed[Key::R] } pub fn start(&self) -> bool { self.pressed[Key::Start] } @@ -85,6 +85,8 @@ impl Keys { pub fn new_right(&mut self) -> bool { let ret = self.new[Key::Right]; self.new[Key::Right] = false; ret } pub fn new_a(&mut self) -> bool { let ret = self.new[Key::A]; self.new[Key::A] = false; ret } pub fn new_b(&mut self) -> bool { let ret = self.new[Key::B]; self.new[Key::B] = false; ret } + pub fn new_x(&mut self) -> bool { let ret = self.new[Key::X]; self.new[Key::X] = false; ret } + pub fn new_y(&mut self) -> bool { let ret = self.new[Key::Y]; self.new[Key::Y] = false; ret } pub fn new_l(&mut self) -> bool { let ret = self.new[Key::L]; self.new[Key::L] = false; ret } pub fn new_r(&mut self) -> bool { let ret = self.new[Key::R]; self.new[Key::R] = false; ret } pub fn new_start(&mut self) -> bool { let ret = self.new[Key::Start]; self.new[Key::Start] = false; ret } @@ -214,6 +216,8 @@ pub fn default_keybindings() -> BiHashMap<Keycode, Key> { (Keycode::new(winit::keyboard::KeyCode::KeyD), Key::Right), (Keycode::new(winit::keyboard::KeyCode::Digit1), Key::A), (Keycode::new(winit::keyboard::KeyCode::Digit2), Key::B), + (Keycode::new(winit::keyboard::KeyCode::Digit3), Key::X), + (Keycode::new(winit::keyboard::KeyCode::Digit4), Key::Y), (Keycode::new(winit::keyboard::KeyCode::KeyQ), Key::L), (Keycode::new(winit::keyboard::KeyCode::KeyE), Key::R), (Keycode::new(winit::keyboard::KeyCode::Tab), Key::Start), @@ -230,6 +234,8 @@ pub fn default_keybindings() -> BiHashMap<Keycode, Key> { (Keycode::new(glfw::Key::D), Key::Right), (Keycode::new(glfw::Key::Num1), Key::A), (Keycode::new(glfw::Key::Num2), Key::B), + (Keycode::new(glfw::Key::Num3), Key::X), + (Keycode::new(glfw::Key::Num4), Key::Y), (Keycode::new(glfw::Key::Q), Key::L), (Keycode::new(glfw::Key::E), Key::R), (Keycode::new(glfw::Key::Tab), Key::Start), @@ -503,16 +509,16 @@ impl State { } /// Return the first keybinding for the given virtual key - pub fn keybinding_for(&self, k: &Key) -> Option<String> { - if let Some(kc) = self.keybindings.get_by_right(k) { + pub fn keybinding_for(&self, k: Key) -> Option<String> { + if let Some(kc) = self.keybindings.get_by_right(&k) { Some(format!("{}", kc)) } else { None } } - pub fn rebind_key(&mut self, k: &Key) { - self.rebinding = Some(*k); + pub fn rebind_key(&mut self, k: Key) { + self.rebinding = Some(k); } // pub fn request<F>(&mut self, f: F) diff --git a/crates/teleia_macros/src/lib.rs b/crates/teleia_macros/src/lib.rs index 664fc01..ead8f50 100644 --- a/crates/teleia_macros/src/lib.rs +++ b/crates/teleia_macros/src/lib.rs @@ -85,7 +85,7 @@ impl Field { _ => panic!("unknown asset type: {}", self.nm), }; let enums: Vec<_> = ents.iter().map(|(e, _)| e.clone()).collect(); - let edecl = format!("#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, enum_map::Enum)] + let edecl = format!("#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, enum_map::Enum)] pub enum {} {{ {} }}", enm, enums.join(", ")); let decl = format!("pub {}: enum_map::EnumMap<{}, {}>", self.nm, enm, ty); let inits: Vec<_> = ents.into_iter().map(|(e, exp)| format!("{}::{} => {}", enm, e, exp)).collect(); |
