mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
color player cursors
This commit is contained in:
parent
e64bf606d3
commit
f41d632775
7 changed files with 33 additions and 9 deletions
|
@ -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,16 +299,18 @@ 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()));
|
||||
self.send(
|
||||
id,
|
||||
&NetMsg::PlayerColor((
|
||||
self.peer.my_id().unwrap().to_string(),
|
||||
self.init_settings.cosmetics,
|
||||
self.init_settings.player_color,
|
||||
)),
|
||||
self.peer.my_id().unwrap().to_string(),
|
||||
self.init_settings.cosmetics,
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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();
|
||||
|
@ -357,4 +377,4 @@ fn edit_by_replacing(
|
|||
|
||||
fn rgb_to_hex(rgb: [u8; 4]) -> String {
|
||||
format!("{:02X}{:02X}{:02X}", rgb[0], rgb[1], rgb[2])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue