the huge refactor
This commit is contained in:
+14
-15
@@ -20,7 +20,7 @@ use kiln_core::game::GameState;
|
||||
use kiln_core::glyph::Glyph;
|
||||
use kiln_core::log::LogLine;
|
||||
use kiln_core::world::World;
|
||||
use kiln_core::{Archetype, Board, Builtin};
|
||||
use kiln_core::{Board, Builtin};
|
||||
use kiln_ui::code_editor::{CodeEditor, CodeEditorOutcome};
|
||||
use kiln_ui::dialog::{Dialog, DialogResult, ListDialogResponse};
|
||||
use ratatui::Frame;
|
||||
@@ -31,6 +31,7 @@ use ratatui::symbols::merge::MergeStrategy;
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Paragraph};
|
||||
use std::cell::{Ref, RefMut};
|
||||
use kiln_core::tile::TileSpec;
|
||||
|
||||
/// How long each half of the cursor blink lasts, in seconds.
|
||||
const BLINK_SECS: f32 = 0.5;
|
||||
@@ -70,7 +71,7 @@ pub(crate) struct EditorState {
|
||||
/// The archetype the drawing tools stamp on [`place_current`](EditorState::place_current).
|
||||
/// Defaults to [`Archetype::Wall`]; changed via the Terrain / Pushers menus
|
||||
/// ([`set_current`](EditorState::set_current)).
|
||||
current_archetype: Archetype,
|
||||
current_archetype: &'static str,
|
||||
/// The glyph the drawing tools stamp. Reset to the current archetype's default
|
||||
/// whenever the archetype changes ([`set_current`](EditorState::set_current)), and
|
||||
/// overridable via the glyph picker (`g`).
|
||||
@@ -112,7 +113,7 @@ impl EditorState {
|
||||
code_editor: None,
|
||||
glyph_dialog: None,
|
||||
cursor,
|
||||
current_archetype: Archetype::Builtin(Builtin::Wall, "wall"),
|
||||
current_archetype: "wall",
|
||||
current_glyph: Builtin::Wall.default_glyph_for("wall"),
|
||||
draw_mode: false,
|
||||
sidebar_width: DEFAULT_SIDEBAR_WIDTH,
|
||||
@@ -241,17 +242,21 @@ impl EditorState {
|
||||
/// Sets the archetype the drawing tools stamp, resetting the drawing glyph to
|
||||
/// that archetype's default (the glyph picker `g` can then override it). Called by
|
||||
/// the Terrain / Pushers menu choices.
|
||||
pub(crate) fn set_current(&mut self, archetype: Archetype) {
|
||||
self.current_archetype = archetype;
|
||||
self.current_glyph = self.current_archetype.default_glyph();
|
||||
pub(crate) fn set_current(&mut self, archetype: &'static str) {
|
||||
if let Some((builtin, variant)) = Builtin::from_name(archetype) {
|
||||
self.current_archetype = variant;
|
||||
self.current_glyph = builtin.default_glyph_for(variant);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stamps the current drawing thing (archetype + glyph) into the cell under the
|
||||
/// cursor, applying the placement rules (see [`Board::place_archetype`]).
|
||||
pub(crate) fn place_current(&mut self) {
|
||||
let (x, y) = (self.cursor.0 as usize, self.cursor.1 as usize);
|
||||
let (arch, glyph) = (self.current_archetype, self.current_glyph);
|
||||
self.board_mut().place_archetype(x, y, arch, glyph);
|
||||
let res = self.board_mut().place(x, y, Some(TileSpec::Builtin { kind: self.current_archetype.to_string(), glyph: Some(self.current_glyph) }));
|
||||
if let Err(e) = res {
|
||||
self.log.push(LogLine::error(e))
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggles draw mode (whether cursor movement auto-stamps the current thing).
|
||||
@@ -330,12 +335,6 @@ impl EditorState {
|
||||
let mut world = self.world.deep_clone();
|
||||
// Start the playtest on the board open in the editor, not world.start.
|
||||
world.start = self.board_name.clone();
|
||||
// Editor-stamped machines (spinners, pushers) are plain terrain cells; expand
|
||||
// them into their scripted objects so they actually run, just as the map loader
|
||||
// does on disk-loaded worlds.
|
||||
for board in world.boards.values() {
|
||||
board.borrow_mut().expand_builtin_archetypes();
|
||||
}
|
||||
let mut game = GameState::from_world(world);
|
||||
game.log(LogLine::raw("[esc] to return to the editor"));
|
||||
game.run_init();
|
||||
@@ -520,7 +519,7 @@ fn draw_footer_lines<'a>(
|
||||
// Separator marking off the footer from the menu above.
|
||||
Line::from(Span::styled("─".repeat(64), sep_style)),
|
||||
// The archetype currently being drawn (no UI to change it yet).
|
||||
Line::from(Span::styled(ed.current_archetype.name(), label_style)),
|
||||
Line::from(Span::styled(ed.current_archetype, label_style)),
|
||||
Line::from(vec![
|
||||
Span::styled("[G] ", key_style),
|
||||
Span::styled("Glyph ", label_style),
|
||||
|
||||
Reference in New Issue
Block a user