idk even anymore
This commit is contained in:
parent
7fa9171ba1
commit
febaaaacc7
13 changed files with 2239 additions and 1508 deletions
|
|
@ -9,6 +9,7 @@ local forwardSprite = love.graphics.newImage("art/_ui/forward.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")
|
||||
local clearSavesSprite = love.graphics.newImage("art/_ui/clear_saves.png")
|
||||
|
||||
local selectedFolder = nil
|
||||
local selectedAsset = nil
|
||||
|
|
@ -28,10 +29,150 @@ local assetButtons = { {} } --table for rows so we can do stuff
|
|||
local editingAssetButtons = {}
|
||||
|
||||
local labels = {}
|
||||
local editorRoomName = nil
|
||||
local roomNameField = nil
|
||||
local editorStatus = nil
|
||||
local clearSaveConfirmationExpires = 0
|
||||
local worldSeedConfirmationExpires = 0
|
||||
local worldMode = "place"
|
||||
local worldRoomButtons = {}
|
||||
local worldControls = {}
|
||||
local worldPage = 1
|
||||
local worldPageSize = 5
|
||||
|
||||
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 = {}
|
||||
local names = gameWorld:listRoomNames()
|
||||
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
|
||||
table.insert(worldRoomButtons, { name = roomName, x = 10, y = 36 + row * 68, w = sideBarBox.w - 20, h = 60 })
|
||||
end
|
||||
worldControls = {
|
||||
{ text = worldMode == "place" and "MODE: PLACE ROOMS" or "MODE: OPEN LEVELS", x = 10, y = sideBarBox.h - 194, w = sideBarBox.w - 20, h = 34,
|
||||
onClic = function() worldMode = worldMode == "place" and "jump" or "place"; rebuildWorldRoomButtons() end },
|
||||
{ text = "RESEED OLD EXITS", x = 10, y = sideBarBox.h - 152, w = sideBarBox.w - 20, h = 34,
|
||||
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 },
|
||||
{ text = "< PAGE " .. worldPage .. "/" .. pages .. " >", x = 10, y = sideBarBox.h - 110, w = sideBarBox.w - 20, h = 34,
|
||||
onClic = function(buttonX)
|
||||
if buttonX < sideBarBox.w / 2 then worldPage = math.max(1, worldPage - 1) else worldPage = math.min(pages, worldPage + 1) end
|
||||
rebuildWorldRoomButtons()
|
||||
end },
|
||||
}
|
||||
end
|
||||
|
||||
local function drawWorldSidebar()
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
love.graphics.printf("ROOMS — " .. (worldMode == "place" and "select to place; re-click to clear" or "click a map room to open"), 8, 10, sideBarBox.w - 16, "center")
|
||||
for _, button in ipairs(worldRoomButtons) do
|
||||
love.graphics.setColor(button.name == selectedRoom and 255 or 100, button.name == selectedRoom and 255 or 100, button.name == selectedRoom and 255 or 100, 255)
|
||||
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
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
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
|
||||
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
|
||||
|
||||
if not currentRoom:saveToSource(name) then
|
||||
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
|
||||
editorStatus = "Saved source level '" .. name .. ".'"
|
||||
end
|
||||
|
||||
local function clearRuntimeSaves()
|
||||
local now = love.timer.getTime()
|
||||
if now > clearSaveConfirmationExpires then
|
||||
clearSaveConfirmationExpires = now + 3
|
||||
editorStatus = "Click the clear-save icon again within 3 seconds to erase runtime saves."
|
||||
return
|
||||
end
|
||||
|
||||
local removed = clearRuntimeSaveData()
|
||||
clearSaveConfirmationExpires = 0
|
||||
local roomName = currentRoom.name
|
||||
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
|
||||
|
||||
|
||||
function _initLevelEditor()
|
||||
gameAssets = getAllAssets()
|
||||
editorRoomName = ""
|
||||
|
||||
--create folder buttons
|
||||
local counter = 1
|
||||
|
|
@ -70,8 +211,7 @@ function _initLevelEditor()
|
|||
onClic = {
|
||||
left = function()
|
||||
if editorView == "room" then
|
||||
print("saveing!!")
|
||||
currentRoom:save()
|
||||
saveRoomFromEditor()
|
||||
end
|
||||
end,
|
||||
right = function()
|
||||
|
|
@ -87,11 +227,7 @@ function _initLevelEditor()
|
|||
sprite = love.graphics.newImage("art/_ui/world.png"),
|
||||
onClic = {
|
||||
left = function()
|
||||
print(editorView)
|
||||
if editorView == "room" then
|
||||
print("saveing!!")
|
||||
currentRoom:save()
|
||||
end
|
||||
if editorView == "world" then assetsView() else worldView() end
|
||||
end,
|
||||
right = function()
|
||||
|
||||
|
|
@ -99,6 +235,17 @@ function _initLevelEditor()
|
|||
},
|
||||
x = sideBarBox.w * (3 / 4),
|
||||
y = sideBarBox.h * (9 / 10)
|
||||
}, "world")
|
||||
|
||||
_addUIButton(createUIElement{
|
||||
name = "clearSaves",
|
||||
sprite = clearSavesSprite,
|
||||
onClic = {
|
||||
left = clearRuntimeSaves,
|
||||
},
|
||||
x = sideBarBox.w / 2,
|
||||
y = sideBarBox.h * (9 / 10),
|
||||
scale = drawScale / 3
|
||||
})
|
||||
|
||||
for _, color in ipairs({"white", "red", "green", "blue"}) do
|
||||
|
|
@ -120,6 +267,22 @@ function _initLevelEditor()
|
|||
})
|
||||
end
|
||||
|
||||
roomNameField = createUIElement{
|
||||
name = "roomName",
|
||||
text = editorRoomName,
|
||||
x = 25,
|
||||
y = sideBarBox.h * (7 / 10),
|
||||
onClic = {
|
||||
left = beginRoomNameEdit,
|
||||
}
|
||||
}
|
||||
_addUIButton(roomNameField, "roomName")
|
||||
|
||||
end
|
||||
|
||||
function setEditorRoomName(name)
|
||||
editorRoomName = name or ""
|
||||
if roomNameField then roomNameField:editText(editorRoomName) end
|
||||
end
|
||||
|
||||
function setSelectedColor(color)
|
||||
|
|
@ -325,7 +488,41 @@ function assetsView()
|
|||
end
|
||||
|
||||
function worldView()
|
||||
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
|
||||
|
||||
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
|
||||
setEditorRoomName(currentRoom.name)
|
||||
assetsView()
|
||||
end
|
||||
|
||||
function editorMouseHandler(x, y, button)
|
||||
|
|
@ -361,11 +558,43 @@ function editorMouseHandler(x, y, button)
|
|||
uiElement:onClic(button)
|
||||
end
|
||||
end
|
||||
elseif editorView == "world" then
|
||||
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
|
||||
control:onClic(x)
|
||||
return
|
||||
end
|
||||
end
|
||||
if uiButtons.world:clicIsInBox(x, y) then uiButtons.world:onClic(button) end
|
||||
end
|
||||
else
|
||||
-- click landed on the grid (game area): place the selected asset
|
||||
if editorView == "room" and button == 1 and selectedAsset then
|
||||
currentRoom:attemptPlace(selectedAsset, gameAssets[selectedAsset], x, y, selectedColor)
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -374,15 +603,18 @@ function editorTextHandler(text)
|
|||
if editorView == "asset" and activeField then
|
||||
inputText = text
|
||||
editingAssetButtons[activeField]:editText(text)
|
||||
elseif editorView == "room" and activeField == "roomName" then
|
||||
inputText = text
|
||||
roomNameField:editText(text)
|
||||
end
|
||||
end
|
||||
|
||||
function editorCompleteResponse()
|
||||
if editorView == "asset" then
|
||||
if editorView == "asset" and activeField then
|
||||
assetProperties[activeField] = inputText
|
||||
print(assetProperties[activeField], "BLELERLLLRLRLRR")
|
||||
elseif editorView == "room" and activeField == "roomName" then
|
||||
editorRoomName = inputText
|
||||
end
|
||||
print(activeField, assetProperties[activeField], "ass")
|
||||
activeField = nil
|
||||
end
|
||||
|
||||
|
|
@ -396,6 +628,8 @@ end
|
|||
|
||||
function editorDraw()
|
||||
if editorView == "room" then
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
love.graphics.printf("LEVEL NAME", 0, sideBarBox.h * (7 / 10) - 24, sideBarBox.w, "center")
|
||||
for _, button in pairs(uiButtons) do
|
||||
button:draw()
|
||||
end
|
||||
|
|
@ -412,9 +646,15 @@ function editorDraw()
|
|||
for _, button in pairs(editingAssetButtons) do
|
||||
button:draw()
|
||||
end
|
||||
elseif editorView == "world" then
|
||||
drawWorldSidebar()
|
||||
end
|
||||
|
||||
for _, label in pairs(labels) do
|
||||
label:draw()
|
||||
end
|
||||
if editorStatus then
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
love.graphics.printf(editorStatus, 10, sideBarBox.h * (6 / 10), sideBarBox.w - 20, "center")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue