improve projectiles asset loading

and defining projectile in heads-db
This commit is contained in:
2025-04-13 16:33:10 +02:00
parent 9779e4e6cb
commit b5ac2a9875
7 changed files with 33 additions and 29 deletions

View File

@@ -1,20 +1,20 @@
([
(key:"angry demonstrator", ability:Thrown, range:80),
(key:"carnival knife thrower", range:60),
(key:"chicago gangster", ability:Gun, range:60),
(key:"commando", ability:Gun, range:60),
(key:"field medic"),
(key:"geisha"),
(key:"goblin", ability:Arrow, range:60),
(key:"green grocer", range:60),
(key:"highland hammer thrower", ability:Thrown, range:80),
(key:"legionnaire", ability:Gun, range:60),
(key:"mig pilot", ability:Gun, range:60, controls:Plane),
(key:"nanny", ability:Thrown, range:60),
(key:"panic attack"),
(key:"salty sea dog"),
(key:"snow plough operator"),
(key:"soldier ant"),
(key:"super market shopper", ability:Thrown, range:80),
(key:"troll", ability:Thrown, range:80),
(key:"angry demonstrator", ability:Thrown, range:80, projectile:"molotov"),//0
(key:"carnival knife thrower", range:60),//1
(key:"chicago gangster", ability:Gun, range:60),//2
(key:"commando", ability:Gun, range:60),//3
(key:"field medic"),//4
(key:"geisha"),//5
(key:"goblin", ability:Arrow, range:60),//6
(key:"green grocer", range:60),//7
(key:"highland hammer thrower", ability:Thrown, range:80, projectile:"hammer"),//8
(key:"legionnaire", ability:Gun, range:60),//9
(key:"mig pilot", ability:Gun, range:60, controls:Plane),//10
(key:"nanny", ability:Thrown, range:60),//11
(key:"panic attack"),//12
(key:"salty sea dog"),//13
(key:"snow plough operator"),//14
(key:"soldier ant"),//15
(key:"super market shopper", ability:Thrown, range:80, projectile:"handbag"),//16
(key:"troll", ability:Thrown, range:80),//17
])

Binary file not shown.

View File

@@ -2,6 +2,7 @@ use super::TriggerThrow;
use crate::{
GameState,
billboards::Billboard,
heads_database::HeadsDatabase,
hitpoints::Hit,
loading_assets::GameAssets,
physics_layers::GameLayer,
@@ -88,6 +89,8 @@ fn on_trigger_thrown(
mut commands: Commands,
query_transform: Query<&Transform>,
assets: Res<GameAssets>,
gltf_assets: Res<Assets<Gltf>>,
heads_db: Res<HeadsDatabase>,
) {
let state = trigger.event().0;
@@ -110,10 +113,12 @@ fn on_trigger_thrown(
* (Vec3::new(2., 1., 0.).normalize() * SPEED)
};
let (mesh, explosion_animation) = match state.head {
8 => (assets.hammer.clone(), false),
_ => (assets.molotov.clone(), true),
};
let head = heads_db.head_stats(state.head);
let mesh = assets.projectiles[format!("{}.glb", head.projectile).as_str()].clone();
let asset = gltf_assets.get(&mesh).unwrap();
//TODO: projectile db?
let explosion_animation = !matches!(state.head, 8 | 16);
commands
.spawn((
@@ -134,7 +139,7 @@ fn on_trigger_thrown(
))
.with_child((
AutoRotation(Quat::from_rotation_x(0.4) * Quat::from_rotation_z(0.3)),
SceneRoot(mesh),
SceneRoot(asset.scenes[0].clone()),
));
}

View File

@@ -18,6 +18,8 @@ pub struct HeadStats {
pub range: f32,
#[serde(default)]
pub controls: HeadControls,
#[serde(default)]
pub projectile: String,
}
#[derive(Debug, Asset, Reflect, Serialize, Deserialize)]

View File

@@ -84,12 +84,6 @@ pub struct GameAssets {
#[asset(path = "models/cash.glb#Scene0")]
pub mesh_cash: Handle<Scene>,
#[asset(path = "models/head_misc/molotov_cocktail.glb#Scene0")]
pub molotov: Handle<Scene>,
#[asset(path = "models/head_misc/hammer.glb#Scene0")]
pub hammer: Handle<Scene>,
#[asset(path = "models/alien_naked.glb#Scene0")]
pub mesh_alien: Handle<Scene>,
@@ -102,6 +96,9 @@ pub struct GameAssets {
collection(mapped, typed)
)]
pub animations_alien: HashMap<AssetLabel, Handle<AnimationClip>>,
#[asset(path = "models/projectiles", collection(mapped, typed))]
pub projectiles: HashMap<AssetFileName, Handle<Gltf>>,
}
pub struct LoadingPlugin;