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
8 changes: 6 additions & 2 deletions lib/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ fn save_file(_: &Lua, (dmi, filename): (LuaTable, String)) -> LuaResult<LuaValue
Ok(LuaValue::Nil)
}

fn new_state(lua: &Lua, (width, height, temp): (u32, u32, String)) -> LuaResult<LuaTable> {
fn new_state(
lua: &Lua,
(width, height, temp, name): (u32, u32, String, Option<String>),
) -> LuaResult<LuaTable> {
if !Path::new(&temp).exists() {
Err("Temp directory does not exist".to_string()).into_lua_err()?
}

let state = State::new_blank(String::new(), width, height).to_serialized(temp)?;
let state_name = name.unwrap_or(String::new());
let state = State::new_blank(state_name, width, height).to_serialized(temp)?;
let table = state.into_lua_table(lua)?;

Ok(table)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{ "path": "./scripts/classes/preferences.lua" },
{ "path": "./scripts/classes/editor/_editor.lua" },
{ "path": "./scripts/classes/editor/rendering.lua" },
{ "path": "./scripts/classes/editor/state_operations.lua" },
{ "path": "./scripts/classes/editor/state.lua" },
{ "path": "./scripts/classes/statesprite.lua" },
{ "path": "./scripts/classes/widget.lua" },
Expand Down
16 changes: 12 additions & 4 deletions scripts/classes/editor/_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--- @field dmi Dmi The currently opened DMI file.
--- @field open_sprites (StateSprite)[] A table containing all open sprites.
--- @field widgets (AnyWidget)[] A table containing all state widgets.
--- @field selected_states State[] Selected icon widgets to possibly combine.
--- @field context_widget ContextWidget|nil The state that is currently being right clicked
--- @field beforecommand number The event object for the "beforecommand" event.
--- @field aftercommand number The event object for the "aftercommand" event.
Expand All @@ -28,8 +29,6 @@ Editor.__index = Editor

--- @class Editor.Mouse
--- @field position Point The current mouse position.
--- @field leftClick boolean Whether the left mouse button is pressed.
--- @field rightClick boolean Whether the right mouse button is pressed.

--- Creates a new instance of the Editor class.
--- @param title string The title of the editor.
Expand All @@ -44,14 +43,19 @@ function Editor.new(title, dmi)
self.focused_widget = nil
self.hovering_widgets = {}
self.scroll = 0
self.mouse = { position = Point(0, 0), leftClick = false, rightClick = false }
self.mouse = { position = Point(0, 0) }
self.dmi = nil
self.open_sprites = {}
self.widgets = {}
self.selected_states = {}
self.context_widget = nil
self.save_path = nil
self.open_path = is_filename and dmi --[[@as string]] or nil

self.dragging = false
self.drag_start_time = math.huge
self.drop_index = nil

self.canvas_width = 185
self.canvas_height = 215
self.max_in_a_row = 1
Expand Down Expand Up @@ -220,7 +224,10 @@ end

--- Shows the editor dialog.
function Editor:show()
self.dialog:show { wait = false }
self.dialog:show {
wait = false,
autoscrollbars=true,
}
end

--- Opens a DMI file and displays it in the editor.
Expand All @@ -239,6 +246,7 @@ function Editor:open_file(dmi)
self.scroll = 0
self.dmi = nil
self.widgets = {}
self.selected_states = {}
self.open_sprites = {}
self.save_path = nil

Expand Down
Loading