feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
//! Authoritative game simulation.
|
|
|
|
|
//!
|
|
|
|
|
//! Used by the dedicated server binary and embedded in the client for
|
|
|
|
|
//! singleplayer and hosting. Clients only send intents (see
|
|
|
|
|
//! [`game_core::protocol`]); all game rules run here.
|
|
|
|
|
|
|
|
|
|
pub mod actions;
|
2026-10-18 19:41:58 +00:00
|
|
|
pub mod commands;
|
|
|
|
|
pub mod config;
|
|
|
|
|
pub mod console;
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
pub mod crafting;
|
2026-10-18 18:28:16 +00:00
|
|
|
pub mod machines;
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
pub mod movement;
|
|
|
|
|
pub mod network;
|
|
|
|
|
pub mod persistence;
|
|
|
|
|
pub mod players;
|
|
|
|
|
pub mod scripting;
|
|
|
|
|
pub mod survival;
|
|
|
|
|
pub mod world;
|
|
|
|
|
|
2026-10-18 18:47:43 +00:00
|
|
|
use std::{sync::Arc, time::Duration};
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use game_core::GameData;
|
|
|
|
|
|
|
|
|
|
pub use network::NetworkServerPlugin;
|
|
|
|
|
|
|
|
|
|
/// Configuration of the simulation.
|
|
|
|
|
#[derive(Resource, Clone, Debug)]
|
|
|
|
|
pub struct ServerSettings {
|
|
|
|
|
/// Tiled map, relative to the assets directory.
|
|
|
|
|
pub map: String,
|
2026-10-18 18:47:43 +00:00
|
|
|
/// Database and world to persist to. `None` disables saving.
|
|
|
|
|
pub storage: Option<persistence::StorageSettings>,
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
pub autosave_interval: Duration,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for ServerSettings {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
map: game_core::DEFAULT_MAP.to_owned(),
|
2026-10-18 18:47:43 +00:00
|
|
|
storage: None,
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
autosave_interval: Duration::from_secs(60),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Runs the game world. Requires [`game_core::CorePlugin`] and the replicon plugins.
|
|
|
|
|
pub struct GameServerPlugin {
|
|
|
|
|
pub settings: ServerSettings,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Plugin for GameServerPlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.insert_resource(self.settings.clone())
|
|
|
|
|
.insert_resource(persistence::AutosaveTimer(Timer::new(
|
|
|
|
|
self.settings.autosave_interval,
|
|
|
|
|
TimerMode::Repeating,
|
|
|
|
|
)))
|
2026-10-18 19:41:58 +00:00
|
|
|
.init_resource::<config::ServerConfig>()
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
.init_resource::<players::Players>()
|
|
|
|
|
.init_resource::<players::CharacterStore>()
|
|
|
|
|
.init_resource::<survival::SurvivalTimer>()
|
|
|
|
|
.add_systems(Startup, (load_scripts, world::setup_world).chain())
|
|
|
|
|
.add_systems(
|
|
|
|
|
FixedUpdate,
|
2026-10-18 18:28:16 +00:00
|
|
|
(
|
|
|
|
|
movement::move_characters,
|
|
|
|
|
survival::tick_survival,
|
|
|
|
|
machines::tick_machines,
|
|
|
|
|
),
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
)
|
|
|
|
|
.add_systems(Update, persistence::autosave)
|
|
|
|
|
.add_systems(Last, persistence::save_on_exit)
|
|
|
|
|
.add_observer(players::on_login)
|
|
|
|
|
.add_observer(players::on_disconnect)
|
|
|
|
|
.add_observer(movement::on_set_move_dir)
|
|
|
|
|
.add_observer(actions::on_pick_up)
|
|
|
|
|
.add_observer(actions::on_drop_item)
|
|
|
|
|
.add_observer(actions::on_use_item)
|
|
|
|
|
.add_observer(actions::on_interact)
|
|
|
|
|
.add_observer(actions::on_craft)
|
|
|
|
|
.add_observer(actions::on_construct)
|
2026-10-18 18:28:16 +00:00
|
|
|
.add_observer(actions::on_deconstruct)
|
|
|
|
|
.add_observer(machines::on_machine_insert)
|
|
|
|
|
.add_observer(machines::on_machine_take);
|
feat: add persistent-world station game
Bevy ECS workspace with three crates:
- game_core: rsn data definitions, components, Tiled map loader, protocol
- game_server: authoritative simulation, Rune scripting, persistence,
dedicated server binary
- game_client: rendering, UI and input; embeds the server for
singleplayer and hosting
Items, recipes, buildings and skills are defined in assets/data, behavior
in Rune scripts under assets/scripts, and maps are made in Tiled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-18 17:44:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_scripts(mut commands: Commands, data: Res<GameData>) {
|
|
|
|
|
let dir = game_core::asset_path("scripts");
|
|
|
|
|
let engine = scripting::ScriptEngine::load(&dir, &data).unwrap_or_else(|e| panic!("{e}"));
|
|
|
|
|
info!("compiled scripts from `{}`", dir.display());
|
|
|
|
|
commands.insert_resource(engine);
|
|
|
|
|
commands.insert_resource(actions::SharedData(Arc::new(data.clone())));
|
|
|
|
|
}
|