Skip to content

Commit

Permalink
chore(deps): update rust dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tversteeg committed Mar 8, 2024
1 parent b4026cd commit 8c00260
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 60 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ debug = ["drawille"]

[dependencies]
blit = "0.8"
miette = { version = "5", features = ["fancy"] }
miette = { version = "7", features = ["fancy"] }
image = { version = "0.24", default-features = false, features = ["png"] }
rotsprite = "0.1"
vek = "0.16"
assets_manager = { version = "0.10", features = ["embedded", "hot-reloading", "toml", "png"], default-features = false }
serde = "1"
itertools = "0.12"
parry2d-f64 = { version = "0.13", features = ["simd-stable"] }
Expand All @@ -34,16 +33,17 @@ bitvec = "1"
line_drawing = "1"
drawille = { version = "0.3", optional = true }
spiral = "0.2"
pixel-game-lib = "0.4"
pixel-game-lib = "0.8"
assets_manager = "0.11"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
fastrand = "2"
puffin = "0.17"
puffin_http = "0.14"
puffin = "0.19"
puffin_http = "0.16"

[target.'cfg(target_arch = "wasm32")'.dependencies]
fastrand = { version = "2", default-features = false, features = ["js"] }
puffin = "0.17"
puffin = "0.19"

[workspace]
members = ["run-wasm"]
6 changes: 3 additions & 3 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
# We need 1.70 because we use OnceLock
channel = "1.70"
targets = ["wasm32-unknown-unknown"]
# We need 1.72.1 due to pixel-game-lib
channel = "1.72.1"
targets = ["wasm32-unknown-unknown"]
1 change: 0 additions & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use assets_manager::{AssetCache, AssetGuard, Compound};

use crate::game::Settings;

Expand Down
16 changes: 8 additions & 8 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pixel_game_lib::{
rigidbody::{RigidBodyBuilder, RigidBodyHandle},
Physics,
},
window::{Input, KeyCode},
window::{Input, KeyCode, MouseButton},
};
use serde::Deserialize;
use vek::{Extent2, Vec2};
Expand Down Expand Up @@ -162,15 +162,15 @@ impl DebugDraw {
self.physics.step(dt, &crate::settings().physics);
}

if input.mouse_released(0) {
if input.mouse_released(MouseButton::Left) {
// Spawn a projectile at the mouse coordinates, camera doesn't apply to local physics engine
let object = crate::asset::<ObjectSettings>(CRATE);
let object = pixel_game_lib::asset::<ObjectSettings>(CRATE);
self.boxes
.push(object.rigidbody_builder(mouse).spawn(&mut self.physics));
}
}

if self.screen == DebugScreen::SpawnProjectiles && input.mouse_released(0) {
if self.screen == DebugScreen::SpawnProjectiles && input.mouse_released(MouseButton::Left) {
// Spawn a projectile at the mouse coordinates
projectiles.push(Projectile::new(
camera.translate_from_screen(self.mouse),
Expand All @@ -179,12 +179,12 @@ impl DebugDraw {
));
}

if self.screen == DebugScreen::Terrain && input.mouse_released(0) {
if self.screen == DebugScreen::Terrain && input.mouse_released(MouseButton::Left) {
// Click to slice the terrain
terrain.remove_circle(camera.translate_from_screen(mouse), 10.0, physics);
}

if self.screen == DebugScreen::Shape && input.mouse_released(0) {
if self.screen == DebugScreen::Shape && input.mouse_released(MouseButton::Left) {
// Click to slice the terrain
let mut new_shapes = Vec::new();
for shape in self.shapes.iter_mut() {
Expand Down Expand Up @@ -251,13 +251,13 @@ impl DebugDraw {
}
DebugScreen::Collisions => {
// Draw collision between rotated rectangles
let object = crate::asset::<ObjectSettings>(SPEAR);
let object = pixel_game_lib::asset::<ObjectSettings>(SPEAR);
let shape = object.shape();

let mouse_iso = Iso::new(self.mouse.as_(), Rotation::from_degrees(-23f64));

// Detect collisions with the heightmap
let level_object = crate::asset::<ObjectSettings>(LEVEL);
let level_object = pixel_game_lib::asset::<ObjectSettings>(LEVEL);
let level_pos = Vec2::new(0.0, 100.0);
let level_iso = Iso::from_pos(level_pos);

Expand Down
47 changes: 11 additions & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod assets;
mod camera;
#[cfg(feature = "debug")]
mod debug;
Expand All @@ -17,8 +16,7 @@ mod unit;

use std::sync::OnceLock;

use assets::Assets;
use assets_manager::{AssetGuard, Compound};
use assets_manager::{AssetReadGuard, Compound};
use font::Font;
use game::{GameState, Settings};
use miette::Result;
Expand All @@ -33,50 +31,27 @@ pub const SIZE: Extent2<usize> = Extent2::new(640, 360);
/// Updates per second of the update loop.
const UPDATES_PER_SECOND: u32 = 60;

/// The assets as a 'static reference.
pub static ASSETS: OnceLock<Assets> = OnceLock::new();

/// Load an generic asset.
pub fn asset<T>(path: &str) -> AssetGuard<T>
where
T: Compound,
{
puffin::profile_function!();

ASSETS
.get()
.expect("Asset handling not initialized yet")
.asset(path)
}

/// Load the global settings.
pub fn settings() -> AssetGuard<'static, Settings> {
ASSETS
.get()
.expect("Asset handling not initialized yet")
.settings()
/// Load the settings.
pub fn settings() -> AssetReadGuard<'static, Settings> {
pixel_game_lib::asset("settings")
}

/// Load a sprite.
pub fn sprite(path: &str) -> AssetGuard<Sprite> {
crate::asset(path)
pub fn sprite(path: &str) -> AssetReadGuard<Sprite> {
pixel_game_lib::asset(path)
}

/// Load a rotatable sprite.
pub fn rotatable_sprite(path: &str) -> AssetGuard<RotatableSprite> {
crate::asset(path)
pub fn rotatable_sprite(path: &str) -> AssetReadGuard<RotatableSprite> {
pixel_game_lib::asset(path)
}

/// Load a font.
pub fn font(path: &str) -> AssetGuard<Font> {
crate::asset(path)
pub fn font(path: &str) -> AssetReadGuard<Font> {
pixel_game_lib::asset(path)
}

fn main() -> Result<()> {
// Initialize the asset loader
let assets = ASSETS.get_or_init(Assets::load);
assets.enable_hot_reloading();

// Construct the game
let state = GameState::new();

Expand All @@ -98,7 +73,7 @@ fn main() -> Result<()> {
buffer_size: SIZE,
title: "Castle Game".to_string(),
updates_per_second: UPDATES_PER_SECOND,
scaling: 2,
scaling: 4,
},
|g, input, mouse, dt| {
puffin::profile_scope!("Update");
Expand Down
2 changes: 1 addition & 1 deletion src/projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Projectile {
puffin::profile_function!();

// Load the object definition for properties of the object
let object = crate::asset::<ObjectSettings>(ASSET_PATH);
let object = pixel_game_lib::asset::<ObjectSettings>(ASSET_PATH);

let rigidbody = object
.rigidbody_builder(pos)
Expand Down
10 changes: 5 additions & 5 deletions src/unit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use assets_manager::{loader::TomlLoader, Asset, AssetGuard};
use assets_manager::{loader::TomlLoader, Asset, AssetReadGuard};
use pixel_game_lib::physics::{rigidbody::RigidBodyHandle, Physics};
use serde::Deserialize;
use vek::{Extent2, Vec2};
Expand All @@ -17,14 +17,14 @@ pub enum UnitType {

impl UnitType {
/// Settings path to load for this type.
pub fn settings(&self) -> AssetGuard<Settings> {
pub fn settings(&self) -> AssetReadGuard<Settings> {
// Settings asset path
let path = match self {
Self::PlayerSpear => "unit.spear",
Self::EnemySpear => "unit.enemy-spear",
};

crate::asset(path)
pixel_game_lib::asset(path)
}

/// Asset path based on what type to load.
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Unit {
let health = r#type.settings().health;

// Load the object definition for properties of the object
let object = crate::asset::<ObjectSettings>(r#type.asset_path());
let object = pixel_game_lib::asset::<ObjectSettings>(r#type.asset_path());
let rigidbody = object.rigidbody_builder(pos).spawn(physics);

Self {
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Unit {
}

/// The settings for this unit.
fn settings(&self) -> AssetGuard<Settings> {
fn settings(&self) -> AssetReadGuard<Settings> {
self.r#type.settings()
}
}
Expand Down

0 comments on commit 8c00260

Please sign in to comment.