2015-03-25 01:38:53 -04:00
|
|
|
require "level_editor/object_attributes"
|
|
|
|
|
require "level_editor/gui"
|
2026-08-11 12:24:54 -04:00
|
|
|
require "level_editor/layout"
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
editorView = "room" --can be "off", "room", "world", "asset"
|
|
|
|
|
selectedColor = "red"
|
|
|
|
|
|
|
|
|
|
local bacSprite = love.graphics.newImage("art/_ui/bac.png")
|
|
|
|
|
local folderSprite = love.graphics.newImage("art/_ui/folder.png")
|
|
|
|
|
local cancelSprite = love.graphics.newImage("art/_ui/cancel.png")
|
|
|
|
|
local confirmSprite = love.graphics.newImage("art/_ui/confirm.png")
|
2026-08-07 01:39:47 -04:00
|
|
|
local clearSavesSprite = love.graphics.newImage("art/_ui/clear_saves.png")
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
local selectedFolder = nil
|
|
|
|
|
local selectedAsset = nil
|
|
|
|
|
local selectedRoom = nil
|
2015-03-25 04:22:10 -04:00
|
|
|
local gameAssets = {}
|
2015-03-25 01:38:53 -04:00
|
|
|
local inputText = ""
|
|
|
|
|
local assetProperties = {}
|
|
|
|
|
|
2015-03-25 03:58:37 -04:00
|
|
|
local hierarchy = {}
|
|
|
|
|
|
2015-03-25 01:38:53 -04:00
|
|
|
local activeField = nil --this is for whenwe are doing text input things
|
|
|
|
|
|
|
|
|
|
local uiButtons = {}
|
|
|
|
|
local folderButtons = {}
|
2026-08-11 12:24:54 -04:00
|
|
|
local assetListButtons = {} -- flat list of the selected folder's assets (scrolls)
|
|
|
|
|
local listScroll = { scroll = 0 } -- shared vertical scroll for the room list
|
2015-03-25 01:38:53 -04:00
|
|
|
local editingAssetButtons = {}
|
|
|
|
|
|
|
|
|
|
local labels = {}
|
2026-08-07 01:39:47 -04:00
|
|
|
local editorRoomName = nil
|
|
|
|
|
local roomNameField = nil
|
|
|
|
|
local editorStatus = nil
|
|
|
|
|
local clearSaveConfirmationExpires = 0
|
2026-08-07 03:22:28 -04:00
|
|
|
local clearSaveConfirmationScope = nil
|
2026-08-07 01:39:47 -04:00
|
|
|
local worldSeedConfirmationExpires = 0
|
|
|
|
|
local worldMode = "place"
|
|
|
|
|
local worldRoomButtons = {}
|
|
|
|
|
local worldControls = {}
|
|
|
|
|
local worldPage = 1
|
|
|
|
|
local worldPageSize = 5
|
2026-08-07 09:08:34 -04:00
|
|
|
local assetSearchText = ""
|
|
|
|
|
local assetSearchButtons = {}
|
|
|
|
|
local worldSearchText = ""
|
|
|
|
|
local worldSearchBox = { x = 10, y = 34, w = 0, h = 28 }
|
2026-08-11 14:11:57 -04:00
|
|
|
local roomBrush = nil
|
|
|
|
|
|
|
|
|
|
-- Convert a pointer position into a valid room cell. Keeping brush state in
|
|
|
|
|
-- cell coordinates means a click that jitters within a tile cannot place or
|
|
|
|
|
-- erase that tile more than once.
|
|
|
|
|
local function roomCellAt(x, y)
|
|
|
|
|
if x < 0 or x >= width or y < 0 or y >= height then return nil end
|
|
|
|
|
local cell = currentRoom:getCellFromMousePos(x, y)
|
|
|
|
|
cell.x = constrain(cell.x, 1, gridWidth)
|
|
|
|
|
cell.y = constrain(cell.y, 1, gridHeight)
|
|
|
|
|
return cell
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function paintRoomCell(cell, button)
|
|
|
|
|
-- Use the centre of the cell so Room's existing pointer-based edit helpers
|
|
|
|
|
-- perform the same operation as a normal click.
|
|
|
|
|
local x = (cell.x - .5) * width / gridWidth
|
|
|
|
|
local y = (cell.y - .5) * height / gridHeight
|
|
|
|
|
if button == 1 and selectedAsset then
|
|
|
|
|
currentRoom:attemptPlace(selectedAsset, gameAssets[selectedAsset], x, y, selectedColor)
|
|
|
|
|
elseif button == 2 then
|
|
|
|
|
currentRoom:attemptDelete(x, y, selectedColor)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function paintRoomLine(from, to, button)
|
|
|
|
|
-- Bresenham keeps a fast mouse movement from leaving holes between the
|
|
|
|
|
-- cells that happened to receive mouse-move events.
|
|
|
|
|
local x, y = from.x, from.y
|
|
|
|
|
local dx, dy = math.abs(to.x - x), math.abs(to.y - y)
|
|
|
|
|
local stepX = x < to.x and 1 or -1
|
|
|
|
|
local stepY = y < to.y and 1 or -1
|
|
|
|
|
local err = dx - dy
|
|
|
|
|
|
|
|
|
|
while true do
|
|
|
|
|
if x ~= from.x or y ~= from.y then paintRoomCell({ x = x, y = y }, button) end
|
|
|
|
|
if x == to.x and y == to.y then break end
|
|
|
|
|
local twiceErr = err * 2
|
|
|
|
|
if twiceErr > -dy then err = err - dy; x = x + stepX end
|
|
|
|
|
if twiceErr < dx then err = err + dx; y = y + stepY end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function beginRoomBrush(x, y, button)
|
|
|
|
|
if button ~= 1 and button ~= 2 then return end
|
|
|
|
|
if button == 1 and not selectedAsset then return end
|
|
|
|
|
local cell = roomCellAt(x, y)
|
|
|
|
|
if not cell then return end
|
|
|
|
|
paintRoomCell(cell, button)
|
|
|
|
|
roomBrush = { button = button, lastCell = cell }
|
|
|
|
|
end
|
2026-08-07 09:08:34 -04:00
|
|
|
|
2026-08-11 12:24:54 -04:00
|
|
|
-- ── Room-view sidebar layout ────────────────────────────────────────────────
|
|
|
|
|
-- Declared up here (not next to editorDraw) so editorMouseHandler, defined
|
|
|
|
|
-- earlier in the file, can still capture these as upvalues.
|
|
|
|
|
|
|
|
|
|
-- Which flat list the room view is currently showing (search > folder > roots).
|
|
|
|
|
local function currentRoomList()
|
|
|
|
|
if assetSearchText ~= "" then return assetSearchButtons
|
|
|
|
|
elseif not selectedFolder then return folderButtons
|
|
|
|
|
else return assetListButtons end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Carve the sidebar into fixed, non-overlapping "divs": a search header pinned
|
|
|
|
|
-- to the top, a control cluster pinned to the bottom, a status strip above it,
|
|
|
|
|
-- and a flexible list filling whatever is left. Recomputed every frame so it
|
|
|
|
|
-- tracks window resizes.
|
|
|
|
|
local function roomSections()
|
|
|
|
|
local pad = 10
|
|
|
|
|
local w = math.max(0, sb.w - pad * 2)
|
|
|
|
|
local controlsH = 104
|
|
|
|
|
local statusH = 44
|
|
|
|
|
local search = { x = pad, y = pad, w = w, h = 34 }
|
|
|
|
|
local controls = { x = pad, y = sb.h - pad - controlsH, w = w, h = controlsH }
|
|
|
|
|
local status = { x = pad, y = controls.y - statusH, w = w, h = statusH }
|
|
|
|
|
local listY = search.y + search.h + 8
|
|
|
|
|
local list = { x = pad, y = listY, w = w, h = math.max(0, status.y - 8 - listY) }
|
|
|
|
|
return { search = search, listRect = list, status = status, controls = controls }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Position the bottom control cluster inside its section: level-name field, a
|
|
|
|
|
-- row of colour buttons, then a row of action buttons. Runs for both drawing
|
|
|
|
|
-- and hit-testing so the two never disagree.
|
|
|
|
|
local function layoutRoomControls(c, s)
|
|
|
|
|
local vgap = 4 -- vertical space between rows
|
|
|
|
|
local hgap = 8 -- horizontal space between buttons in a row
|
|
|
|
|
local y = c.y
|
|
|
|
|
|
|
|
|
|
s.labelY = y
|
|
|
|
|
y = y + 15
|
|
|
|
|
|
|
|
|
|
local field = uiButtons.roomName
|
|
|
|
|
if field then field.x = c.x; field.y = y; field.w = c.w; field.h = 22 end
|
|
|
|
|
y = y + 22 + vgap
|
|
|
|
|
|
|
|
|
|
-- Resize a sprite button to a target height in place, so all control sizing
|
|
|
|
|
-- lives here instead of being scattered across the creation calls.
|
|
|
|
|
local function sizeBtn(name, target)
|
|
|
|
|
local b = uiButtons[name]
|
|
|
|
|
if b and b.sprite then
|
|
|
|
|
b.scale = target / b.sprite:getHeight()
|
|
|
|
|
b.w = b.sprite:getWidth() * b.scale
|
|
|
|
|
b.h = b.sprite:getHeight() * b.scale
|
|
|
|
|
end
|
|
|
|
|
return b
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Pack the row centered with a fixed gap, rather than spreading each button
|
|
|
|
|
-- across a full-width slot (which left big gaps between small icons).
|
|
|
|
|
local function placeRow(names, target)
|
|
|
|
|
local btns, total = {}, 0
|
|
|
|
|
for _, name in ipairs(names) do
|
|
|
|
|
local b = sizeBtn(name, target)
|
|
|
|
|
if b then table.insert(btns, b); total = total + b.w end
|
|
|
|
|
end
|
|
|
|
|
total = total + hgap * math.max(0, #btns - 1)
|
|
|
|
|
local x = c.x + (c.w - total) / 2
|
|
|
|
|
for _, b in ipairs(btns) do
|
|
|
|
|
b.x = x
|
|
|
|
|
b.y = y + (target - b.h) / 2
|
|
|
|
|
x = x + b.w + hgap
|
|
|
|
|
end
|
|
|
|
|
y = y + target + vgap
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
placeRow({ "white", "red", "green", "blue" }, 22)
|
|
|
|
|
placeRow({ "save", "clearSaves", "world" }, 28)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Build the full room-view layout (sections + a scroll list + a back/search
|
|
|
|
|
-- header) without drawing. Shared by editorDraw and editorMouseHandler.
|
|
|
|
|
local function buildRoomLayout()
|
|
|
|
|
local s = roomSections()
|
|
|
|
|
|
|
|
|
|
local showBack = assetSearchText ~= "" or selectedFolder
|
|
|
|
|
local sx, sw = s.search.x, s.search.w
|
|
|
|
|
if showBack then
|
|
|
|
|
s.back = { x = s.search.x, y = s.search.y, w = s.search.h, h = s.search.h }
|
|
|
|
|
sx = s.back.x + s.back.w + 6
|
|
|
|
|
sw = s.search.w - s.back.w - 6
|
|
|
|
|
end
|
|
|
|
|
s.searchBox = { x = sx, y = s.search.y, w = sw, h = s.search.h }
|
|
|
|
|
|
|
|
|
|
s.items = currentRoomList()
|
|
|
|
|
s.list = Layout.list(listScroll, s.listRect, 40, #s.items, 2)
|
|
|
|
|
|
|
|
|
|
layoutRoomControls(s.controls, s)
|
|
|
|
|
return s
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Mouse wheel scrolls the room list; clamped by Layout.list next frame.
|
|
|
|
|
function editorScrollRoomList(dy)
|
|
|
|
|
listScroll.scroll = math.max(0, (listScroll.scroll or 0) - dy * 40)
|
|
|
|
|
end
|
|
|
|
|
-- ────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
2026-08-07 09:08:34 -04:00
|
|
|
local function fuzzyMatches(value, query)
|
|
|
|
|
query = (query or ""):lower():gsub("%s+", "")
|
|
|
|
|
if query == "" then return true end
|
|
|
|
|
local index = 1
|
|
|
|
|
for character in value:lower():gmatch(".") do
|
|
|
|
|
if character == query:sub(index, index) then
|
|
|
|
|
index = index + 1
|
|
|
|
|
if index > #query then return true end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function beginSearch(field)
|
|
|
|
|
activeField = field
|
|
|
|
|
inputText = field == "assetSearch" and assetSearchText or worldSearchText
|
|
|
|
|
response = inputText
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function rebuildAssetSearchButtons()
|
|
|
|
|
assetSearchButtons = {}
|
2026-08-11 12:24:54 -04:00
|
|
|
listScroll.scroll = 0
|
2026-08-07 09:08:34 -04:00
|
|
|
if assetSearchText == "" then return end
|
|
|
|
|
local names = {}
|
|
|
|
|
for asset in pairs(gameAssets) do
|
|
|
|
|
if fuzzyMatches(asset, assetSearchText) then table.insert(names, asset) end
|
|
|
|
|
end
|
|
|
|
|
table.sort(names)
|
|
|
|
|
for index, asset in ipairs(names) do
|
|
|
|
|
local sprites = {}
|
|
|
|
|
for color, location in pairs(gameAssets[asset].sprites) do sprites[color] = love.graphics.newImage(location) end
|
|
|
|
|
table.insert(assetSearchButtons, createUIElement{
|
|
|
|
|
sprites = sprites,
|
|
|
|
|
name = "asset",
|
|
|
|
|
text = asset,
|
|
|
|
|
x = 30,
|
|
|
|
|
y = 45 + (index - 1) * 62,
|
|
|
|
|
onClic = { left = function() selectAsset(asset) end }
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
|
|
|
|
|
local function buttonContains(button, x, y)
|
|
|
|
|
return x > button.x and x < button.x + button.w and y > button.y and y < button.y + button.h
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function rebuildWorldRoomButtons()
|
|
|
|
|
worldRoomButtons = {}
|
2026-08-07 09:08:34 -04:00
|
|
|
local names = {}
|
|
|
|
|
for _, name in ipairs(gameWorld:listRoomNames()) do
|
|
|
|
|
if fuzzyMatches(name, worldSearchText) then table.insert(names, name) end
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
local pages = math.max(1, math.ceil(#names / worldPageSize))
|
|
|
|
|
worldPage = constrain(worldPage, 1, pages)
|
|
|
|
|
local first = (worldPage - 1) * worldPageSize + 1
|
|
|
|
|
for index = first, math.min(first + worldPageSize - 1, #names) do
|
|
|
|
|
local roomName = names[index]
|
|
|
|
|
local row = index - first
|
2026-08-11 12:24:54 -04:00
|
|
|
table.insert(worldRoomButtons, { name = roomName, x = 10, y = 70 + row * 68, w = sb.w - 20, h = 60 })
|
2026-08-07 01:39:47 -04:00
|
|
|
end
|
|
|
|
|
worldControls = {
|
2026-08-11 12:24:54 -04:00
|
|
|
{ text = worldMode == "place" and "MODE: PLACE ROOMS" or "MODE: OPEN LEVELS", x = 10, y = sb.h - 194, w = sb.w - 20, h = 34,
|
2026-08-07 01:39:47 -04:00
|
|
|
onClic = function() worldMode = worldMode == "place" and "jump" or "place"; rebuildWorldRoomButtons() end },
|
2026-08-11 12:24:54 -04:00
|
|
|
{ text = "RESEED OLD EXITS", x = 10, y = sb.h - 152, w = sb.w - 20, h = 34,
|
2026-08-07 01:39:47 -04:00
|
|
|
onClic = function()
|
|
|
|
|
local now = love.timer.getTime()
|
|
|
|
|
if now > worldSeedConfirmationExpires then
|
|
|
|
|
worldSeedConfirmationExpires = now + 3
|
|
|
|
|
editorStatus = "Click RESEED OLD EXITS again within 3 seconds to replace the current map."
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
worldSeedConfirmationExpires = 0
|
|
|
|
|
local result = seedWorldFromLegacyExits(gameWorld)
|
|
|
|
|
editorStatus = "Seeded " .. result.placed .. " rooms; " .. result.links .. " legacy links (" .. result.conflicts .. " conflicts kept separate)."
|
|
|
|
|
rebuildWorldRoomButtons()
|
|
|
|
|
end },
|
2026-08-11 12:24:54 -04:00
|
|
|
{ text = "< PAGE " .. worldPage .. "/" .. pages .. " >", x = 10, y = sb.h - 110, w = sb.w - 20, h = 34,
|
2026-08-07 01:39:47 -04:00
|
|
|
onClic = function(buttonX)
|
2026-08-11 12:24:54 -04:00
|
|
|
if buttonX < sb.w / 2 then worldPage = math.max(1, worldPage - 1) else worldPage = math.min(pages, worldPage + 1) end
|
2026-08-07 01:39:47 -04:00
|
|
|
rebuildWorldRoomButtons()
|
|
|
|
|
end },
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function drawWorldSidebar()
|
|
|
|
|
love.graphics.setColor(gColor.white:set())
|
2026-08-11 12:24:54 -04:00
|
|
|
love.graphics.printf("ROOMS — " .. (worldMode == "place" and "select to place; re-click to clear" or "click a map room to open"), 8, 6, sb.w - 16, "center")
|
|
|
|
|
worldSearchBox.w = sb.w - 20
|
2026-08-07 09:08:34 -04:00
|
|
|
love.graphics.rectangle("line", worldSearchBox.x, worldSearchBox.y, worldSearchBox.w, worldSearchBox.h)
|
|
|
|
|
love.graphics.printf("SEARCH: " .. worldSearchText, worldSearchBox.x + 6, worldSearchBox.y + 7, worldSearchBox.w - 12, "left")
|
2026-08-07 01:39:47 -04:00
|
|
|
for _, button in ipairs(worldRoomButtons) do
|
2026-08-07 20:56:42 -04:00
|
|
|
love.graphics.setColor(button.name == selectedRoom and 1 or 100 / 255, button.name == selectedRoom and 1 or 100 / 255, button.name == selectedRoom and 1 or 100 / 255, 1)
|
2026-08-07 01:39:47 -04:00
|
|
|
love.graphics.rectangle("line", button.x, button.y, button.w, button.h)
|
|
|
|
|
gameWorld:drawRoomPreview(button.name, button.x + 4, button.y + 4, button.h - 8)
|
|
|
|
|
love.graphics.setColor(gColor.white:set())
|
|
|
|
|
love.graphics.printf(button.name, button.x + button.h + 4, button.y + 21, button.w - button.h - 8, "left")
|
|
|
|
|
end
|
|
|
|
|
for _, control in ipairs(worldControls) do
|
2026-08-07 20:56:42 -04:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
2026-08-07 01:39:47 -04:00
|
|
|
love.graphics.rectangle("line", control.x, control.y, control.w, control.h)
|
|
|
|
|
love.graphics.printf(control.text, control.x, control.y + 9, control.w, "center")
|
|
|
|
|
end
|
2026-08-11 12:24:54 -04:00
|
|
|
-- Pin the assets/world toggle to a fixed spot here; the room view owns its
|
|
|
|
|
-- position otherwise, so give the world view a stable one of its own.
|
|
|
|
|
uiButtons.world.x = sb.w / 2 - uiButtons.world.w / 2
|
|
|
|
|
uiButtons.world.y = sb.h - uiButtons.world.h - 12
|
2026-08-07 01:39:47 -04:00
|
|
|
uiButtons.world:draw()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function validRoomName(name)
|
|
|
|
|
name = (name or ""):match("^%s*(.-)%s*$")
|
|
|
|
|
if name == "" then return nil, "Enter a level name." end
|
|
|
|
|
if not name:match("^[%w][%w_-]*$") then
|
|
|
|
|
return nil, "Use letters, numbers, _ or - for level names."
|
|
|
|
|
end
|
|
|
|
|
return name
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function beginRoomNameEdit()
|
|
|
|
|
activeField = "roomName"
|
|
|
|
|
inputText = ""
|
|
|
|
|
response = ""
|
|
|
|
|
roomNameField:editText("")
|
|
|
|
|
editorStatus = "Type a name, press Enter, then Save."
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function saveRoomFromEditor()
|
|
|
|
|
local requestedName = editorRoomName or currentRoom.name
|
|
|
|
|
if activeField == "roomName" then requestedName = inputText end
|
|
|
|
|
local name, err = validRoomName(requestedName)
|
|
|
|
|
if not name then
|
|
|
|
|
editorStatus = err
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local oldName = currentRoom.name
|
|
|
|
|
if name ~= oldName and readFromSource("rooms/" .. name .. ".sav") then
|
|
|
|
|
editorStatus = "A source level named '" .. name .. "' already exists."
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2026-08-07 03:22:28 -04:00
|
|
|
local savePlayerPositions = love.keyboard.isDown("lshift", "rshift")
|
|
|
|
|
if not currentRoom:saveToSource(name, savePlayerPositions, oldName) then
|
2026-08-07 01:39:47 -04:00
|
|
|
editorStatus = "Could not save '" .. name .. "'."
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- A changed name is a rename, not an accidental duplicate. Do this only
|
|
|
|
|
-- after the new source file is safely written.
|
|
|
|
|
if oldName and oldName ~= name then
|
|
|
|
|
removeFromSource("rooms/" .. oldName .. ".sav")
|
|
|
|
|
gameWorld:renameRoom(oldName, name)
|
|
|
|
|
end
|
|
|
|
|
gameWorld:invalidatePreview(name)
|
|
|
|
|
if editorView == "world" then rebuildWorldRoomButtons() end
|
|
|
|
|
currentRoom.name = name
|
|
|
|
|
editorRoomName = name
|
|
|
|
|
roomNameField:editText(name)
|
|
|
|
|
activeField = nil
|
2026-08-07 03:22:28 -04:00
|
|
|
editorStatus = "Saved source level '" .. name .. "'" .. (savePlayerPositions and " with player positions." or ".")
|
2026-08-07 01:39:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function clearRuntimeSaves()
|
|
|
|
|
local now = love.timer.getTime()
|
2026-08-07 03:22:28 -04:00
|
|
|
local clearAll = love.keyboard.isDown("lshift", "rshift")
|
|
|
|
|
local roomName = currentRoom.name
|
|
|
|
|
local scope = clearAll and "all" or roomName
|
|
|
|
|
if now > clearSaveConfirmationExpires or clearSaveConfirmationScope ~= scope then
|
2026-08-07 01:39:47 -04:00
|
|
|
clearSaveConfirmationExpires = now + 3
|
2026-08-07 03:22:28 -04:00
|
|
|
clearSaveConfirmationScope = scope
|
|
|
|
|
if clearAll then
|
|
|
|
|
editorStatus = "Shift-click the clear-save icon again within 3 seconds to erase runtime saves for every room."
|
|
|
|
|
else
|
|
|
|
|
editorStatus = "Click the clear-save icon again within 3 seconds to erase the runtime save for '" .. (roomName or "this room") .. "'."
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2026-08-07 03:22:28 -04:00
|
|
|
local removed = clearRuntimeSaveData(clearAll and nil or roomName)
|
2026-08-07 01:39:47 -04:00
|
|
|
clearSaveConfirmationExpires = 0
|
2026-08-07 03:22:28 -04:00
|
|
|
clearSaveConfirmationScope = nil
|
2026-08-07 01:39:47 -04:00
|
|
|
if roomName then
|
|
|
|
|
currentRoom = Room:new{ name = roomName }
|
|
|
|
|
setEditorRoomName(currentRoom.name)
|
|
|
|
|
editorStatus = "Cleared " .. removed .. " runtime save item(s) and reloaded '" .. roomName .. ".'"
|
|
|
|
|
else
|
|
|
|
|
editorStatus = "Cleared " .. removed .. " runtime save item(s). No named level to reload."
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
function _initLevelEditor()
|
2015-03-25 04:22:10 -04:00
|
|
|
gameAssets = getAllAssets()
|
2026-08-07 01:39:47 -04:00
|
|
|
editorRoomName = ""
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
--create folder buttons
|
|
|
|
|
local counter = 1
|
2015-03-25 03:58:37 -04:00
|
|
|
|
|
|
|
|
for asset, attributes in pairs(gameAssets) do
|
|
|
|
|
if not hierarchy[gameAssets[asset].directory] then
|
|
|
|
|
hierarchy[gameAssets[asset].directory] = {}
|
|
|
|
|
end
|
|
|
|
|
table.insert(hierarchy[gameAssets[asset].directory], asset)
|
|
|
|
|
end
|
|
|
|
|
|
2026-08-07 09:08:34 -04:00
|
|
|
local folders = {}
|
|
|
|
|
for folder in pairs(hierarchy) do table.insert(folders, folder) end
|
|
|
|
|
table.sort(folders)
|
|
|
|
|
for _, folder in ipairs(folders) do
|
2015-03-25 01:38:53 -04:00
|
|
|
local button = createUIElement{
|
|
|
|
|
name = "folder",
|
|
|
|
|
text = folder,
|
|
|
|
|
x = 30,
|
2026-08-11 12:24:54 -04:00
|
|
|
y = (sb.h - 50) * (counter / 15),
|
2015-03-25 01:38:53 -04:00
|
|
|
sprite = folderSprite,
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function(self)
|
|
|
|
|
print("my asse")
|
|
|
|
|
selectFolder(folder)
|
|
|
|
|
end,
|
|
|
|
|
right = function()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
counter = counter + 1
|
|
|
|
|
table.insert(folderButtons, button)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
_addUIButton(createUIElement{
|
|
|
|
|
name = "save",
|
|
|
|
|
sprite = love.graphics.newImage("art/_ui/save.png"),
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function()
|
|
|
|
|
if editorView == "room" then
|
2026-08-07 01:39:47 -04:00
|
|
|
saveRoomFromEditor()
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
right = function()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
},
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w / 4,
|
|
|
|
|
y = sb.h * (9 / 10)
|
|
|
|
|
}, "save")
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
_addUIButton(createUIElement{
|
|
|
|
|
name = "world",
|
|
|
|
|
sprite = love.graphics.newImage("art/_ui/world.png"),
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function()
|
2026-08-07 01:39:47 -04:00
|
|
|
if editorView == "world" then assetsView() else worldView() end
|
2015-03-25 01:38:53 -04:00
|
|
|
end,
|
|
|
|
|
right = function()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
},
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w * (3 / 4),
|
|
|
|
|
y = sb.h * (9 / 10)
|
2026-08-07 01:39:47 -04:00
|
|
|
}, "world")
|
|
|
|
|
|
|
|
|
|
_addUIButton(createUIElement{
|
|
|
|
|
name = "clearSaves",
|
|
|
|
|
sprite = clearSavesSprite,
|
|
|
|
|
onClic = {
|
|
|
|
|
left = clearRuntimeSaves,
|
|
|
|
|
},
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w / 2,
|
|
|
|
|
y = sb.h * (9 / 10),
|
|
|
|
|
scale = editorScale / 3
|
|
|
|
|
}, "clearSaves")
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
for _, color in ipairs({"white", "red", "green", "blue"}) do
|
|
|
|
|
_addUIButton(createUIElement{
|
|
|
|
|
name = color,
|
|
|
|
|
sprite = love.graphics.newImage("art/_ui/" .. color .. ".png"),
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function(self)
|
|
|
|
|
if editorView == "room" then
|
|
|
|
|
setSelectedColor(color)
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
right = function()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
},
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w * (_ / 5),
|
|
|
|
|
y = sb.h * (8 / 10)
|
|
|
|
|
}, color)
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
2026-08-07 01:39:47 -04:00
|
|
|
roomNameField = createUIElement{
|
|
|
|
|
name = "roomName",
|
|
|
|
|
text = editorRoomName,
|
|
|
|
|
x = 25,
|
2026-08-11 12:24:54 -04:00
|
|
|
y = sb.h * (7 / 10),
|
2026-08-07 01:39:47 -04:00
|
|
|
onClic = {
|
|
|
|
|
left = beginRoomNameEdit,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_addUIButton(roomNameField, "roomName")
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function setEditorRoomName(name)
|
|
|
|
|
editorRoomName = name or ""
|
|
|
|
|
if roomNameField then roomNameField:editText(editorRoomName) end
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function setSelectedColor(color)
|
|
|
|
|
selectedColor = color
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function selectFolder(folder)
|
|
|
|
|
selectedFolder = folder
|
2026-08-11 12:24:54 -04:00
|
|
|
listScroll.scroll = 0
|
|
|
|
|
assetListButtons = {}
|
2015-03-25 01:38:53 -04:00
|
|
|
|
2026-08-07 09:08:34 -04:00
|
|
|
table.sort(hierarchy[selectedFolder])
|
|
|
|
|
for _, asset in ipairs(hierarchy[selectedFolder]) do
|
2015-03-25 01:38:53 -04:00
|
|
|
local sprites = {}
|
2015-03-25 03:58:37 -04:00
|
|
|
for color, location in pairs(gameAssets[asset].sprites) do
|
2015-03-25 01:38:53 -04:00
|
|
|
sprites[color] = love.graphics.newImage(location)
|
|
|
|
|
end
|
|
|
|
|
|
2026-08-11 12:24:54 -04:00
|
|
|
-- x/y are placeholders; the room-view layout repositions every item
|
|
|
|
|
-- each frame from the list section (see buildRoomLayout).
|
|
|
|
|
table.insert(assetListButtons, createUIElement{
|
2015-03-25 01:38:53 -04:00
|
|
|
sprites = sprites,
|
|
|
|
|
name = "asset",
|
|
|
|
|
text = asset,
|
|
|
|
|
x = 30,
|
2026-08-11 12:24:54 -04:00
|
|
|
y = 0,
|
2015-03-25 01:38:53 -04:00
|
|
|
onClic = {
|
2026-08-11 12:24:54 -04:00
|
|
|
left = function() selectAsset(asset) end,
|
|
|
|
|
right = function() editAsset(asset) end,
|
2015-03-25 01:38:53 -04:00
|
|
|
}
|
2026-08-11 12:24:54 -04:00
|
|
|
})
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function selectAsset(asset)
|
|
|
|
|
print("selecting", asset)
|
|
|
|
|
selectedAsset = asset
|
|
|
|
|
print(selectedAsset)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function editAsset(asset)
|
|
|
|
|
inputText = ""
|
|
|
|
|
editorView = "asset"
|
|
|
|
|
selectedAsset = asset
|
|
|
|
|
|
2015-03-25 03:58:37 -04:00
|
|
|
assetProperties = gameAssets[selectedAsset]
|
|
|
|
|
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
local cancelButton = createUIElement{
|
|
|
|
|
name = "cancel",
|
|
|
|
|
sprite = cancelSprite,
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w / 3,
|
|
|
|
|
y = sb.h - 75,
|
2015-03-25 01:38:53 -04:00
|
|
|
onClic = {
|
|
|
|
|
left = function(self)
|
|
|
|
|
assetsView()
|
|
|
|
|
end,
|
|
|
|
|
right = function(self) return end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local confirmButton = createUIElement{
|
|
|
|
|
name = "confirm",
|
|
|
|
|
sprite = confirmSprite,
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w * 2 / 3,
|
|
|
|
|
y = sb.h - 75,
|
2015-03-25 01:38:53 -04:00
|
|
|
onClic = {
|
|
|
|
|
left = function(self)
|
|
|
|
|
saveAsset()
|
|
|
|
|
end,
|
|
|
|
|
right = function(self) return end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editingAssetButtons[cancelButton] = cancelButton
|
|
|
|
|
editingAssetButtons[confirmButton] = confirmButton
|
|
|
|
|
|
|
|
|
|
local assetSprites = {}
|
2015-03-25 03:58:37 -04:00
|
|
|
for color, path in pairs(assetProperties.sprites) do
|
2015-03-25 01:38:53 -04:00
|
|
|
assetSprites[color] = love.graphics.newImage(path)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local assetButton = createUIElement{
|
|
|
|
|
name = asset,
|
|
|
|
|
sprites = assetSprites,
|
2026-08-11 12:24:54 -04:00
|
|
|
x = sb.w / 2 - 18,
|
2015-03-25 01:38:53 -04:00
|
|
|
y = 80,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local classFieldLabel = {
|
2026-08-11 12:24:54 -04:00
|
|
|
draw = function() love.graphics.printf("CLASS", 0, 125, sb.w, "center") end
|
2015-03-25 01:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labels[classFieldLabel] = classFieldLabel
|
|
|
|
|
|
|
|
|
|
local classButton = createUIElement{
|
|
|
|
|
name = "class",
|
|
|
|
|
text = assetProperties.class or "",
|
|
|
|
|
x = 25,
|
|
|
|
|
y = 150,
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function()
|
|
|
|
|
activeField = "class"
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 03:58:37 -04:00
|
|
|
local preloadLabel = {
|
2026-08-11 12:24:54 -04:00
|
|
|
draw = function() love.graphics.printf("preload", 0, 225, sb.w, "center") end
|
2015-03-25 03:58:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labels[preloadLabel] = preloadLabel
|
|
|
|
|
|
|
|
|
|
local preloadButton = createUIElement{
|
|
|
|
|
name = "preload",
|
|
|
|
|
text = tostring(assetProperties.preload),
|
|
|
|
|
x = 25,
|
|
|
|
|
y = 250,
|
|
|
|
|
onClic = {
|
|
|
|
|
left = function()
|
|
|
|
|
assetProperties.preload = not assetProperties.preload
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 01:38:53 -04:00
|
|
|
editingAssetButtons[assetButton] = assetButton
|
|
|
|
|
editingAssetButtons.class = classButton
|
2015-03-25 03:58:37 -04:00
|
|
|
editingAssetButtons.preload = preloadButton
|
|
|
|
|
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function saveAsset()
|
2015-03-25 03:58:37 -04:00
|
|
|
gameAssets[selectedAsset] = assetProperties
|
2026-08-07 00:56:33 -04:00
|
|
|
-- the asset's class lives in its .meta next to the art (source of truth,
|
|
|
|
|
-- read back by getAllAssets); write it there
|
|
|
|
|
local metaPath = "art/" .. assetProperties.directory .. "/" .. selectedAsset .. ".meta"
|
|
|
|
|
writeToSource(metaPath, TSerial.pack({ class = assetProperties.class }, nil, true))
|
2015-03-25 01:38:53 -04:00
|
|
|
assetsView()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _addUIButton(button, name)
|
|
|
|
|
local index = name or button
|
|
|
|
|
uiButtons[index] = button
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function folderView()
|
|
|
|
|
selectedFolder = nil
|
2026-08-11 12:24:54 -04:00
|
|
|
assetListButtons = {}
|
|
|
|
|
listScroll.scroll = 0
|
2015-03-25 01:38:53 -04:00
|
|
|
labels = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function assetsView()
|
|
|
|
|
editingAssetButtons = {}
|
|
|
|
|
editorView = "room"
|
|
|
|
|
labels = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function worldView()
|
2026-08-07 01:39:47 -04:00
|
|
|
editorView = "world"
|
|
|
|
|
activeField = nil
|
|
|
|
|
selectedFolder = nil
|
|
|
|
|
worldMode = "place"
|
|
|
|
|
worldPage = 1
|
|
|
|
|
rebuildWorldRoomButtons()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function newWorldRoomName(cellX, cellY)
|
|
|
|
|
local base = string.format("room_%02d_%02d", cellX, cellY)
|
|
|
|
|
local name, suffix = base, 2
|
|
|
|
|
while gameWorld:roomLocation(name) or readFromSource("rooms/" .. name .. ".sav") do
|
|
|
|
|
name = base .. "_" .. suffix
|
|
|
|
|
suffix = suffix + 1
|
|
|
|
|
end
|
|
|
|
|
return name
|
|
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
|
2026-08-07 01:39:47 -04:00
|
|
|
local function openWorldRoom(cellX, cellY)
|
|
|
|
|
local name = gameWorld:roomAt(cellX, cellY)
|
|
|
|
|
if not name then
|
|
|
|
|
name = newWorldRoomName(cellX, cellY)
|
|
|
|
|
currentRoom = Room:new{ name = name }
|
|
|
|
|
-- Creating from an empty cell is a real level creation, not merely a
|
|
|
|
|
-- transient map reference, so it immediately joins the room picker.
|
|
|
|
|
currentRoom:saveToSource(name)
|
|
|
|
|
gameWorld:placeRoom(name, cellX, cellY)
|
|
|
|
|
gameWorld:invalidatePreview(name)
|
|
|
|
|
editorStatus = "Created and opened '" .. name .. ".'"
|
|
|
|
|
else
|
|
|
|
|
currentRoom = Room:new{ name = name }
|
|
|
|
|
editorStatus = "Editing '" .. name .. ".'"
|
|
|
|
|
end
|
2026-08-07 03:22:28 -04:00
|
|
|
gameWorld:setLastRoom(currentRoom.name)
|
2026-08-07 01:39:47 -04:00
|
|
|
setEditorRoomName(currentRoom.name)
|
|
|
|
|
assetsView()
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function editorMouseHandler(x, y, button)
|
|
|
|
|
if x > width then
|
2026-08-11 12:24:54 -04:00
|
|
|
-- map from real window coords into the sidebar's fixed virtual space
|
|
|
|
|
-- (same transform used to scale the sidebar canvas up in love.draw)
|
|
|
|
|
x = (x - width) * sb.w / sideBarBox.w
|
|
|
|
|
y = y * sb.h / sideBarBox.h
|
2015-03-25 01:38:53 -04:00
|
|
|
|
|
|
|
|
if editorView == "room" then
|
2026-08-11 12:24:54 -04:00
|
|
|
local s = buildRoomLayout()
|
|
|
|
|
|
|
|
|
|
-- back button: drop the search, else leave the folder
|
|
|
|
|
if s.back and Layout.hit(s.back, x, y) then
|
|
|
|
|
if assetSearchText ~= "" then
|
|
|
|
|
assetSearchText = ""
|
|
|
|
|
inputText = ""
|
|
|
|
|
activeField = nil
|
|
|
|
|
rebuildAssetSearchButtons()
|
|
|
|
|
elseif selectedFolder then
|
|
|
|
|
folderView()
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if Layout.hit(s.searchBox, x, y) then
|
2026-08-07 09:08:34 -04:00
|
|
|
beginSearch("assetSearch")
|
|
|
|
|
return
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
2026-08-11 12:24:54 -04:00
|
|
|
-- scrolling list item
|
|
|
|
|
local i = s.list.at(x, y)
|
|
|
|
|
if i and s.items[i] then
|
|
|
|
|
s.items[i]:onClic(button)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- control cluster (only the buttons that live there)
|
|
|
|
|
for _, name in ipairs({ "roomName", "white", "red", "green", "blue", "save", "clearSaves", "world" }) do
|
|
|
|
|
local b = uiButtons[name]
|
|
|
|
|
if b and b:clicIsInBox(x, y) then
|
|
|
|
|
b:onClic(button)
|
|
|
|
|
return
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif editorView == "asset" then
|
|
|
|
|
for _, uiElement in pairs(editingAssetButtons) do
|
|
|
|
|
if uiElement:clicIsInBox(x, y) then
|
|
|
|
|
uiElement:onClic(button)
|
|
|
|
|
end
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
elseif editorView == "world" then
|
2026-08-07 09:08:34 -04:00
|
|
|
if buttonContains(worldSearchBox, x, y) then
|
|
|
|
|
beginSearch("worldSearch")
|
|
|
|
|
return
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
for _, roomButton in ipairs(worldRoomButtons) do
|
|
|
|
|
if buttonContains(roomButton, x, y) then
|
|
|
|
|
if selectedRoom == roomButton.name then
|
|
|
|
|
selectedRoom = nil
|
|
|
|
|
editorStatus = "Room brush cleared. Click the map to open or create a level."
|
|
|
|
|
else
|
|
|
|
|
selectedRoom = roomButton.name
|
|
|
|
|
editorStatus = "Selected '" .. selectedRoom .. "' for placement. Click it again to clear."
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for _, control in ipairs(worldControls) do
|
|
|
|
|
if buttonContains(control, x, y) then
|
2026-08-07 09:08:34 -04:00
|
|
|
control.onClic(x)
|
2026-08-07 01:39:47 -04:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if uiButtons.world:clicIsInBox(x, y) then uiButtons.world:onClic(button) end
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
2026-08-06 23:54:49 -04:00
|
|
|
else
|
|
|
|
|
-- click landed on the grid (game area): place the selected asset
|
2026-08-11 14:11:57 -04:00
|
|
|
if editorView == "room" then
|
|
|
|
|
beginRoomBrush(x, y, button)
|
2026-08-07 01:39:47 -04:00
|
|
|
elseif editorView == "world" then
|
|
|
|
|
local cellX, cellY = gameWorld:getCellFromMousePos(x, y)
|
|
|
|
|
if not gameWorld:isInBounds(cellX, cellY) then return end
|
|
|
|
|
if button == 2 then
|
|
|
|
|
local removed, name = gameWorld:removeRoom(cellX, cellY)
|
|
|
|
|
if removed then editorStatus = "Removed '" .. name .. "' from the world." end
|
|
|
|
|
elseif worldMode == "jump" or not selectedRoom then
|
|
|
|
|
openWorldRoom(cellX, cellY)
|
|
|
|
|
elseif selectedRoom then
|
|
|
|
|
gameWorld:placeRoom(selectedRoom, cellX, cellY)
|
|
|
|
|
editorStatus = "Placed '" .. selectedRoom .. "' at " .. cellX .. ", " .. cellY .. "."
|
|
|
|
|
end
|
2026-08-06 23:54:49 -04:00
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-08-11 14:11:57 -04:00
|
|
|
function editorMouseMoved(x, y)
|
|
|
|
|
if not roomBrush then return end
|
|
|
|
|
if editorView ~= "room" then
|
|
|
|
|
roomBrush = nil
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cell = roomCellAt(x, y)
|
|
|
|
|
if not cell then
|
|
|
|
|
-- Leaving the grid ends this stroke; re-entering should not draw a line
|
|
|
|
|
-- across the sidebar or outside of the level.
|
|
|
|
|
roomBrush = nil
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if cell.x == roomBrush.lastCell.x and cell.y == roomBrush.lastCell.y then return end
|
|
|
|
|
|
|
|
|
|
paintRoomLine(roomBrush.lastCell, cell, roomBrush.button)
|
|
|
|
|
roomBrush.lastCell = cell
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function editorMouseReleased(_, _, button)
|
|
|
|
|
if roomBrush and roomBrush.button == button then roomBrush = nil end
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-25 01:38:53 -04:00
|
|
|
function editorTextHandler(text)
|
|
|
|
|
if editorView == "asset" and activeField then
|
|
|
|
|
inputText = text
|
|
|
|
|
editingAssetButtons[activeField]:editText(text)
|
2026-08-07 01:39:47 -04:00
|
|
|
elseif editorView == "room" and activeField == "roomName" then
|
|
|
|
|
inputText = text
|
|
|
|
|
roomNameField:editText(text)
|
2026-08-07 09:08:34 -04:00
|
|
|
elseif editorView == "room" and activeField == "assetSearch" then
|
|
|
|
|
inputText = text
|
|
|
|
|
assetSearchText = text
|
|
|
|
|
rebuildAssetSearchButtons()
|
|
|
|
|
elseif editorView == "world" and activeField == "worldSearch" then
|
|
|
|
|
inputText = text
|
|
|
|
|
worldSearchText = text
|
|
|
|
|
worldPage = 1
|
|
|
|
|
rebuildWorldRoomButtons()
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function editorCompleteResponse()
|
2026-08-07 01:39:47 -04:00
|
|
|
if editorView == "asset" and activeField then
|
2015-03-25 01:38:53 -04:00
|
|
|
assetProperties[activeField] = inputText
|
2026-08-07 01:39:47 -04:00
|
|
|
elseif editorView == "room" and activeField == "roomName" then
|
|
|
|
|
editorRoomName = inputText
|
2026-08-07 09:08:34 -04:00
|
|
|
elseif editorView == "room" and activeField == "assetSearch" then
|
|
|
|
|
assetSearchText = inputText
|
|
|
|
|
elseif editorView == "world" and activeField == "worldSearch" then
|
|
|
|
|
worldSearchText = inputText
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
activeField = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function sortAllAssets()
|
|
|
|
|
setAll()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function createUIElement(t)
|
|
|
|
|
return GUI:new(t)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function editorDraw()
|
|
|
|
|
if editorView == "room" then
|
2026-08-11 12:24:54 -04:00
|
|
|
local s = buildRoomLayout()
|
2026-08-07 09:08:34 -04:00
|
|
|
love.graphics.setColor(gColor.white:set())
|
2026-08-11 12:24:54 -04:00
|
|
|
|
|
|
|
|
-- header: optional back button + search box
|
|
|
|
|
if s.back then
|
|
|
|
|
love.graphics.rectangle("line", s.back.x, s.back.y, s.back.w, s.back.h)
|
|
|
|
|
local sc = (s.back.h - 8) / bacSprite:getHeight()
|
|
|
|
|
love.graphics.draw(bacSprite, s.back.x + 4, s.back.y + 4, 0, sc, sc)
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
2026-08-11 12:24:54 -04:00
|
|
|
love.graphics.rectangle("line", s.searchBox.x, s.searchBox.y, s.searchBox.w, s.searchBox.h)
|
|
|
|
|
love.graphics.printf("SEARCH: " .. assetSearchText, s.searchBox.x + 6, s.searchBox.y + 9, s.searchBox.w - 12, "left")
|
|
|
|
|
|
|
|
|
|
-- scrolling list, clipped to its section so nothing bleeds into others
|
|
|
|
|
Layout.clip(s.listRect)
|
|
|
|
|
for i, item in ipairs(s.items) do
|
|
|
|
|
if s.list.visible(i) then
|
|
|
|
|
item.x, item.y = s.list.pos(i)
|
|
|
|
|
item.w = s.listRect.w
|
|
|
|
|
item:draw()
|
2026-08-11 14:11:57 -04:00
|
|
|
if item.name == "asset" and item.text == selectedAsset then
|
|
|
|
|
love.graphics.setColor(1, 0.85, 0.2, 1)
|
|
|
|
|
love.graphics.setLineWidth(3)
|
|
|
|
|
love.graphics.rectangle("line", item.x + 1, item.y + 1, item.w - 2, item.h - 2)
|
|
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
end
|
2026-08-11 12:24:54 -04:00
|
|
|
Layout.unclip()
|
|
|
|
|
Layout.scrollbar(s.list)
|
|
|
|
|
|
|
|
|
|
-- control cluster
|
|
|
|
|
love.graphics.setColor(gColor.white:set())
|
|
|
|
|
love.graphics.printf("LEVEL NAME", s.controls.x, s.labelY, s.controls.w, "center")
|
|
|
|
|
for _, name in ipairs({ "roomName", "white", "red", "green", "blue", "save", "clearSaves", "world" }) do
|
|
|
|
|
if uiButtons[name] then uiButtons[name]:draw() end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- status strip between the list and the controls
|
|
|
|
|
if editorStatus then
|
|
|
|
|
Layout.clip(s.status)
|
|
|
|
|
love.graphics.setColor(gColor.white:set())
|
|
|
|
|
love.graphics.printf(editorStatus, s.status.x, s.status.y + 4, s.status.w, "center")
|
|
|
|
|
Layout.unclip()
|
|
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
elseif editorView == "asset" then
|
|
|
|
|
for _, button in pairs(editingAssetButtons) do
|
|
|
|
|
button:draw()
|
|
|
|
|
end
|
2026-08-07 01:39:47 -04:00
|
|
|
elseif editorView == "world" then
|
|
|
|
|
drawWorldSidebar()
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for _, label in pairs(labels) do
|
|
|
|
|
label:draw()
|
|
|
|
|
end
|
2026-08-11 12:24:54 -04:00
|
|
|
-- The room view draws its status inside its own strip (see the room branch);
|
|
|
|
|
-- the other views keep the simple centered line.
|
|
|
|
|
if editorStatus and editorView ~= "room" then
|
2026-08-07 01:39:47 -04:00
|
|
|
love.graphics.setColor(gColor.white:set())
|
2026-08-11 12:24:54 -04:00
|
|
|
love.graphics.printf(editorStatus, 10, sb.h * (6 / 10), sb.w - 20, "center")
|
2026-08-07 01:39:47 -04:00
|
|
|
end
|
2015-03-25 01:38:53 -04:00
|
|
|
end
|