Skip to content

Commit

Permalink
v0.6.0
Browse files Browse the repository at this point in the history
Timeframe for vfx;
text.vfx default timeframe;
Last battle run mode;
Death check after all events only;
Fix pool chaching to always wait for subscription;
Pools disable caching option;
  • Loading branch information
makscee committed Feb 4, 2024
1 parent 7925adb commit 67f2d26
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 47 deletions.
31 changes: 27 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "cargo",
"command": "run",
"problemMatcher": [
"$rustc"
],
"label": "Last",
"args": [
"--features",
"bevy/dynamic_linking",
"--",
"--mode",
"last"
],
"group": {
"kind": "build"
},
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "cargo",
"command": "run",
Expand Down Expand Up @@ -134,6 +155,8 @@
],
"label": "Sync Assets",
"args": [
"--features",
"bevy/dynamic_linking",
"--",
"--mode",
"sync"
Expand All @@ -159,15 +182,15 @@
"group": {
"kind": "build"
},
"command": "spacetime publish aoi_dev -p server"
"command": "spacetime publish aoi_dev2 -p server"
},
{
"label": "STDB: Publish & Clear",
"type": "shell",
"group": {
"kind": "build"
},
"command": "spacetime publish -c aoi_dev -p server"
"command": "spacetime publish -c aoi -p server"
},
{
"label": "STDB: Start",
Expand All @@ -191,15 +214,15 @@
"group": {
"kind": "build"
},
"command": "spacetime sql aoi_dev --interactive"
"command": "spacetime sql aoi_dev2 --interactive"
},
{
"label": "Flamegraph: Run Debug",
"type": "shell",
"group": {
"kind": "build"
},
"command": "sudo cargo flamegraph --dev -- --mode regular"
"command": "sudo cargo flamegraph --dev -- --mode custom"
},
{
"label": "Flamegraph: Run Release",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["server"]

[workspace.package]
version = "0.5.0"
version = "0.6.0"
edition = "2021"

[package]
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/vfx/apply_status.vfx.ron
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
representation: (
material: Curve(
color: State(Color),
curvature: Float(1.6),
curvature: Float(2.0),
thickness: State(Thickness),
aa: Float(0.5),
dilations: [
Expand Down
1 change: 0 additions & 1 deletion assets/ron/vfx/magic_missile.vfx.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(
timeframe: 1.0,
anim: Run(
[
Change(
Expand Down
1 change: 1 addition & 0 deletions assets/ron/vfx/text.vfx.ron
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(
timeframe: 0.1,
anim: Run(
[
Change(
Expand Down
2 changes: 1 addition & 1 deletion server/src/user_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum UserRight {
const SERVER_IDENTITY_HEX: &str =
"41e46206c21c35062daafb836aacbebca4444370e9eef8ec8452003d8d6f0ad1";
pub const LOCAL_IDENTITY_HEX: &str =
"5b32d445d4258388a7f8e337acc0d6f9a56c4799298aa6ee49906876cf98c066";
"a05ddac1b01bfea396399057f347787f0d6ae7ed454ae76a3839ae52453c9832";

#[spacetimedb(reducer)]
fn give_right(ctx: ReducerContext, identity: String) -> Result<(), String> {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum RunMode {
Regular,
Test,
Custom,
Last,
Continue,
Sync,
Editor,
Expand All @@ -33,6 +34,7 @@ fn main() {
let next_state = match args.mode {
RunMode::Regular => GameState::MainMenu,
RunMode::Custom => GameState::CustomBattle,
RunMode::Last => GameState::LastBattle,
RunMode::Editor => GameState::HeroEditor,
RunMode::Continue => GameState::Shop,
RunMode::Test => GameState::TestsLoading,
Expand Down
27 changes: 14 additions & 13 deletions src/plugins/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ impl ActionPlugin {
}
continue;
}
let dead = UnitPlugin::run_death_check(world);
let died = !dead.is_empty();
for unit in dead {
UnitPlugin::turn_into_corpse(unit, world);
}
if died {
GameTimer::get().advance_insert(0.5);
UnitPlugin::fill_slot_gaps(Faction::Left, world);
UnitPlugin::fill_slot_gaps(Faction::Right, world);
UnitPlugin::translate_to_slots(world);
GameTimer::get().insert_to_end();
}
let mut actions_added = false;
while let Some((event, context)) = Self::pop_event(world) {
if event.process(context, world) {
Expand All @@ -74,7 +62,20 @@ impl ActionPlugin {
}
}
if processed {
GameTimer::get().advance_insert(0.3);
let dead = UnitPlugin::run_death_check(world);
let died = !dead.is_empty();
for unit in dead {
UnitPlugin::turn_into_corpse(unit, world);
}
if died {
GameTimer::get().advance_insert(0.5);
UnitPlugin::fill_slot_gaps(Faction::Left, world);
UnitPlugin::fill_slot_gaps(Faction::Right, world);
UnitPlugin::translate_to_slots(world);
GameTimer::get().insert_to_end();
} else {
GameTimer::get().advance_insert(0.3);
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/plugins/custom_battle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ pub struct CustomBattlePlugin;

impl Plugin for CustomBattlePlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::CustomBattle), Self::on_enter);
app.add_systems(OnEnter(GameState::LastBattle), Self::on_enter_last)
.add_systems(OnEnter(GameState::CustomBattle), Self::on_enter);
}
}

impl CustomBattlePlugin {
fn on_enter(world: &mut World) {
Pools::get_mut(world).only_local_cache = true;
Self::load_teams(world);
GameState::change(GameState::Battle, world);
}
fn on_enter_last(world: &mut World) {
Pools::get_mut(world).only_local_cache = true;
Self::load_teams_last(world);
GameState::change(GameState::Battle, world);
}

fn load_teams(world: &mut World) {
let cb = Options::get_custom_battle(world).clone();
BattlePlugin::load_teams(cb.left, cb.right, None, world);
}
fn load_teams_last(world: &mut World) {
let (left, right) = PersistentData::load(world).last_battle;
BattlePlugin::load_teams(left, right, None, world);
}
}

#[derive(Deserialize, TypeUuid, TypePath, Debug, Clone)]
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl LoginPlugin {
Status::Committed => {
let user = User::find(|u| u.identities.contains(identity)).unwrap();
Self::save_current_user(user.name, user.id, identity.clone());
OperationsPlugin::add(PoolsPlugin::cache_server_pools);
}
Status::Failed(e) => {
AlertPlugin::add_error(
Expand Down Expand Up @@ -277,7 +276,10 @@ fn subscribe_to_tables(user_id: u64) {
&format!("select * from ArenaRun where user_id = {user_id}"),
"select * from ArenaPool",
]) {
Ok(_) => debug!("Subscribe successful"),
Ok(_) => {
debug!("Subscribe successful");
once_on_subscription_applied(|| OperationsPlugin::add(PoolsPlugin::cache_server_pools));
}
Err(e) => error!("Subscription error: {e}"),
}
}
6 changes: 5 additions & 1 deletion src/plugins/shop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl ShopPlugin {
} else {
default()
};
PersistentData::load(world)
.set_last_battle(left.clone(), right.clone())
.save(world)
.unwrap();
BattlePlugin::load_teams(left, right, Some(run.id), world);
}

Expand Down Expand Up @@ -220,7 +224,7 @@ impl ShopPlugin {
);
});
Area::new("battle button")
.anchor(Align2::RIGHT_CENTER, [-40.0, 0.0])
.anchor(Align2::RIGHT_CENTER, [-40.0, -50.0])
.show(ctx, |ui| {
if ui.button("START BATTLE").clicked() {
Self::go_to_battle(world);
Expand Down
35 changes: 15 additions & 20 deletions src/resourses/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ impl Effect {
.with_context(|| format!("Ability not found {ability}"))?
.effect
.clone();
let color = Pools::get_ability_house(ability, world)
.with_context(|| format!("Failed to find house for ability {ability}"))?
.color
.clone()
.into();
Pools::get_vfx("text", world)
.clone()
.set_var(
VarName::Position,
VarState::get(context.owner(), world).get_value_last(VarName::Position)?,
)
.set_var(VarName::Text, VarValue::String(format!("Use {ability}")))
.set_var(VarName::Color, VarValue::Color(color))
.unpack(world)?;
{
let context = context
.clone()
Expand All @@ -116,29 +130,10 @@ impl Effect {
.get_var(VarName::Level, world)
.unwrap_or(VarValue::Int(1)),
)
.set_var(VarName::Color, VarValue::Color(color))
.take();
ActionPlugin::action_push_front(effect, context, world);
}
Pools::get_vfx("text", world)
.clone()
.set_var(
VarName::Position,
VarState::get(context.owner(), world).get_value_last(VarName::Position)?,
)
.set_var(VarName::Text, VarValue::String(format!("Use {ability}")))
.set_var(
VarName::Color,
VarValue::Color(
Pools::get_ability_house(ability, world)
.with_context(|| {
format!("Failed to find house for ability {ability}")
})?
.color
.clone()
.into(),
),
)
.unpack(world)?;
}
Effect::AddStatus(status) => {
let charges = context
Expand Down
3 changes: 2 additions & 1 deletion src/resourses/game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum GameState {
BattleTest,
Restart,
CustomBattle,
LastBattle,
Battle,
Shop,
HeroEditor,
Expand All @@ -28,7 +29,7 @@ impl GameState {
pub fn exit(&self, world: &mut World) {
match self {
GameState::MainMenu | GameState::Login => world.send_event(AppExit),
GameState::CustomBattle | GameState::Battle => {
GameState::CustomBattle | GameState::LastBattle | GameState::Battle => {
GameTimer::get().skip_to_end();
}
GameState::Shop | GameState::HeroEditor | GameState::HeroGallery => {
Expand Down
6 changes: 5 additions & 1 deletion src/resourses/persistent_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::*;
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
pub struct PersistentData {
pub hero_editor_data: HeroEditorData,
pub last_battle: (PackedTeam, PackedTeam),
}

const PERSISTENT_DATA_KEY: &str = "persistent_data";
Expand All @@ -13,7 +14,6 @@ impl PersistentData {
.get(PERSISTENT_DATA_KEY)
.unwrap_or_default()
}

pub fn save(&self, world: &mut World) -> Result<()> {
world
.resource_mut::<PkvStore>()
Expand All @@ -25,4 +25,8 @@ impl PersistentData {
self.hero_editor_data = data;
self
}
pub fn set_last_battle(mut self, left: PackedTeam, right: PackedTeam) -> Self {
self.last_battle = (left, right);
self
}
}
5 changes: 5 additions & 0 deletions src/resourses/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Pools {
#[asset(key = "pool.vfx", collection(typed, mapped))]
vfx_handles: HashMap<String, Handle<Vfx>>,
pub vfx: HashMap<String, Vfx>,
pub only_local_cache: bool,
}

impl Pools {
Expand Down Expand Up @@ -182,6 +183,10 @@ impl PoolsPlugin {
return;
}
let mut pools = Pools::get_mut(world);
if pools.only_local_cache {
debug!("Server cache disabled");
return;
}
debug!("Cache server pools start");
pools.heroes.clear();
pools.houses.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/resourses/vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct Vfx {
pub representation: Representation,
#[serde(default)]
pub state: VarState,
#[serde(default)]
pub timeframe: f32,
pub parent: Option<Entity>,
}

Expand All @@ -26,6 +28,9 @@ impl Vfx {
.take(),
world,
);
if self.timeframe > 0.0 {
GameTimer::get().advance_insert(self.timeframe);
}
result
}

Expand Down

0 comments on commit 67f2d26

Please sign in to comment.