Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/editor/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ pub enum EditorAction {
OpenCreateMapWindow,
OpenMap(usize),
OpenLoadMapWindow,
SaveMap(Option<String>),
SaveMap {
name: Option<String>,
is_user_map: Option<bool>,
},
OpenSaveMapWindow,
DeleteMap(usize),
ExitToMainMenu,
Expand Down
2 changes: 1 addition & 1 deletion src/editor/gui/editor_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn open_editor_menu(ctx: &EditorContext) {
MenuEntry {
index: EDITOR_MENU_RESULT_SAVE,
title: "Save".to_string(),
is_disabled: !ctx.is_user_map,
is_disabled: !ctx.is_user_map && !cfg!(debug_assertions),
..Default::default()
},
MenuEntry {
Expand Down
5 changes: 4 additions & 1 deletion src/editor/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ impl EditorGui {
res = Some(action);
}
EDITOR_MENU_RESULT_SAVE => {
let action = EditorAction::SaveMap(None);
let action = EditorAction::SaveMap {
name: None,
is_user_map: None,
};
res = Some(action);
}
EDITOR_MENU_RESULT_SAVE_AS => {
Expand Down
5 changes: 4 additions & 1 deletion src/editor/gui/windows/save_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ impl Window for SaveMapWindow {

let mut action = None;
if is_valid_map_export_path(&path, self.should_overwrite) {
let save_action = EditorAction::SaveMap(Some(self.name.clone()));
let save_action = EditorAction::SaveMap {
name: Some(self.name.clone()),
is_user_map: Some(true),
};
let batch = self.get_close_action().then(save_action);

action = Some(batch);
Expand Down
11 changes: 8 additions & 3 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ impl Editor {
let mut gui = storage::get_mut::<EditorGui>();
gui.add_window(LoadMapWindow::new());
}
EditorAction::SaveMap(name) => {
EditorAction::SaveMap { name, is_user_map } => {
let mut map_resource = self.map_resource.clone();

if let Some(name) = name {
Expand All @@ -630,7 +630,9 @@ impl Editor {
map_resource.meta.path = path.to_string_lossy().to_string();
}

map_resource.meta.is_user_map = true;
if let Some(is_user_map) = is_user_map {
map_resource.meta.is_user_map = is_user_map;
}
map_resource.meta.is_tiled_map = false;

let mut resources = storage::get_mut::<Resources>();
Expand Down Expand Up @@ -692,7 +694,10 @@ impl Node for Editor {

if node.input.save {
let action = if node.map_resource.meta.is_user_map {
EditorAction::SaveMap(None)
EditorAction::SaveMap {
name: None,
is_user_map: None,
}
} else {
EditorAction::OpenSaveMapWindow
};
Expand Down
10 changes: 7 additions & 3 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,15 @@ impl Resources {
let assets_path = Path::new(&self.assets_dir);
let export_path = assets_path.join(&map_resource.meta.path);

let mut map_already_existed = false;
if export_path.exists() {
let mut i = 0;
while i < self.maps.len() {
let res = &self.maps[i];
if res.meta.path == map_resource.meta.path {
if res.meta.is_user_map {
self.maps.remove(i);
if res.meta.is_user_map || cfg!(debug_assertions) {
map_already_existed = true;
self.maps[i] = map_resource.clone();
break;
} else {
return Err(formaterr!(
Expand All @@ -453,7 +455,9 @@ impl Resources {

map_resource.map.save(export_path)?;

self.maps.push(map_resource.clone());
if !map_already_existed {
self.maps.push(map_resource.clone());
}
self.save_maps_file()?;

Ok(())
Expand Down