Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53727a216c | ||
|
|
769d82573a |
+5
-7
@@ -32,13 +32,9 @@ use clap::Parser;
|
|||||||
use ron_asset_manager::RonAssetPlugin;
|
use ron_asset_manager::RonAssetPlugin;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
camera::MatchCameraPlugin,
|
camera::MatchCameraPlugin, fighter::manifest::FighterManifest, game_settings::GameSettings,
|
||||||
fighter::manifest::FighterManifest,
|
match_runtime::MatchRuntimePlugin, menus::style::FGUiStyle, schedule::GameplaySchedulePlugin,
|
||||||
game_settings::GameSettings,
|
stage::manifest::StageManifest, ui::InGameUIPlugin,
|
||||||
menus::style::FGUiStyle,
|
|
||||||
schedule::GameplaySchedulePlugin,
|
|
||||||
stage::manifest::StageManifest,
|
|
||||||
ui::InGameUIPlugin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
@@ -48,6 +44,7 @@ pub mod fighter;
|
|||||||
pub mod game_settings;
|
pub mod game_settings;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod match_loading;
|
pub mod match_loading;
|
||||||
|
pub mod match_runtime;
|
||||||
mod math;
|
mod math;
|
||||||
pub mod menus;
|
pub mod menus;
|
||||||
pub mod netcode;
|
pub mod netcode;
|
||||||
@@ -111,6 +108,7 @@ impl Plugin for GamePlugin {
|
|||||||
// Brings up GGRS (and with it `GgrsSchedule`), so it goes first.
|
// Brings up GGRS (and with it `GgrsSchedule`), so it goes first.
|
||||||
netcode::FighterNetcodePlugin::default(),
|
netcode::FighterNetcodePlugin::default(),
|
||||||
GameplaySchedulePlugin,
|
GameplaySchedulePlugin,
|
||||||
|
MatchRuntimePlugin,
|
||||||
input::FighterInputPlugin,
|
input::FighterInputPlugin,
|
||||||
replay::ReplayPlugin,
|
replay::ReplayPlugin,
|
||||||
debug_tools::DebugToolsPlugin,
|
debug_tools::DebugToolsPlugin,
|
||||||
|
|||||||
+126
-33
@@ -8,28 +8,29 @@ use bevy_ggrs::prelude::Session;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
AppState,
|
||||||
args::Args,
|
args::Args,
|
||||||
fighter::{
|
fighter::{
|
||||||
|
FighterId, FighterRoster,
|
||||||
animation::AnimKind,
|
animation::AnimKind,
|
||||||
attack::{AttackKind, FighterAttackScriptAssets},
|
attack::{AttackKind, FighterAttackScriptAssets},
|
||||||
baked_animation::{BakedFighterAnimations, BAKED_ANIMATION_FPS},
|
baked_animation::{BAKED_ANIMATION_FPS, BakedFighterAnimations},
|
||||||
manifest::{FighterManifest, FighterManifestRegistry},
|
manifest::{FighterManifest, FighterManifestRegistry},
|
||||||
spawn_fighter,
|
spawn_fighter,
|
||||||
visual::FighterAnimations,
|
visual::FighterAnimations,
|
||||||
FighterId, FighterRoster,
|
|
||||||
},
|
},
|
||||||
input::{LocalInputAssignments, LocalInputSource},
|
input::{LocalInputAssignments, LocalInputSource},
|
||||||
|
match_runtime::MatchState,
|
||||||
math::{int::FGi32, vec::FGVec2},
|
math::{int::FGi32, vec::FGVec2},
|
||||||
netcode::{
|
netcode::{
|
||||||
session::{create_session, ConnectionStatus, SessionConfig},
|
|
||||||
GGRSCfg,
|
GGRSCfg,
|
||||||
|
session::{ConnectionStatus, SessionConfig, create_session},
|
||||||
},
|
},
|
||||||
scripting::FighterAttackScript,
|
scripting::FighterAttackScript,
|
||||||
stage::{
|
stage::{
|
||||||
self,
|
self,
|
||||||
manifest::{StageId, StageManifest, StageManifestRegistry},
|
manifest::{StageId, StageManifest, StageManifestRegistry},
|
||||||
},
|
},
|
||||||
AppState,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@@ -38,10 +39,49 @@ pub struct MatchPlayer {
|
|||||||
pub fighter: FighterId,
|
pub fighter: FighterId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Debug, Clone, PartialEq, Eq)]
|
#[derive(Resource, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct PendingMatch {
|
pub struct MatchConfig {
|
||||||
pub stage: StageId,
|
pub stage: StageId,
|
||||||
pub players: Vec<MatchPlayer>,
|
pub players: Vec<MatchPlayer>,
|
||||||
|
pub rules: MatchRules,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum MatchRules {
|
||||||
|
Stock {
|
||||||
|
starting_stocks: u8,
|
||||||
|
time_limit_frames: Option<u32>,
|
||||||
|
},
|
||||||
|
Timed {
|
||||||
|
time_limit_frames: u32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for MatchRules {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Stock {
|
||||||
|
starting_stocks: 3,
|
||||||
|
time_limit_frames: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MatchRules {
|
||||||
|
fn validate(&self) -> Result<(), &'static str> {
|
||||||
|
match self {
|
||||||
|
Self::Stock {
|
||||||
|
starting_stocks: 0, ..
|
||||||
|
} => Err("stock matches must start with at least one stock"),
|
||||||
|
Self::Stock {
|
||||||
|
time_limit_frames: Some(0),
|
||||||
|
..
|
||||||
|
} => Err("stock match time limits must be greater than zero frames"),
|
||||||
|
Self::Timed {
|
||||||
|
time_limit_frames: 0,
|
||||||
|
} => Err("timed match limits must be greater than zero frames"),
|
||||||
|
_ => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SelectedFighterAssets {
|
pub struct SelectedFighterAssets {
|
||||||
@@ -59,7 +99,7 @@ pub struct MatchAssets {
|
|||||||
|
|
||||||
impl MatchAssets {
|
impl MatchAssets {
|
||||||
fn requested(world: &World) -> Self {
|
fn requested(world: &World) -> Self {
|
||||||
let request = world.resource::<PendingMatch>();
|
let config = world.resource::<MatchConfig>();
|
||||||
let asset_server = world.resource::<AssetServer>();
|
let asset_server = world.resource::<AssetServer>();
|
||||||
let registry = world.resource::<FighterManifestRegistry>();
|
let registry = world.resource::<FighterManifestRegistry>();
|
||||||
let stage_registry = world.resource::<StageManifestRegistry>();
|
let stage_registry = world.resource::<StageManifestRegistry>();
|
||||||
@@ -67,7 +107,7 @@ impl MatchAssets {
|
|||||||
let stage_manifests = world.resource::<Assets<StageManifest>>();
|
let stage_manifests = world.resource::<Assets<StageManifest>>();
|
||||||
|
|
||||||
let stage_handle = stage_registry
|
let stage_handle = stage_registry
|
||||||
.get(request.stage)
|
.get(config.stage)
|
||||||
.expect("Startup validation guarantees every stage has a manifest");
|
.expect("Startup validation guarantees every stage has a manifest");
|
||||||
let stage_manifest = stage_manifests
|
let stage_manifest = stage_manifests
|
||||||
.get(&stage_handle)
|
.get(&stage_handle)
|
||||||
@@ -75,7 +115,7 @@ impl MatchAssets {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
stage: asset_server.load(stage_manifest.model_path.clone()),
|
stage: asset_server.load(stage_manifest.model_path.clone()),
|
||||||
fighters: request
|
fighters: config
|
||||||
.players
|
.players
|
||||||
.iter()
|
.iter()
|
||||||
.map(|player| {
|
.map(|player| {
|
||||||
@@ -141,10 +181,10 @@ pub struct MatchRoot;
|
|||||||
pub fn initiate_match(
|
pub fn initiate_match(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
next_state: &mut NextState<AppState>,
|
next_state: &mut NextState<AppState>,
|
||||||
request: PendingMatch,
|
config: MatchConfig,
|
||||||
) {
|
) {
|
||||||
commands.remove_resource::<crate::netcode::session::MatchDisconnected>();
|
commands.remove_resource::<crate::netcode::session::MatchDisconnected>();
|
||||||
commands.insert_resource(request);
|
commands.insert_resource(config);
|
||||||
next_state.set(AppState::LoadingMatch);
|
next_state.set(AppState::LoadingMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,12 +206,9 @@ pub fn initiate_default_match(
|
|||||||
if let Some(path) = &args.play_replay {
|
if let Some(path) = &args.play_replay {
|
||||||
match crate::replay::load(path) {
|
match crate::replay::load(path) {
|
||||||
Ok(replay) => {
|
Ok(replay) => {
|
||||||
let request = PendingMatch {
|
let config = replay.match_config.clone();
|
||||||
stage: replay.match_config.stage,
|
|
||||||
players: replay.match_config.players.clone(),
|
|
||||||
};
|
|
||||||
commands.insert_resource(crate::replay::LoadedReplay(replay));
|
commands.insert_resource(crate::replay::LoadedReplay(replay));
|
||||||
initiate_match(&mut commands, &mut next_state, request);
|
initiate_match(&mut commands, &mut next_state, config);
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
error!("Replay load failed: {error}");
|
error!("Replay load failed: {error}");
|
||||||
@@ -215,16 +252,17 @@ pub fn initiate_default_match(
|
|||||||
initiate_match(
|
initiate_match(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_state,
|
&mut next_state,
|
||||||
PendingMatch {
|
MatchConfig {
|
||||||
stage: StageId::TestStage,
|
stage: StageId::TestStage,
|
||||||
players,
|
players,
|
||||||
|
rules: MatchRules::default(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare_match(
|
pub fn prepare_match(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
request: Res<PendingMatch>,
|
config: Res<MatchConfig>,
|
||||||
assets: Res<MatchAssets>,
|
assets: Res<MatchAssets>,
|
||||||
gltfs: Res<Assets<Gltf>>,
|
gltfs: Res<Assets<Gltf>>,
|
||||||
baked_animations: Res<Assets<BakedFighterAnimations>>,
|
baked_animations: Res<Assets<BakedFighterAnimations>>,
|
||||||
@@ -236,7 +274,7 @@ pub fn prepare_match(
|
|||||||
args: Res<Args>,
|
args: Res<Args>,
|
||||||
mut next_state: ResMut<NextState<AppState>>,
|
mut next_state: ResMut<NextState<AppState>>,
|
||||||
) {
|
) {
|
||||||
if !valid_player_handles(&request.players) {
|
if !valid_player_handles(&config.players) {
|
||||||
fail_match(
|
fail_match(
|
||||||
&mut next_state,
|
&mut next_state,
|
||||||
"player handles must be unique and cover 0..player_count",
|
"player handles must be unique and cover 0..player_count",
|
||||||
@@ -244,7 +282,12 @@ pub fn prepare_match(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if assets.fighters.len() != request.players.len() {
|
if let Err(error) = config.rules.validate() {
|
||||||
|
fail_match(&mut next_state, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if assets.fighters.len() != config.players.len() {
|
||||||
fail_match(
|
fail_match(
|
||||||
&mut next_state,
|
&mut next_state,
|
||||||
"loaded character assets do not match the requested player slots",
|
"loaded character assets do not match the requested player slots",
|
||||||
@@ -396,7 +439,7 @@ pub fn prepare_match(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let session_config = match SessionConfig::from_args(&args, request.players.len()) {
|
let session_config = match SessionConfig::from_args(&args, config.players.len()) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
fail_match(
|
fail_match(
|
||||||
@@ -406,7 +449,7 @@ pub fn prepare_match(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let session = match create_session(&args, request.players.len()) {
|
let session = match create_session(&args, config.players.len()) {
|
||||||
Ok(session) => session,
|
Ok(session) => session,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
fail_match(
|
fail_match(
|
||||||
@@ -420,7 +463,7 @@ pub fn prepare_match(
|
|||||||
let root = commands.spawn((Name::new("Match"), MatchRoot)).id();
|
let root = commands.spawn((Name::new("Match"), MatchRoot)).id();
|
||||||
|
|
||||||
let stage_handle = stage_registry
|
let stage_handle = stage_registry
|
||||||
.get(request.stage)
|
.get(config.stage)
|
||||||
.expect("Initialization check should ensure all stages exist");
|
.expect("Initialization check should ensure all stages exist");
|
||||||
let stage_manifest = stage_manifests
|
let stage_manifest = stage_manifests
|
||||||
.get(&stage_handle)
|
.get(&stage_handle)
|
||||||
@@ -433,11 +476,11 @@ pub fn prepare_match(
|
|||||||
stage_manifest.camera.clone(),
|
stage_manifest.camera.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut fighter_roster = Vec::with_capacity(request.players.len());
|
let mut fighter_roster = Vec::with_capacity(config.players.len());
|
||||||
for (index, (player, (scene, animations, attack_scripts, manifest_handle, model_scale))) in
|
for (index, (player, (scene, animations, attack_scripts, manifest_handle, model_scale))) in
|
||||||
request.players.iter().zip(prepared).enumerate()
|
config.players.iter().zip(prepared).enumerate()
|
||||||
{
|
{
|
||||||
let spawn_x = (index as i32 * 2 + 1 - request.players.len() as i32) * 5;
|
let spawn_x = (index as i32 * 2 + 1 - config.players.len() as i32) * 5;
|
||||||
fighter_roster.push(spawn_fighter(
|
fighter_roster.push(spawn_fighter(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
player.handle,
|
player.handle,
|
||||||
@@ -451,6 +494,7 @@ pub fn prepare_match(
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands.insert_resource(FighterRoster(fighter_roster));
|
commands.insert_resource(FighterRoster(fighter_roster));
|
||||||
|
commands.insert_resource(MatchState::from_config(&config));
|
||||||
commands.insert_resource(session_config);
|
commands.insert_resource(session_config);
|
||||||
commands.insert_resource(ConnectionStatus::default());
|
commands.insert_resource(ConnectionStatus::default());
|
||||||
commands.insert_resource::<Session<GGRSCfg>>(session);
|
commands.insert_resource::<Session<GGRSCfg>>(session);
|
||||||
@@ -487,7 +531,8 @@ pub fn cleanup_match(
|
|||||||
commands.remove_resource::<ConnectionStatus>();
|
commands.remove_resource::<ConnectionStatus>();
|
||||||
commands.remove_resource::<stage::line::StageCollision>();
|
commands.remove_resource::<stage::line::StageCollision>();
|
||||||
commands.remove_resource::<MatchAssets>();
|
commands.remove_resource::<MatchAssets>();
|
||||||
commands.remove_resource::<PendingMatch>();
|
commands.remove_resource::<MatchConfig>();
|
||||||
|
commands.remove_resource::<MatchState>();
|
||||||
commands.remove_resource::<FighterRoster>();
|
commands.remove_resource::<FighterRoster>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,8 +541,8 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_request_keeps_duplicate_fighter_slots() {
|
fn match_config_keeps_duplicate_fighter_slots() {
|
||||||
let request = PendingMatch {
|
let config = MatchConfig {
|
||||||
stage: StageId::TestStage,
|
stage: StageId::TestStage,
|
||||||
players: vec![
|
players: vec![
|
||||||
MatchPlayer {
|
MatchPlayer {
|
||||||
@@ -509,12 +554,13 @@ mod tests {
|
|||||||
fighter: FighterId::TestFighter,
|
fighter: FighterId::TestFighter,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
rules: MatchRules::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(request.players.len(), 2);
|
assert_eq!(config.players.len(), 2);
|
||||||
assert_eq!(request.players[0].handle, 0);
|
assert_eq!(config.players[0].handle, 0);
|
||||||
assert_eq!(request.players[1].handle, 1);
|
assert_eq!(config.players[1].handle, 1);
|
||||||
assert!(valid_player_handles(&request.players));
|
assert!(valid_player_handles(&config.players));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -533,6 +579,53 @@ mod tests {
|
|||||||
assert!(!valid_player_handles(&players));
|
assert!(!valid_player_handles(&players));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_rules_reject_zero_limits() {
|
||||||
|
assert!(
|
||||||
|
MatchRules::Stock {
|
||||||
|
starting_stocks: 0,
|
||||||
|
time_limit_frames: None,
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
MatchRules::Stock {
|
||||||
|
starting_stocks: 3,
|
||||||
|
time_limit_frames: Some(0),
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
MatchRules::Timed {
|
||||||
|
time_limit_frames: 0,
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_rules_accept_valid_modes() {
|
||||||
|
assert!(MatchRules::default().validate().is_ok());
|
||||||
|
assert!(
|
||||||
|
MatchRules::Stock {
|
||||||
|
starting_stocks: 3,
|
||||||
|
time_limit_frames: Some(60),
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_ok()
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
MatchRules::Timed {
|
||||||
|
time_limit_frames: 60,
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_ok()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_loading_waits_for_attack_scripts() {
|
fn match_loading_waits_for_attack_scripts() {
|
||||||
let mut attack_scripts = HashMap::new();
|
let mut attack_scripts = HashMap::new();
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
//! Rollback-simulated state for an active match.
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_ggrs::prelude::*;
|
||||||
|
|
||||||
|
use crate::match_loading::{MatchConfig, MatchRules};
|
||||||
|
|
||||||
|
#[derive(Resource, Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
|
pub struct MatchState {
|
||||||
|
pub elapsed_frames: u32,
|
||||||
|
/// Indexed by the player's session handle.
|
||||||
|
pub players: Vec<PlayerMatchState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
|
pub struct PlayerMatchState {
|
||||||
|
pub stocks_remaining: Option<u8>,
|
||||||
|
pub score: i32,
|
||||||
|
pub deaths: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MatchState {
|
||||||
|
pub fn from_config(config: &MatchConfig) -> Self {
|
||||||
|
let stocks_remaining = match &config.rules {
|
||||||
|
MatchRules::Stock {
|
||||||
|
starting_stocks, ..
|
||||||
|
} => Some(*starting_stocks),
|
||||||
|
MatchRules::Timed { .. } => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
elapsed_frames: 0,
|
||||||
|
players: (0..config.players.len())
|
||||||
|
.map(|_| PlayerMatchState {
|
||||||
|
stocks_remaining,
|
||||||
|
score: 0,
|
||||||
|
deaths: 0,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MatchRuntimePlugin;
|
||||||
|
|
||||||
|
impl Plugin for MatchRuntimePlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.rollback_resource_with_clone::<MatchState>()
|
||||||
|
.checksum_resource_with_hash::<MatchState>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::{fighter::FighterId, match_loading::MatchPlayer, stage::manifest::StageId};
|
||||||
|
|
||||||
|
fn config(rules: MatchRules) -> MatchConfig {
|
||||||
|
MatchConfig {
|
||||||
|
stage: StageId::TestStage,
|
||||||
|
players: vec![
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 1,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 0,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stock_state_starts_with_configured_stocks() {
|
||||||
|
let state = MatchState::from_config(&config(MatchRules::Stock {
|
||||||
|
starting_stocks: 4,
|
||||||
|
time_limit_frames: Some(60),
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert_eq!(state.elapsed_frames, 0);
|
||||||
|
assert_eq!(state.players.len(), 2);
|
||||||
|
assert!(state.players.iter().all(|player| {
|
||||||
|
player.stocks_remaining == Some(4) && player.score == 0 && player.deaths == 0
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn timed_state_has_no_stock_counter() {
|
||||||
|
let state = MatchState::from_config(&config(MatchRules::Timed {
|
||||||
|
time_limit_frames: 60,
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
state
|
||||||
|
.players
|
||||||
|
.iter()
|
||||||
|
.all(|player| player.stocks_remaining.is_none())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ use thiserror::Error;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::FighterId,
|
fighter::FighterId,
|
||||||
match_loading::{MatchPlayer, PendingMatch},
|
match_loading::{MatchConfig, MatchPlayer, MatchRules},
|
||||||
stage::manifest::StageId,
|
stage::manifest::StageId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ impl MenuMatchConfig {
|
|||||||
!has_unselected_fighter
|
!has_unselected_fighter
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_pending_match(&self) -> Result<PendingMatch, MenuMatchConfigErrors> {
|
pub fn to_match_config(&self) -> Result<MatchConfig, MenuMatchConfigErrors> {
|
||||||
let mut match_players = vec![];
|
let mut match_players = vec![];
|
||||||
|
|
||||||
let stage = self.stage.ok_or(MenuMatchConfigErrors::StageNotSelected)?;
|
let stage = self.stage.ok_or(MenuMatchConfigErrors::StageNotSelected)?;
|
||||||
@@ -78,9 +78,28 @@ impl MenuMatchConfig {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(PendingMatch {
|
Ok(MatchConfig {
|
||||||
players: match_players,
|
players: match_players,
|
||||||
stage,
|
stage,
|
||||||
|
rules: MatchRules::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn menu_config_uses_default_match_rules() {
|
||||||
|
let menu = MenuMatchConfig {
|
||||||
|
stage: Some(StageId::TestStage),
|
||||||
|
players: vec![MenuMatchPlayerSlot {
|
||||||
|
slot: 0,
|
||||||
|
fighter: Some(FighterId::TestFighter),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(menu.to_match_config().unwrap().rules, MatchRules::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ pub fn stage_selected(
|
|||||||
initiate_match(
|
initiate_match(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_state,
|
&mut next_state,
|
||||||
match_config.to_pending_match()?,
|
match_config.to_match_config()?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+26
-25
@@ -12,16 +12,12 @@ use clap::ValueEnum;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AppState,
|
AppState, args::Args, input::FighterInputFrame, match_loading::MatchConfig, netcode::GGRSCfg,
|
||||||
args::Args,
|
|
||||||
input::FighterInputFrame,
|
|
||||||
match_loading::{MatchPlayer, PendingMatch},
|
|
||||||
netcode::GGRSCfg,
|
|
||||||
schedule::GameplaySet,
|
schedule::GameplaySet,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAGIC: &[u8; 8] = b"SPRPLY01";
|
const MAGIC: &[u8; 8] = b"SPRPLY01";
|
||||||
pub const REPLAY_VERSION: u32 = 1;
|
pub const REPLAY_VERSION: u32 = 2;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
|
||||||
pub enum ReplayFormat {
|
pub enum ReplayFormat {
|
||||||
@@ -34,17 +30,11 @@ pub enum ReplayFormat {
|
|||||||
pub struct Replay {
|
pub struct Replay {
|
||||||
pub replay_version: u32,
|
pub replay_version: u32,
|
||||||
pub game_version: String,
|
pub game_version: String,
|
||||||
pub match_config: ReplayMatch,
|
pub match_config: MatchConfig,
|
||||||
pub frames: Vec<ReplayFrame>,
|
pub frames: Vec<ReplayFrame>,
|
||||||
pub checksums: Vec<ReplayChecksum>,
|
pub checksums: Vec<ReplayChecksum>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct ReplayMatch {
|
|
||||||
pub stage: crate::stage::manifest::StageId,
|
|
||||||
pub players: Vec<MatchPlayer>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct ReplayFrame {
|
pub struct ReplayFrame {
|
||||||
pub frame: i32,
|
pub frame: i32,
|
||||||
@@ -267,27 +257,27 @@ fn stop_recording(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
stop_request: Option<Res<StopReplayRecording>>,
|
stop_request: Option<Res<StopReplayRecording>>,
|
||||||
runtime: Option<ResMut<ReplayRuntime>>,
|
runtime: Option<ResMut<ReplayRuntime>>,
|
||||||
request: Option<Res<PendingMatch>>,
|
config: Option<Res<MatchConfig>>,
|
||||||
) {
|
) {
|
||||||
if stop_request.is_none() {
|
if stop_request.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commands.remove_resource::<StopReplayRecording>();
|
commands.remove_resource::<StopReplayRecording>();
|
||||||
finish_recording_inner(&mut commands, runtime, request);
|
finish_recording_inner(&mut commands, runtime, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish_recording(
|
fn finish_recording(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
runtime: Option<ResMut<ReplayRuntime>>,
|
runtime: Option<ResMut<ReplayRuntime>>,
|
||||||
request: Option<Res<PendingMatch>>,
|
config: Option<Res<MatchConfig>>,
|
||||||
) {
|
) {
|
||||||
finish_recording_inner(&mut commands, runtime, request);
|
finish_recording_inner(&mut commands, runtime, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish_recording_inner(
|
fn finish_recording_inner(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
runtime: Option<ResMut<ReplayRuntime>>,
|
runtime: Option<ResMut<ReplayRuntime>>,
|
||||||
request: Option<Res<PendingMatch>>,
|
config: Option<Res<MatchConfig>>,
|
||||||
) {
|
) {
|
||||||
let Some(mut runtime) = runtime else { return };
|
let Some(mut runtime) = runtime else { return };
|
||||||
let ReplayMode::Record { path, format } = &runtime.mode else {
|
let ReplayMode::Record { path, format } = &runtime.mode else {
|
||||||
@@ -296,16 +286,13 @@ fn finish_recording_inner(
|
|||||||
if runtime.finished || runtime.frames.is_empty() {
|
if runtime.finished || runtime.frames.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(request) = request else { return };
|
let Some(config) = config else { return };
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
let format = *format;
|
let format = *format;
|
||||||
let replay = Replay {
|
let replay = Replay {
|
||||||
replay_version: REPLAY_VERSION,
|
replay_version: REPLAY_VERSION,
|
||||||
game_version: env!("CARGO_PKG_VERSION").into(),
|
game_version: env!("CARGO_PKG_VERSION").into(),
|
||||||
match_config: ReplayMatch {
|
match_config: config.as_ref().clone(),
|
||||||
stage: request.stage,
|
|
||||||
players: request.players.clone(),
|
|
||||||
},
|
|
||||||
frames: runtime
|
frames: runtime
|
||||||
.frames
|
.frames
|
||||||
.iter()
|
.iter()
|
||||||
@@ -355,7 +342,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::FighterId,
|
fighter::FighterId,
|
||||||
match_loading::MatchPlayer,
|
match_loading::{MatchPlayer, MatchRules},
|
||||||
math::{int::FGi32, vec::FGVec2},
|
math::{int::FGi32, vec::FGVec2},
|
||||||
stage::manifest::StageId,
|
stage::manifest::StageId,
|
||||||
};
|
};
|
||||||
@@ -364,12 +351,15 @@ mod tests {
|
|||||||
Replay {
|
Replay {
|
||||||
replay_version: REPLAY_VERSION,
|
replay_version: REPLAY_VERSION,
|
||||||
game_version: "test".into(),
|
game_version: "test".into(),
|
||||||
match_config: ReplayMatch {
|
match_config: MatchConfig {
|
||||||
stage: StageId::TestStage,
|
stage: StageId::TestStage,
|
||||||
players: vec![MatchPlayer {
|
players: vec![MatchPlayer {
|
||||||
handle: 0,
|
handle: 0,
|
||||||
fighter: FighterId::TestFighter,
|
fighter: FighterId::TestFighter,
|
||||||
}],
|
}],
|
||||||
|
rules: MatchRules::Timed {
|
||||||
|
time_limit_frames: 21_600,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
frames: vec![ReplayFrame {
|
frames: vec![ReplayFrame {
|
||||||
frame: 1,
|
frame: 1,
|
||||||
@@ -406,4 +396,15 @@ mod tests {
|
|||||||
replay.frames[0].inputs.clear();
|
replay.frames[0].inputs.clear();
|
||||||
assert!(validate(&replay).is_err());
|
assert!(validate(&replay).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupported_replay_version_is_rejected() {
|
||||||
|
let mut replay = sample();
|
||||||
|
replay.replay_version = 1;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
validate(&replay).unwrap_err(),
|
||||||
|
"unsupported replay version 1"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-9
@@ -1,20 +1,29 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::manifest::{FighterManifest, FighterManifestRegistry}, match_loading::{PendingMatch}, ui::{errors::UIErrors, fighter_info::FighterInfoUI},
|
fighter::manifest::{FighterManifest, FighterManifestRegistry},
|
||||||
|
match_loading::MatchConfig,
|
||||||
|
ui::{errors::UIErrors, fighter_info::FighterInfoUI},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component, FromTemplate)]
|
#[derive(Component, FromTemplate)]
|
||||||
pub struct BattleUI {
|
pub struct BattleUI {}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn spawn_battle_ui(mut commands: Commands, request: Res<PendingMatch>, fighter_registry: Res<FighterManifestRegistry>, manifests: Res<Assets<FighterManifest>>) -> Result {
|
|
||||||
|
|
||||||
|
pub fn spawn_battle_ui(
|
||||||
|
mut commands: Commands,
|
||||||
|
config: Res<MatchConfig>,
|
||||||
|
fighter_registry: Res<FighterManifestRegistry>,
|
||||||
|
manifests: Res<Assets<FighterManifest>>,
|
||||||
|
) -> Result {
|
||||||
let mut fighter_uis = vec![];
|
let mut fighter_uis = vec![];
|
||||||
|
|
||||||
for player in &request.players {
|
for player in &config.players {
|
||||||
let manifest = fighter_registry.get(player.fighter).ok_or_else(|| UIErrors::FighterManifestHandleNotFound(player.fighter))?;
|
let manifest = fighter_registry
|
||||||
let manifest = manifests.get(manifest).ok_or_else(|| UIErrors::FighterManifestNotFound(player.fighter))?;
|
.get(player.fighter)
|
||||||
|
.ok_or_else(|| UIErrors::FighterManifestHandleNotFound(player.fighter))?;
|
||||||
|
let manifest = manifests
|
||||||
|
.get(manifest)
|
||||||
|
.ok_or_else(|| UIErrors::FighterManifestNotFound(player.fighter))?;
|
||||||
|
|
||||||
fighter_uis.push(FighterInfoUI::build(manifest, player));
|
fighter_uis.push(FighterInfoUI::build(manifest, player));
|
||||||
}
|
}
|
||||||
@@ -54,4 +63,4 @@ pub fn cleanup_battle_ui(mut commands: Commands, battle_ui: Query<Entity, With<B
|
|||||||
for entity in battle_ui {
|
for entity in battle_ui {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user