Skip to content

Commit

Permalink
add checkerbox background to tile selector
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaiZephyr committed Jan 16, 2025
1 parent 17eb142 commit 110e23b
Show file tree
Hide file tree
Showing 28 changed files with 1,211 additions and 378 deletions.
4 changes: 3 additions & 1 deletion game/editor/src/action_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ pub fn merge_actions(actions: &mut Vec<EditorAction>) -> anyhow::Result<()> {
}

while actions.len() > 1 {
let act1 = actions.pop();
let act2 = actions.pop();
let act1 = actions.pop();

if let (Some(act1), Some(act2)) = (act1, act2) {
let (act1, act2) = merge_actions_group(act1, act2)?;
Expand All @@ -562,6 +562,8 @@ pub fn merge_actions(actions: &mut Vec<EditorAction>) -> anyhow::Result<()> {
actions.push(act2);
break;
}
} else {
unreachable!();
}
}

Expand Down
118 changes: 98 additions & 20 deletions game/editor/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ use graphics::{
texture::texture::GraphicsTextureHandle,
},
};
use math::math::vector::vec2;
use network::network::types::NetworkClientCertCheckMode;
use sound::sound_mt::SoundMultiThreaded;

use crate::{
action_logic::do_action,
action_logic::{do_action, undo_action},
actions::actions::{EditorAction, EditorActionGroup},
event::{EditorEvent, EditorEventGenerator, EditorEventOverwriteMap, EditorNetEvent},
event::{
ClientProps, EditorCommand, EditorEvent, EditorEventClientToServer, EditorEventGenerator,
EditorEventOverwriteMap, EditorEventServerToClient, EditorNetEvent,
},
map::EditorMap,
network::EditorNetwork,
notifications::{EditorNotification, EditorNotifications},
Expand All @@ -31,6 +35,12 @@ pub struct EditorClient {

notifications: EditorNotifications,
local_client: bool,

pub(crate) clients: Vec<ClientProps>,
pub(crate) server_id: u64,

mapper_name: String,
color: [u8; 3],
}

impl EditorClient {
Expand All @@ -41,11 +51,13 @@ impl EditorClient {
notifications: EditorNotifications,
server_password: String,
local_client: bool,
mapper_name: Option<String>,
color: Option<[u8; 3]>,
) -> Self {
let has_events: Arc<AtomicBool> = Default::default();
let event_generator = Arc::new(EditorEventGenerator::new(has_events.clone()));

let mut res = Self {
let res = Self {
network: EditorNetwork::new_client(
sys,
event_generator.clone(),
Expand All @@ -56,12 +68,21 @@ impl EditorClient {
event_generator,
notifications,
local_client,

clients: Default::default(),
server_id: Default::default(),

mapper_name: mapper_name.unwrap_or_else(|| "mapper".to_string()),
color: color.unwrap_or([255, 255, 255]),
};

res.network.send(EditorEvent::Auth {
password: server_password,
is_local_client: local_client,
});
res.network
.send(EditorEvent::Client(EditorEventClientToServer::Auth {
password: server_password,
is_local_client: local_client,
mapper_name: res.mapper_name.clone(),
color: res.color,
}));

res
}
Expand All @@ -83,8 +104,8 @@ impl EditorClient {

for (id, _, event) in events {
match event {
EditorNetEvent::Editor(ev) => match ev {
EditorEvent::Action(act) => {
EditorNetEvent::Editor(EditorEvent::Server(ev)) => match ev {
EditorEventServerToClient::DoAction(act) => {
if !self.local_client {
for act in act.actions {
if let Err(err) = do_action(
Expand All @@ -103,17 +124,42 @@ impl EditorClient {
}
}
}
EditorEvent::Command(_) => {
// ignore
EditorEventServerToClient::UndoAction(act) => {
if !self.local_client {
for act in act.actions.into_iter().rev() {
if let Err(err) = undo_action(
tp,
sound_mt,
graphics_mt,
buffer_object_handle,
backend_handle,
texture_handle,
act,
map,
) {
self.notifications.push(EditorNotification::Error(format!("There has been an critical error while processing a action of the server: {err}.\nThis usually indicates a bug in the editor code.\nCan not continue.")));
return Err(anyhow!("critical error during do_action"));
}
}
}
}
EditorEvent::Error(err) => todo!("{}", err),
EditorEvent::Auth { .. } => {
// ignore
EditorEventServerToClient::Error(err) => {
self.notifications.push(EditorNotification::Error(err));
}
EditorEvent::Map(map) => {
EditorEventServerToClient::Map(map) => {
res = Some(map);
}
EditorEventServerToClient::Infos(infos) => {
self.clients = infos;
}
EditorEventServerToClient::Info { server_id } => {
self.server_id = server_id;
}
},

EditorNetEvent::Editor(EditorEvent::Client(_)) => {
// ignore
}
EditorNetEvent::NetworkEvent(ev) => self.network.handle_network_ev(id, ev),
}
}
Expand All @@ -123,13 +169,45 @@ impl EditorClient {
}

pub fn execute(&mut self, action: EditorAction, group_identifier: Option<&str>) {
self.network.send(EditorEvent::Action(EditorActionGroup {
actions: vec![action],
identifier: group_identifier.map(|s| s.to_string()),
}));
self.network
.send(EditorEvent::Client(EditorEventClientToServer::Action(
EditorActionGroup {
actions: vec![action],
identifier: group_identifier.map(|s| s.to_string()),
},
)));
}

pub fn execute_group(&mut self, action_group: EditorActionGroup) {
self.network.send(EditorEvent::Action(action_group));
self.network
.send(EditorEvent::Client(EditorEventClientToServer::Action(
action_group,
)));
}

pub fn undo(&self) {
self.network
.send(EditorEvent::Client(EditorEventClientToServer::Command(
EditorCommand::Undo,
)));
}

pub fn redo(&self) {
self.network
.send(EditorEvent::Client(EditorEventClientToServer::Command(
EditorCommand::Redo,
)));
}

pub fn update_info(&self, cursor_world_pos: vec2) {
self.network
.send(EditorEvent::Client(EditorEventClientToServer::Info(
ClientProps {
mapper_name: self.mapper_name.clone(),
color: self.color,
cursor_world: cursor_world_pos,
server_id: self.server_id,
},
)));
}
}
Loading

0 comments on commit 110e23b

Please sign in to comment.