|
|
|
|
@ -28,7 +28,6 @@ pub(crate) struct Display3dPlugin;
|
|
|
|
|
impl Plugin for Display3dPlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_plugins(TemporalAntiAliasPlugin)
|
|
|
|
|
.add_systems(OnEnter(GameState::Loading), load_assets)
|
|
|
|
|
.insert_resource(Msaa::Off)
|
|
|
|
|
.add_systems(
|
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
|
@ -37,6 +36,9 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
(
|
|
|
|
|
load_assets
|
|
|
|
|
.run_if(in_state(GameState::Loading))
|
|
|
|
|
.run_if(on_event::<AssetEvent<Tweakfile>>()),
|
|
|
|
|
hydrate_camera.run_if(any_component_added::<Camera3d>),
|
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece>),
|
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>),
|
|
|
|
|
@ -119,7 +121,11 @@ fn load_assets(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
|
|
|
|
|
let hitbox_shape = meshes.add(shape::Box::new(1.0, 0.1, 1.0).into());
|
|
|
|
|
let hitbox_material = materials.add(StandardMaterial {
|
|
|
|
|
base_color: Color::NONE,
|
|
|
|
|
@ -129,8 +135,8 @@ fn load_assets(
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
commands.insert_resource(AssetsMap {
|
|
|
|
|
models: server.load("models/Martian Chess.glb"),
|
|
|
|
|
skybox: server.load("images/skybox.png"),
|
|
|
|
|
models: server.load(tweak.display3d.models.assets_file.as_str()),
|
|
|
|
|
skybox: server.load(tweak.display3d.models.skybox_file.as_str()),
|
|
|
|
|
hitbox_shape,
|
|
|
|
|
hitbox_material,
|
|
|
|
|
});
|
|
|
|
|
@ -196,7 +202,11 @@ fn hydrate_camera(
|
|
|
|
|
state: Res<State<game::TurnState>>,
|
|
|
|
|
mut players: Query<&mut AnimationPlayer>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
events
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|(name, _)| name.as_str() == "GameCam")
|
|
|
|
|
@ -209,7 +219,7 @@ fn hydrate_camera(
|
|
|
|
|
Camera3dBundle {
|
|
|
|
|
camera: Camera {
|
|
|
|
|
is_active: false,
|
|
|
|
|
hdr: true,
|
|
|
|
|
hdr: tweak.display3d.hdr,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
dither: DebandDither::Enabled,
|
|
|
|
|
@ -235,8 +245,12 @@ fn hydrate_camera(
|
|
|
|
|
debug!("Animations: {:?}", gltf.named_animations.keys());
|
|
|
|
|
// GameCamIntro1, GameCamIntro2, GameCamSide1>2, GameCamSide2>1
|
|
|
|
|
let animation = match state.get() {
|
|
|
|
|
game::TurnState::SideA => gltf.named_animations.get("GameCamIntro1"),
|
|
|
|
|
game::TurnState::SideB => gltf.named_animations.get("GameCamIntro2"),
|
|
|
|
|
game::TurnState::SideA => gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.intro_a.as_str()),
|
|
|
|
|
game::TurnState::SideB => gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.intro_b.as_str()),
|
|
|
|
|
};
|
|
|
|
|
player
|
|
|
|
|
.play(animation.expect("Camera Startup").clone())
|
|
|
|
|
@ -312,13 +326,23 @@ fn set_piece_model(
|
|
|
|
|
mut events: Query<(&mut Handle<Scene>, &Piece), (Added<game::Piece>, With<Display3d>)>,
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
events.iter_mut().for_each(|(mut handle, piece)| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
*handle = match piece {
|
|
|
|
|
game::Piece::Pawn => gltf.named_scenes.get("Pawn"),
|
|
|
|
|
game::Piece::Drone => gltf.named_scenes.get("Drone"),
|
|
|
|
|
game::Piece::Queen => gltf.named_scenes.get("Queen"),
|
|
|
|
|
game::Piece::Pawn => gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get(tweak.display3d.models.scenes.pawn.as_str()),
|
|
|
|
|
game::Piece::Drone => gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get(tweak.display3d.models.scenes.drone.as_str()),
|
|
|
|
|
game::Piece::Queen => gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get(tweak.display3d.models.scenes.queen.as_str()),
|
|
|
|
|
}
|
|
|
|
|
.expect("Game board model")
|
|
|
|
|
.clone();
|
|
|
|
|
@ -344,15 +368,20 @@ fn set_board_model(
|
|
|
|
|
>,
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
boards.iter_mut().for_each(|mut handle| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
*handle = gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get("Gameboard")
|
|
|
|
|
.get(tweak.display3d.models.scenes.board.as_str())
|
|
|
|
|
.expect("Game board model")
|
|
|
|
|
.clone();
|
|
|
|
|
});
|
|
|
|
|
// TODO: Get rid of this -- upstream asset has merged tiles back into gameboard scene
|
|
|
|
|
tiles.iter_mut().for_each(|mut handle| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
*handle = gltf
|
|
|
|
|
@ -459,7 +488,11 @@ fn set_piece_texture(
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
mut models: Query<(&Name, &mut Handle<StandardMaterial>)>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
events.iter().for_each(|(entity, piece, side)| {
|
|
|
|
|
debug!("Checking piece texture for {:?}", entity);
|
|
|
|
|
if let Some(gltf) = gltfs.get(&assets_map.models) {
|
|
|
|
|
@ -470,84 +503,84 @@ fn set_piece_texture(
|
|
|
|
|
(Piece::Queen, Side::A, "Queen.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Queen")
|
|
|
|
|
.get(tweak.display3d.models.materials.queen_red.as_str())
|
|
|
|
|
.expect("Load Red Queen texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Queen, Side::A, "Queen.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Dots")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_red.as_str())
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Queen, Side::B, "Queen.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("QueenBlue")
|
|
|
|
|
.get(tweak.display3d.models.materials.queen_blue.as_str())
|
|
|
|
|
.expect("Load Blue Queen texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Queen, Side::B, "Queen.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_blue.as_str())
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Drone, Side::A, "Drone.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Drone")
|
|
|
|
|
.get(tweak.display3d.models.materials.drone_red.as_str())
|
|
|
|
|
.expect("Load Red Drone texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Drone, Side::A, "Drone.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Dots")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_red.as_str())
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Drone, Side::B, "Drone.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("DroneBlue")
|
|
|
|
|
.get(tweak.display3d.models.materials.drone_blue.as_str())
|
|
|
|
|
.expect("Load Blue Drone texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Drone, Side::B, "Drone.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_blue.as_str())
|
|
|
|
|
.expect("Load Blue Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Pawn, Side::A, "Pawn.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Pawn")
|
|
|
|
|
.get(tweak.display3d.models.materials.pawn_red.as_str())
|
|
|
|
|
.expect("Load Red Pawn texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Pawn, Side::A, "Pawn.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("Dots")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_red.as_str())
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Pawn, Side::B, "Pawn.0") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("DroneBlue") // TODO: FIX
|
|
|
|
|
.get(tweak.display3d.models.materials.pawn_blue.as_str())
|
|
|
|
|
.expect("Load Blue Pawn texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
(Piece::Pawn, Side::B, "Pawn.1") => {
|
|
|
|
|
*m = gltf
|
|
|
|
|
.named_materials
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
.get(tweak.display3d.models.materials.dots_blue.as_str())
|
|
|
|
|
.expect("Load Blue Dots texture")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
@ -668,10 +701,18 @@ fn set_valid_move_model(
|
|
|
|
|
mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
if let Some(gltf) = gltfs.get(&assets_map.models) {
|
|
|
|
|
events.iter_mut().for_each(|mut handle| {
|
|
|
|
|
*handle = gltf.named_scenes.get("Valid Move Spot").unwrap().clone()
|
|
|
|
|
*handle = gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get(tweak.display3d.models.scenes.valid_move.as_str())
|
|
|
|
|
.unwrap()
|
|
|
|
|
.clone()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -703,14 +744,22 @@ fn pick_up(
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
mut players: Query<&mut AnimationPlayer>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
events.iter_mut().for_each(|(entity, piece)| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
|
if let Ok(mut player) = players.get_mut(child) {
|
|
|
|
|
info!("Picking up {:?} {:?}", entity, piece);
|
|
|
|
|
let animation = gltf.named_animations.get("PiecePickup");
|
|
|
|
|
let idle = gltf.named_animations.get("PieceIdle");
|
|
|
|
|
let animation = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.pick_up.as_str());
|
|
|
|
|
let idle = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.idle.as_str());
|
|
|
|
|
player
|
|
|
|
|
.start_with_transition(
|
|
|
|
|
animation.expect("Pickup Animation").clone(),
|
|
|
|
|
@ -733,14 +782,20 @@ fn put_down(
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
mut players: Query<&mut AnimationPlayer>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
events.iter().for_each(|entity| {
|
|
|
|
|
if let Ok(_piece) = query.get_mut(entity) {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
|
if let Ok(mut player) = players.get_mut(child) {
|
|
|
|
|
info!("Putting down {:?}", entity);
|
|
|
|
|
let animation = gltf.named_animations.get("PiecePutDown");
|
|
|
|
|
let animation = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.put_down.as_str());
|
|
|
|
|
player
|
|
|
|
|
.start_with_transition(
|
|
|
|
|
animation.expect("PutDown Animation").clone(),
|
|
|
|
|
@ -773,12 +828,20 @@ fn switch_sides(
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
state: Res<State<game::TurnState>>,
|
|
|
|
|
tweaks: Res<Assets<Tweakfile>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
|
|
|
|
let tweak = tweaks.get(&handle).expect("Load tweakfile");
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
players.iter_mut().for_each(|mut player| {
|
|
|
|
|
let animation = match state.get() {
|
|
|
|
|
game::TurnState::SideA => gltf.named_animations.get("GameCamSide2>1"),
|
|
|
|
|
game::TurnState::SideB => gltf.named_animations.get("GameCamSide1>2"),
|
|
|
|
|
game::TurnState::SideA => gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.turn_a.as_str()),
|
|
|
|
|
game::TurnState::SideB => gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(tweak.display3d.models.animations.turn_b.as_str()),
|
|
|
|
|
};
|
|
|
|
|
player.start_with_transition(
|
|
|
|
|
animation.expect("Camera Transition Animation").clone(),
|
|
|
|
|
@ -796,6 +859,8 @@ pub(crate) mod tweaks {
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default)]
|
|
|
|
|
pub(crate) struct Display3dTweaks {
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub hdr: bool,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub fog: FogTweaks,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
@ -804,6 +869,8 @@ pub(crate) mod tweaks {
|
|
|
|
|
pub ssao: SsaoTweaks,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub msaa: MsaaTweaks,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub models: ModelTweaks,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default)]
|
|
|
|
|
@ -1002,4 +1069,45 @@ pub(crate) mod tweaks {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default, Clone)]
|
|
|
|
|
pub(crate) struct ModelTweaks {
|
|
|
|
|
pub assets_file: String,
|
|
|
|
|
pub skybox_file: String,
|
|
|
|
|
pub scenes: SceneTweaks,
|
|
|
|
|
pub animations: AnimationTweaks,
|
|
|
|
|
pub materials: MaterialTweaks,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default, Clone)]
|
|
|
|
|
pub(crate) struct SceneTweaks {
|
|
|
|
|
pub queen: String,
|
|
|
|
|
pub drone: String,
|
|
|
|
|
pub pawn: String,
|
|
|
|
|
pub board: String,
|
|
|
|
|
pub valid_move: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default, Clone)]
|
|
|
|
|
pub(crate) struct AnimationTweaks {
|
|
|
|
|
pub intro_a: String,
|
|
|
|
|
pub intro_b: String,
|
|
|
|
|
pub turn_a: String,
|
|
|
|
|
pub turn_b: String,
|
|
|
|
|
pub pick_up: String,
|
|
|
|
|
pub put_down: String,
|
|
|
|
|
pub idle: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Default, Clone)]
|
|
|
|
|
pub(crate) struct MaterialTweaks {
|
|
|
|
|
pub queen_red: String,
|
|
|
|
|
pub queen_blue: String,
|
|
|
|
|
pub drone_red: String,
|
|
|
|
|
pub drone_blue: String,
|
|
|
|
|
pub pawn_red: String,
|
|
|
|
|
pub pawn_blue: String,
|
|
|
|
|
pub dots_red: String,
|
|
|
|
|
pub dots_blue: String,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|