add onshowscene and get_current_scene functions

This commit is contained in:
Rusty Striker 2025-06-16 20:57:51 +03:00
parent f59c06c348
commit 731f22a2c2
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15
7 changed files with 188 additions and 103 deletions

View file

@ -42,7 +42,7 @@ impl GameServer {
ActionDefinition::new("weapon/attack".to_string())
.display_name(Some("Attack +7".to_string()))
.with_roll(DiceRoll::new("Pierce".to_string(), 12, 1).constant(1))
.with_roll(DiceRoll::new("Fire".to_string(), 4, 2)),
.with_roll(DiceRoll::new("Fire".to_string(), 4, 2).enabled(false)),
)
.with_action(ActionDefinition::new("Attack +3".to_string()).with_roll(DiceRoll::new(
"Base".to_string(),
@ -158,6 +158,33 @@ impl GameServer {
}
}
}
api::Request::GetCurrentScene => {
let scene = self.game.current_scene();
let mut scene_tokens = self
.game
.available_tokens(scene)
.iter()
.map(|id| self.game.token_info(0, *id).map(|info| (id, info)))
.flatten()
.map(|(id, info)| SpawnToken {
token_id: *id,
x: info.x,
y: info.y,
img: info.img_source.clone(),
})
.collect::<Vec<_>>();
for spawn in scene_tokens.iter_mut() {
let bits = std::fs::read(&spawn.img).expect("FAILED READING TOKEN IMAGE");
spawn.img = base64::Engine::encode(&base64::prelude::BASE64_STANDARD, &bits);
}
_ = broadcast.send((
Some(id.clone()),
api::Response::ShowScene {
scene: scene,
tokens: scene_tokens,
},
));
}
api::Request::SpawnToken {
map_id,
character,