color player cursors

This commit is contained in:
bgkillas 2024-10-02 20:08:37 -04:00
parent e64bf606d3
commit f41d632775
7 changed files with 33 additions and 9 deletions

View file

@ -233,6 +233,7 @@ impl NetManager {
self.init_settings.cosmetics,
self.init_settings.player_color,
),
self.is_host()
);
while self.continue_running.load(atomic::Ordering::Relaxed) {
if cli {
@ -298,6 +299,7 @@ impl NetManager {
self.init_settings.cosmetics,
self.init_settings.player_color,
),
self.is_host()
);
}
state.try_ws_write(ws_encode_proxy("join", id.as_hex()));
@ -306,8 +308,9 @@ impl NetManager {
&NetMsg::PlayerColor((
self.peer.my_id().unwrap().to_string(),
self.init_settings.cosmetics,
self.init_settings.player_color,
)),
self.init_settings.player_color),
self.is_host()
),
Reliability::Reliable,
);
}
@ -344,11 +347,12 @@ impl NetManager {
}
}
NetMsg::WorldMessage(msg) => state.world.handle_msg(src, msg),
NetMsg::PlayerColor(rgb) => {
NetMsg::PlayerColor(rgb, host) => {
create_player_png(
&self.init_settings.mod_path,
&self.init_settings.player_path,
rgb,
host
);
}
}

View file

@ -25,7 +25,7 @@ pub(crate) enum NetMsg {
ModRaw { data: Vec<u8> },
ModCompressed { data: Vec<u8> },
WorldMessage(WorldNetMessage),
PlayerColor((String, (bool, bool, bool), PlayerColor)),
PlayerColor((String, (bool, bool, bool), PlayerColor), bool),
}
impl From<MessageRequest<WorldNetMessage>> for MessageRequest<NetMsg> {

View file

@ -15,6 +15,15 @@ pub fn player_path(path: PathBuf) -> PathBuf {
path.join("files/system/player/unmodified.png")
}
pub fn arrows_path(path: PathBuf, is_host: bool) -> PathBuf {
let p = path.parent().unwrap().join("player_arrows");
if is_host {
p.join("arrow_host.png")
} else {
p.join("arrow.png")
}
}
pub fn replace_color(image: &mut RgbaImage, main: Rgba<u8>, alt: Rgba<u8>, arm: Rgba<u8>) {
let target_main = Rgba::from([155, 111, 154, 255]);
let target_alt = Rgba::from([127, 84, 118, 255]);
@ -219,6 +228,7 @@ pub fn create_player_png(
mod_path: &Path,
player_path: &Path,
rgb: (String, (bool, bool, bool), PlayerColor),
is_host: bool
) {
let id = if rgb.0.len() < 5 {
format!("{:01$}", rgb.0.parse::<usize>().unwrap(), 16)
@ -228,6 +238,7 @@ pub fn create_player_png(
let cosmetics = rgb.1;
let rgb = rgb.2;
let tmp_path = player_path.parent().unwrap();
let arrows_path = arrows_path(tmp_path.into(), is_host);
let mut img = image::open(player_path).unwrap().into_rgba8();
replace_color(
&mut img,
@ -235,8 +246,17 @@ pub fn create_player_png(
Rgba::from(rgb.player_alt),
Rgba::from(rgb.player_arm),
);
let mut img_arrow = image::open(arrows_path).unwrap().into_rgba8();
replace_color(
&mut img_arrow,
Rgba::from(rgb.player_main),
Rgba::from(rgb.player_alt),
Rgba::from(rgb.player_arm),
);
let path = tmp_path.join(format!("tmp/{}.png", id));
img.save(path).unwrap();
let path = tmp_path.join(format!("tmp/{}_arrow.png", id));
img_arrow.save(path).unwrap();
let img = create_arm(Rgba::from(rgb.player_forearm));
let path = tmp_path.join(format!("tmp/{}_arm.png", id));
img.save(path).unwrap();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

View file

@ -117,13 +117,13 @@ function module.on_world_update()
if is_notplayer then
img_path = "mods/quant.ew/files/system/player_arrows/arrow_host_notplayer.png"
else
img_path = "mods/quant.ew/files/system/player_arrows/arrow_host.png"
img_path = "mods/quant.ew/files/system/player/tmp/" .. player_data.peer_id .. "_arrow.png"
end
else
if is_notplayer then
img_path = "mods/quant.ew/files/system/player_arrows/arrow_notplayer.png"
else
img_path = "mods/quant.ew/files/system/player_arrows/arrow.png"
img_path = "mods/quant.ew/files/system/player/tmp/" .. player_data.peer_id .. "_arrow.png"
end
end
local scale = math.max(1 / 6, 0.7 - math.atan((math.sqrt(dist_sq) - tch) / 1280) / math.pi)