diff options
-rw-r--r-- | server/src/data.rs | 11 | ||||
-rw-r--r-- | server/src/game.rs | 3 | ||||
-rw-r--r-- | server/src/interaction.rs | 15 | ||||
-rw-r--r-- | server/src/protocol.rs | 1 | ||||
-rw-r--r-- | test-client/main.ts | 5 | ||||
-rw-r--r-- | test-client/protocol.ts | 2 | ||||
-rw-r--r-- | test-client/visual.ts | 2 |
7 files changed, 27 insertions, 12 deletions
diff --git a/server/src/data.rs b/server/src/data.rs index fd6f266d..17b508ec 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -19,13 +19,15 @@ pub enum Action { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct RecipeDecl { #[serde(default)] - pub tile: Option<String>, + tile: Option<String>, #[serde(default)] - pub inputs: Vec<String>, + inputs: Vec<String>, #[serde(default)] - pub outputs: Vec<String>, + outputs: Vec<String>, #[serde(default)] - pub action: Action, + action: Action, + #[serde(default)] + warn: bool, } #[derive(Debug, Clone, Deserialize)] @@ -92,6 +94,7 @@ pub fn build_gamedata( Action::Never => {} Action::Passive(duration) => recipes.push(Recipe::Passive { duration, + warn: r.warn, tile, input: inputs.next().expect("passive recipe without input"), output: outputs.next(), diff --git a/server/src/game.rs b/server/src/game.rs index b478c037..a8ea9991 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -282,7 +282,8 @@ impl Game { for (&pos, tile) in &mut self.tiles { if let Some(effect) = tick_tile(dt, &self.data, tile) { match effect { - TickEffect::Progress => self.packet_out.push_back(PacketC::SetActive { + TickEffect::Progress(warn) => self.packet_out.push_back(PacketC::SetActive { + warn, tile: pos, progress: tile .item diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 7f694ad8..ef6d5bf7 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -13,6 +13,7 @@ pub enum Recipe { tile: Option<TileIndex>, input: ItemIndex, output: Option<ItemIndex>, + warn: bool, }, Active { duration: f32, @@ -42,6 +43,12 @@ impl Recipe { _ => None, } } + pub fn warn(&self) -> bool { + match self { + Recipe::Passive { warn, .. } => *warn, + _ => false, + } + } pub fn inputs(&self) -> Vec<ItemIndex> { match self { Recipe::Passive { input, .. } => vec![*input], @@ -189,7 +196,7 @@ pub fn interact( } pub enum TickEffect { - Progress, + Progress(bool), Produce, } pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect> { @@ -205,7 +212,7 @@ pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect }; a.progress = 1.; } - return Some(TickEffect::Progress); + return Some(TickEffect::Progress(r.warn())); } } else { for (ri, recipe) in data.recipes() { @@ -220,11 +227,11 @@ pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect recipe: ri, progress: 0., working: 1, - }) + }); + return Some(TickEffect::Progress(recipe.warn())); } } } - return Some(TickEffect::Progress); } } None diff --git a/server/src/protocol.rs b/server/src/protocol.rs index a82dad96..305ffa1d 100644 --- a/server/src/protocol.rs +++ b/server/src/protocol.rs @@ -96,6 +96,7 @@ pub enum PacketC { SetActive { tile: IVec2, progress: Option<f32>, + warn: bool, }, UpdateMap { pos: IVec2, diff --git a/test-client/main.ts b/test-client/main.ts index eeb9d9c0..9a7e41a4 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -43,6 +43,7 @@ export interface ItemData { y: number, tracking?: V2, progress?: number + progress_warn?: boolean remove_anim?: number } export interface PlayerData { @@ -139,7 +140,9 @@ function packet(p: PacketC) { break; } case "set_active": { - tiles.get(p.tile.toString())!.item!.progress = p.progress + const item = tiles.get(p.tile.toString())!.item!; + item.progress = p.progress + item.progress_warn = p.warn break; } case "update_map": diff --git a/test-client/protocol.ts b/test-client/protocol.ts index f075852e..145e08fe 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -26,7 +26,7 @@ export type PacketC = | { type: "put_item", tile: Vec2, player: PlayerID } // An item was put on a tile | { type: "set_tile_item", tile: Vec2, item?: ItemIndex } // A tile changed its item | { type: "set_player_item", player: PlayerID, item?: ItemIndex } // A player changed their item - | { type: "set_active", tile: Vec2, progress?: number } // A tile is doing something. progress goes from 0 to 1, then null when finished + | { type: "set_active", tile: Vec2, progress?: number, warn: boolean } // A tile is doing something. progress goes from 0 to 1, then null when finished | { type: "update_map", pos: Vec2, tile: TileIndex, neighbors: [TileIndex | null] } // A map tile was changed | { type: "communicate", player: PlayerID, message?: Message } // A player wants to communicate something, message is null when cleared diff --git a/test-client/visual.ts b/test-client/visual.ts index 4d7468eb..2b98561a 100644 --- a/test-client/visual.ts +++ b/test-client/visual.ts @@ -91,7 +91,7 @@ function draw_item(item: ItemData) { c(ctx) } if (item.progress !== null && item.progress !== undefined) { - ctx.fillStyle = "rgba(115, 230, 58, 0.66)" + ctx.fillStyle = item.progress_warn ? "rgba(230, 58, 58, 0.66)" : "rgba(115, 230, 58, 0.66)" ctx.fillRect(-0.5, -0.5, 1, item.progress) } ctx.restore() |