allow texture streaming(png, jpeg for now) and use texture url instead of passing textures in base64

This commit is contained in:
Rusty Striker 2025-06-20 16:47:55 +03:00
parent 1d63e3d983
commit d29a2a8590
Signed by: RustyStriker
GPG key ID: 9DBDBC7C48FC3C31
5 changed files with 47 additions and 17 deletions

View file

@ -144,15 +144,13 @@ impl GameServer {
api::Request::GetTokens { scene } => {
for token_id in self.game.available_tokens(scene) {
if let Some(ti) = self.game.token_info(0, token_id) {
let bits = std::fs::read(&ti.img_source).expect("FAILED READING TOKEN IMAGE");
let img = base64::Engine::encode(&base64::prelude::BASE64_STANDARD, &bits);
_ = broadcast.send((
Some(id.clone()),
api::Response::SpawnToken(SpawnToken {
token_id: token_id,
x: ti.x,
y: ti.y,
img,
img: ti.img_source.clone(),
}),
));
}
@ -160,7 +158,7 @@ impl GameServer {
}
api::Request::GetCurrentScene => {
let scene = self.game.current_scene();
let mut scene_tokens = self
let scene_tokens = self
.game
.available_tokens(scene)
.iter()
@ -173,10 +171,6 @@ impl GameServer {
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 {
@ -193,11 +187,9 @@ impl GameServer {
img_path,
} => {
let token_id = self.game.create_token(map_id, character, img_path.clone(), x, y);
let bits = std::fs::read(&img_path).expect("FAILED READING TOKEN IMAGE");
let img = base64::Engine::encode(&base64::prelude::BASE64_STANDARD, &bits);
_ = broadcast.send((
Some(id.clone()),
api::Response::SpawnToken(SpawnToken { token_id, x, y, img }),
api::Response::SpawnToken(SpawnToken { token_id, x, y, img: img_path.clone() }),
));
}
api::Request::MoveToken { token_id, x, y } => {