Skip to content

Commit a0923f3

Browse files
committed
Move editor support.rs to main.rs
1 parent b654bd1 commit a0923f3

5 files changed

Lines changed: 43 additions & 46 deletions

File tree

crates/spaceman-dmm/src/edit_prefab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Environment, GREEN, RED};
1+
use crate::editor::{Environment, GREEN, RED};
22
use dmm_tools::dmm::Prefab;
33
use imgui::*;
44

crates/spaceman-dmm/src/editor.rs

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
//! The map editor proper, with a GUI and everything.
2-
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
3-
#![allow(dead_code)] // TODO: remove when this is not a huge WIP
4-
#![allow(unused_variables)]
5-
6-
mod config;
7-
mod dmi;
8-
mod edit_prefab;
9-
mod history;
10-
mod map_renderer;
11-
mod map_repr;
12-
mod support;
13-
mod tasks;
14-
mod tools;
15-
16-
use dmi::IconCache;
1+
use crate::dmi::IconCache;
2+
use crate::edit_prefab::EditPrefab;
3+
use crate::{config, dmi, history, map_renderer, map_repr, tasks, tools};
174
use dmm_tools::dmm::Map;
185
use dreammaker::objtree::{ObjectTree, TypeRef};
19-
use edit_prefab::EditPrefab;
206
use imgui::*;
217
use sdl3::dialog::{DialogError, DialogFileFilter};
228
use sdl3::gpu::{ColorTargetInfo, CommandBuffer, Device};
@@ -26,27 +12,23 @@ use std::borrow::Cow;
2612
use std::path::{Path, PathBuf};
2713
use std::sync::{mpsc, Arc};
2814

29-
type History = history::History<map_repr::AtomMap, Environment>;
30-
type ImRenderer = imgui_sdl3::renderer::Renderer;
15+
pub type History = history::History<map_repr::AtomMap, Environment>;
16+
pub type ImRenderer = imgui_sdl3::renderer::Renderer;
3117

32-
const RED: [f32; 4] = [1.0, 0.25, 0.25, 1.0];
33-
const GREEN: [f32; 4] = [0.25, 1.0, 0.25, 1.0];
18+
pub const RED: [f32; 4] = [1.0, 0.25, 0.25, 1.0];
19+
pub const GREEN: [f32; 4] = [0.25, 1.0, 0.25, 1.0];
3420
const THUMBNAIL_SIZE: u16 = 186;
3521
const MAX_ZOOM: f32 = 16.;
3622
const MIN_ZOOM: f32 = 1. / 16.;
3723

3824
const CLEAR_COLOR: Color = Color::RGB(64, 64, 128);
3925

40-
fn main() {
41-
support::run("SpacemanDMM");
42-
}
43-
4426
// ---------------------------------------------------------------------------
4527
// Data structures
4628

4729
pub struct EditorScene {
4830
device: sdl3::gpu::Device,
49-
logical_size: (u32, u32),
31+
pub logical_size: (u32, u32),
5032

5133
config: config::Config,
5234
map_renderer: map_renderer::MapRenderer,
@@ -100,8 +82,8 @@ enum Command {
10082
pub struct Environment {
10183
path: PathBuf,
10284
errors: Vec<String>,
103-
objtree: Arc<ObjectTree>,
104-
icons: Arc<IconCache>,
85+
pub objtree: Arc<ObjectTree>,
86+
pub icons: Arc<IconCache>,
10587
turf: String,
10688
area: String,
10789
}
@@ -153,7 +135,7 @@ struct EditInstance {
153135
// Editor scene, including rendering and UI
154136

155137
impl EditorScene {
156-
fn new(device: &Device, logical_size: (u32, u32)) -> Self {
138+
pub fn new(device: &Device, logical_size: (u32, u32)) -> Self {
157139
let (command_tx, command_rx) = mpsc::channel();
158140
let mut ed = EditorScene {
159141
device: device.clone(),
@@ -281,7 +263,7 @@ impl EditorScene {
281263
self.environment = Some(environment);
282264
}
283265

284-
fn run(&mut self) {
266+
pub fn run(&mut self) {
285267
while let Ok(command) = self.command_rx.try_recv() {
286268
match command {
287269
Command::DialogError(e) => self.handle_dialog_error(e),
@@ -390,7 +372,7 @@ impl EditorScene {
390372
}
391373
}
392374

393-
fn render(&mut self, command_buffer: &mut CommandBuffer, target: ColorTargetInfo) {
375+
pub fn render(&mut self, command_buffer: &mut CommandBuffer, target: ColorTargetInfo) {
394376
let target = target
395377
.with_clear_color(CLEAR_COLOR)
396378
.with_load_op(sdl3::gpu::LoadOp::CLEAR);
@@ -437,7 +419,7 @@ impl EditorScene {
437419
self.device.end_render_pass(render_pass);
438420
}
439421

440-
fn run_ui(&mut self, ui: &Ui, renderer: &mut ImRenderer) -> bool {
422+
pub fn run_ui(&mut self, ui: &Ui, renderer: &mut ImRenderer) -> bool {
441423
ui.dockspace_over_main_viewport();
442424

443425
for tool in self.tools.iter_mut() {
@@ -1225,7 +1207,7 @@ impl EditorScene {
12251207
continue_running
12261208
}
12271209

1228-
fn mouse_moved(&mut self, (x, y): (i32, i32)) {
1210+
pub fn mouse_moved(&mut self, (x, y): (i32, i32)) {
12291211
self.last_mouse_pos = (x, y);
12301212
self.target_tile = self.tile_under((x, y));
12311213
}
@@ -1262,7 +1244,7 @@ impl EditorScene {
12621244
}
12631245
}
12641246

1265-
fn mouse_wheel(&mut self, ctrl: bool, shift: bool, alt: bool, x: f32, y: f32) {
1247+
pub fn mouse_wheel(&mut self, ctrl: bool, shift: bool, alt: bool, x: f32, y: f32) {
12661248
if alt {
12671249
if y > 0.0 {
12681250
self.zoom_in();
@@ -1294,7 +1276,7 @@ impl EditorScene {
12941276

12951277
// Commented out due to https://github.com/rust-lang/rust/issues/82012
12961278
//#[deny(unreachable_patterns)]
1297-
fn chord(&mut self, ctrl: bool, shift: bool, alt: bool, key: Scancode) {
1279+
pub fn chord(&mut self, ctrl: bool, shift: bool, alt: bool, key: Scancode) {
12981280
macro_rules! k {
12991281
(@[$ctrl:pat, $shift:pat, $alt:pat] $k:ident) => {
13001282
($ctrl, $shift, $alt, Scancode::$k)
@@ -1608,7 +1590,7 @@ const FILTERS_DMM: &[DialogFileFilter] = &[DialogFileFilter {
16081590
// Helpers
16091591

16101592
impl Environment {
1611-
fn find_closest_type(&self, mut path: &str) -> (bool, Option<TypeRef<'_>>) {
1593+
pub fn find_closest_type(&self, mut path: &str) -> (bool, Option<TypeRef<'_>>) {
16121594
// find the "best" type by chopping the path if needed
16131595
let mut ty = self.objtree.find(path);
16141596
let red_paths = ty.is_none();
@@ -1704,7 +1686,7 @@ fn detect_environment(path: &Path) -> Option<PathBuf> {
17041686
None
17051687
}
17061688

1707-
fn prepare_tool_icon(
1689+
pub fn prepare_tool_icon(
17081690
renderer: &mut ImRenderer,
17091691
environment: Option<&Environment>,
17101692
map_renderer: &mut map_renderer::MapRenderer,
@@ -1768,7 +1750,7 @@ fn prepare_tool_icon(
17681750
// ---------------------------------------------------------------------------
17691751
// Extension traits
17701752

1771-
trait UiExt {
1753+
pub trait UiExt {
17721754
fn fits_width(&self, width: f32) -> usize;
17731755
fn objtree_menu<'e>(&self, env: &'e Environment, selection: &mut Option<TypeRef<'e>>);
17741756
fn tool_icon(
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
//! Platform support helpers.
1+
//! The map editor proper, with a GUI and everything.
2+
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
3+
#![allow(dead_code)] // TODO: remove when this is not a huge WIP
4+
#![allow(unused_variables)]
5+
6+
mod config;
7+
mod dmi;
8+
mod edit_prefab;
9+
mod editor;
10+
mod history;
11+
mod map_renderer;
12+
mod map_repr;
13+
mod tasks;
14+
mod tools;
15+
216
use imgui::{ConfigFlags, Context, FontConfig};
317
use imgui_sdl3::{platform::Platform, renderer::Renderer};
418
use sdl3::{
@@ -7,15 +21,15 @@ use sdl3::{
721
hint::names::RENDER_VSYNC,
822
};
923

10-
pub fn run(title: &str) {
24+
fn main() {
1125
sdl3::hint::set(RENDER_VSYNC, "1");
1226

1327
let mut sdl = sdl3::init().expect("sdl3::init");
1428
let mut events = sdl.event_pump().expect("event_pump");
1529
let video = sdl.video().expect("video");
1630

1731
let window = video
18-
.window(title, 1300, 730)
32+
.window("SpacemanDMM", 1300, 730)
1933
.position_centered()
2034
.resizable()
2135
.build()
@@ -54,7 +68,7 @@ pub fn run(title: &str) {
5468
let mut im_platform = Platform::new(&mut imgui);
5569
let mut im_renderer = Renderer::new(&device, &window, &mut imgui).expect("Renderer::new");
5670

57-
let mut scene = crate::EditorScene::new(&device, window.size());
71+
let mut scene = editor::EditorScene::new(&device, window.size());
5872

5973
let mut quit = false;
6074

crates/spaceman-dmm/src/tools/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Placement and editing tools which appear in the workbench.
22
3-
use crate::{Environment, History, ImRenderer};
3+
use crate::editor::{Environment, History, ImRenderer};
44
use dmm_tools::dmm::Prefab;
55
use dreammaker::dmi;
66
use dreammaker::objtree::ObjectTree;
@@ -142,7 +142,7 @@ impl ToolIcon {
142142

143143
pub fn prepare(&mut self, environment: Option<&Environment>, ctx: &mut IconCtx) -> &mut Self {
144144
let temp = std::mem::replace(self, ToolIcon::None);
145-
*self = crate::prepare_tool_icon(ctx.renderer, environment, ctx.map_renderer, temp);
145+
*self = crate::editor::prepare_tool_icon(ctx.renderer, environment, ctx.map_renderer, temp);
146146
self
147147
}
148148
}

crates/spaceman-dmm/src/tools/place.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
2-
use crate::{EditPrefab, UiExt};
2+
use crate::edit_prefab::EditPrefab;
3+
use crate::editor::UiExt;
34
use std::collections::HashSet;
45

56
/// The standard placement tool.

0 commit comments

Comments
 (0)