id_
This commit is contained in:
parent
b19f58726c
commit
01d272981e
133 changed files with 822 additions and 66 deletions
389
level_editor/editor.lua
Normal file
389
level_editor/editor.lua
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
require "level_editor/object_attributes"
|
||||
require "level_editor/gui"
|
||||
|
||||
editorView = "room" --can be "off", "room", "world", "asset"
|
||||
selectedColor = "red"
|
||||
|
||||
local bacSprite = love.graphics.newImage("art/_ui/bac.png")
|
||||
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 selectedFolder = nil
|
||||
local selectedAsset = nil
|
||||
local selectedRoom = nil
|
||||
local selectedRow = 1
|
||||
local gameAssets = getAllAssets()
|
||||
local inputText = ""
|
||||
local assetProperties = {}
|
||||
|
||||
local activeField = nil --this is for whenwe are doing text input things
|
||||
|
||||
local uiButtons = {}
|
||||
local folderButtons = {}
|
||||
local assetButtons = { {} } --table for rows so we can do stuff
|
||||
local editingAssetButtons = {}
|
||||
|
||||
local labels = {}
|
||||
|
||||
|
||||
function _initLevelEditor()
|
||||
assets = getAllAssets()
|
||||
|
||||
--create folder buttons
|
||||
local counter = 1
|
||||
for folder, object in pairs(gameAssets) do
|
||||
local button = createUIElement{
|
||||
name = "folder",
|
||||
text = folder,
|
||||
x = 30,
|
||||
y = (sideBarBox.h - 50) * (counter / 15),
|
||||
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
|
||||
print("saveing!!")
|
||||
currentRoom:save()
|
||||
end
|
||||
end,
|
||||
right = function()
|
||||
|
||||
end
|
||||
},
|
||||
x = sideBarBox.w / 4,
|
||||
y = sideBarBox.h * (9 / 10)
|
||||
})
|
||||
|
||||
_addUIButton(createUIElement{
|
||||
name = "world",
|
||||
sprite = love.graphics.newImage("art/_ui/world.png"),
|
||||
onClic = {
|
||||
left = function()
|
||||
print(editorView)
|
||||
if editorView == "room" then
|
||||
print("saveing!!")
|
||||
currentRoom:save()
|
||||
end
|
||||
end,
|
||||
right = function()
|
||||
|
||||
end
|
||||
},
|
||||
x = sideBarBox.w * (3 / 4),
|
||||
y = sideBarBox.h * (9 / 10)
|
||||
})
|
||||
|
||||
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
|
||||
},
|
||||
x = sideBarBox.w * (_ / 5),
|
||||
y = sideBarBox.h * (8 / 10)
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function setSelectedColor(color)
|
||||
selectedColor = color
|
||||
end
|
||||
|
||||
function selectFolder(folder)
|
||||
selectedFolder = folder
|
||||
|
||||
local bacButton = _addUIButton(createUIElement{
|
||||
name = "bacToFolderView",
|
||||
sprite = bacSprite,
|
||||
x = sideBarBox.w / 2,
|
||||
y = 37.5,
|
||||
onClic = {
|
||||
left = function(self)
|
||||
print(self, self.x)
|
||||
self = nil
|
||||
folderView(self)
|
||||
end,
|
||||
right = function(self) return end
|
||||
}
|
||||
}, "bacToFolderView")
|
||||
local row = 1
|
||||
local counter = 1
|
||||
local limit = 10
|
||||
|
||||
for asset, colorArray in pairs(gameAssets[selectedFolder]) do
|
||||
if counter % limit == 0 then
|
||||
counter = 1
|
||||
|
||||
local forwardButton = createUIElement{
|
||||
name = "forward",
|
||||
sprite = forwardSprite,
|
||||
x = sideBarBox.w / 2,
|
||||
y = sideBarBox.h - 250,
|
||||
onClic = {
|
||||
left = function()
|
||||
selectedRow = selectedRow + 1
|
||||
end,
|
||||
right = function()
|
||||
|
||||
end
|
||||
}
|
||||
}
|
||||
table.insert(assetButtons[row], forwardbutton)
|
||||
|
||||
row = row + 1
|
||||
table.insert(assetButtons, {})
|
||||
end
|
||||
|
||||
local sprites = {}
|
||||
|
||||
for color, location in pairs(colorArray) do
|
||||
sprites[color] = love.graphics.newImage(location)
|
||||
end
|
||||
|
||||
local assetButton = createUIElement{
|
||||
sprites = sprites,
|
||||
name = "asset",
|
||||
text = asset,
|
||||
x = 30,
|
||||
y = (sideBarBox.h - 225) * (counter / limit) + 20,
|
||||
onClic = {
|
||||
left = function()
|
||||
print(asset)
|
||||
selectAsset(asset)
|
||||
end,
|
||||
right = function()
|
||||
editAsset(asset)
|
||||
end
|
||||
}
|
||||
}
|
||||
table.insert(assetButtons[row], assetButton)
|
||||
counter = counter + 1
|
||||
end
|
||||
end
|
||||
|
||||
function selectAsset(asset)
|
||||
print("selecting", asset)
|
||||
selectedAsset = asset
|
||||
print(selectedAsset)
|
||||
end
|
||||
|
||||
function editAsset(asset)
|
||||
assetProperties = {
|
||||
class = "",
|
||||
}
|
||||
|
||||
inputText = ""
|
||||
editorView = "asset"
|
||||
selectedAsset = asset
|
||||
|
||||
local filename = "art/" .. selectedFolder .. "/" .. selectedAsset .. ".prop"
|
||||
if love.filesystem.exists(filename) then
|
||||
assetProperties = TSerial.unpack(love.filesystem.read(filename))
|
||||
end
|
||||
|
||||
local cancelButton = createUIElement{
|
||||
name = "cancel",
|
||||
sprite = cancelSprite,
|
||||
x = sideBarBox.w / 3,
|
||||
y = sideBarBox.h - 75,
|
||||
onClic = {
|
||||
left = function(self)
|
||||
assetsView()
|
||||
end,
|
||||
right = function(self) return end
|
||||
}
|
||||
}
|
||||
|
||||
local confirmButton = createUIElement{
|
||||
name = "confirm",
|
||||
sprite = confirmSprite,
|
||||
x = sideBarBox.w * 2 / 3,
|
||||
y = sideBarBox.h - 75,
|
||||
onClic = {
|
||||
left = function(self)
|
||||
saveAsset()
|
||||
end,
|
||||
right = function(self) return end
|
||||
}
|
||||
}
|
||||
|
||||
editingAssetButtons[cancelButton] = cancelButton
|
||||
editingAssetButtons[confirmButton] = confirmButton
|
||||
|
||||
|
||||
local assetSprites = {}
|
||||
for color, path in pairs(gameAssets[selectedFolder][selectedAsset]) do
|
||||
assetSprites[color] = love.graphics.newImage(path)
|
||||
end
|
||||
|
||||
local assetButton = createUIElement{
|
||||
name = asset,
|
||||
sprites = assetSprites,
|
||||
x = sideBarBox.w / 2 - 18,
|
||||
y = 80,
|
||||
}
|
||||
|
||||
local classFieldLabel = {
|
||||
draw = function() love.graphics.printf("CLASS", 0, 125, sideBarBox.w, "center") end
|
||||
}
|
||||
|
||||
labels[classFieldLabel] = classFieldLabel
|
||||
|
||||
local classButton = createUIElement{
|
||||
name = "class",
|
||||
text = assetProperties.class or "",
|
||||
x = 25,
|
||||
y = 150,
|
||||
onClic = {
|
||||
left = function()
|
||||
activeField = "class"
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
editingAssetButtons[assetButton] = assetButton
|
||||
editingAssetButtons.class = classButton
|
||||
end
|
||||
|
||||
function saveAsset()
|
||||
local save = TSerial.pack(assetProperties, nil, true)
|
||||
diditdoit = love.filesystem.write("art/" .. selectedFolder .. "/" .. selectedAsset .. ".prop", save)
|
||||
print("fdfdfdfd", diditdoit)
|
||||
assetsView()
|
||||
end
|
||||
|
||||
|
||||
function _addUIButton(button, name)
|
||||
local index = name or button
|
||||
uiButtons[index] = button
|
||||
end
|
||||
|
||||
function folderView()
|
||||
selectedRow = 1
|
||||
selectedFolder = nil
|
||||
assetButtons = {{}}
|
||||
uiButtons.bacToFolderView = nil
|
||||
labels = {}
|
||||
end
|
||||
|
||||
function assetsView()
|
||||
editingAssetButtons = {}
|
||||
editorView = "room"
|
||||
labels = {}
|
||||
end
|
||||
|
||||
function worldView()
|
||||
|
||||
end
|
||||
|
||||
function editorMouseHandler(x, y, button)
|
||||
if x > width then
|
||||
--we need to adjust for sidebar coords
|
||||
x = x - width
|
||||
|
||||
if editorView == "room" then
|
||||
if not selectedFolder then
|
||||
for _, uiElement in pairs(folderButtons) do
|
||||
if uiElement:clicIsInBox(x, y) then
|
||||
uiElement:onClic(button)
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, uiElement in pairs(assetButtons[selectedRow]) do
|
||||
if uiElement:clicIsInBox(x, y) then
|
||||
uiElement:onClic(button)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, uiElement in pairs(uiButtons) do
|
||||
if uiElement:clicIsInBox(x, y) then
|
||||
uiElement:onClic(button)
|
||||
end
|
||||
end
|
||||
elseif editorView == "asset" then
|
||||
for _, uiElement in pairs(editingAssetButtons) do
|
||||
if uiElement:clicIsInBox(x, y) then
|
||||
uiElement:onClic(button)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function editorTextHandler(text)
|
||||
if editorView == "asset" and activeField then
|
||||
inputText = text
|
||||
editingAssetButtons[activeField]:editText(text)
|
||||
end
|
||||
end
|
||||
|
||||
function editorCompleteResponse()
|
||||
if editorView == "asset" then
|
||||
assetProperties[activeField] = inputText
|
||||
end
|
||||
print(assetProperties[activeField], "ass")
|
||||
activeField = nil
|
||||
end
|
||||
|
||||
function sortAllAssets()
|
||||
setAll()
|
||||
end
|
||||
|
||||
function createUIElement(t)
|
||||
return GUI:new(t)
|
||||
end
|
||||
|
||||
function editorDraw()
|
||||
if editorView == "room" then
|
||||
for _, button in pairs(uiButtons) do
|
||||
button:draw()
|
||||
end
|
||||
if not selectedFolder then
|
||||
for _, folder in pairs(folderButtons) do
|
||||
folder:draw()
|
||||
end
|
||||
else
|
||||
for _, entity in ipairs(assetButtons[selectedRow]) do
|
||||
entity:draw()
|
||||
end
|
||||
end
|
||||
elseif editorView == "asset" then
|
||||
for _, button in pairs(editingAssetButtons) do
|
||||
button:draw()
|
||||
end
|
||||
end
|
||||
|
||||
for _, label in pairs(labels) do
|
||||
label:draw()
|
||||
end
|
||||
end
|
||||
129
level_editor/gui.lua
Normal file
129
level_editor/gui.lua
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
GUI = class("level_editor/gui")
|
||||
|
||||
GUI.static.pressSound = love.audio.newSource("sounds/ui/button.wav")
|
||||
|
||||
GUI.static.defaultCallbac = function() print("this button has not been configured") end
|
||||
|
||||
function GUI:initialize(t)
|
||||
print("i exist", t.name, t.text)
|
||||
self.offset = {x = 0, y = 0}
|
||||
self.name = t.name
|
||||
self.text = t.text
|
||||
|
||||
if not t.onClic then
|
||||
t.onClic = {}
|
||||
end
|
||||
if not t.onClic.right then
|
||||
t.onClic.right = GUI.defaultCallbac
|
||||
end
|
||||
if not t.onClic.left then
|
||||
t.onClic.left = GUI.defaultCallbac
|
||||
end
|
||||
|
||||
self.clic = t.onClic
|
||||
|
||||
self.x, self.y = t.x, t.y
|
||||
|
||||
if t.sprite then
|
||||
print(self.name)
|
||||
self.scale = drawScale * 2 / 3
|
||||
self.w = t.sprite:getWidth() * self.scale
|
||||
self.h = t.sprite:getHeight() * self.scale
|
||||
self.sprite = t.sprite
|
||||
|
||||
self.offset = {x = self.w / 2, y = self.h / 2}
|
||||
self.x, self.y = t.x - self.offset.x, t.y - self.offset.y
|
||||
elseif t.sprites then
|
||||
self.sprites = t.sprites
|
||||
local w, h
|
||||
for color, sprite in pairs(t.sprites) do
|
||||
w = sprite:getWidth()
|
||||
h = sprite:getHeight()
|
||||
end
|
||||
if w > h then
|
||||
self.scale = (drawScale * (2 / 3)) / (w / 16)
|
||||
elseif w < h then
|
||||
self.scale = (drawScale * (2 / 3)) / (h / 16)
|
||||
else
|
||||
self.scale = (drawScale * (2 / 3)) / (w / 16)
|
||||
end
|
||||
self.w = sideBarBox.w - (self.x * 2)
|
||||
self.h = h * self.scale
|
||||
else
|
||||
-- this is text
|
||||
self.x, self.y = t.x, t.y
|
||||
self.w, self.h = sideBarBox.w - self.x * 2, 50
|
||||
end
|
||||
|
||||
if self.name == "folder" then
|
||||
self.w = sideBarBox.w - self.x * 2
|
||||
end
|
||||
end
|
||||
|
||||
function GUI:clicIsInBox(x, y)
|
||||
if x > self.x and x < self.x + self.w and y > self.y and y < self.y + self.h then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function GUI:getBox()
|
||||
return {x = self.x, y = self.y, w = self.w, h = self.h}
|
||||
end
|
||||
|
||||
function GUI:editText(text)
|
||||
self.text = text
|
||||
end
|
||||
|
||||
function GUI:draw()
|
||||
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
love.graphics.setLineWidth(4)
|
||||
|
||||
local box = self:getBox()
|
||||
box.x = box.x + self:sha()
|
||||
box.y = box.y + self:sha()
|
||||
|
||||
if name == "forward" then
|
||||
print(box.x, box.y)
|
||||
end
|
||||
|
||||
if selectedColor == self.name then
|
||||
love.graphics.rectangle("line", box.x, box.y, box.w, box.h)
|
||||
end
|
||||
|
||||
if self.sprite then
|
||||
love.graphics.draw(self.sprite, box.x, box.y, 0, self.scale, self.scale)
|
||||
end
|
||||
|
||||
if self.sprites then
|
||||
for color, sprite in pairs(self.sprites) do
|
||||
love.graphics.setColor(gColor[color]:set())
|
||||
love.graphics.draw(sprite, box.x, box.y, 0, self.scale, self.scale)
|
||||
end
|
||||
end
|
||||
|
||||
if self.text then
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
if not self.sprites and not self.sprite then
|
||||
love.graphics.rectangle("line", box.x, box.y, box.w, box.h)
|
||||
end
|
||||
love.graphics.print(self.text, box.x + 50, box.y + 15)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function GUI:onClic(button)
|
||||
print(button)
|
||||
print("hey!!! u cliced on me. my name is ", self.name, self.text)
|
||||
GUI.pressSound:play()
|
||||
if button == "l" then
|
||||
self.clic:left()
|
||||
elseif button == "r" then
|
||||
self.clic:right()
|
||||
end
|
||||
end
|
||||
|
||||
function GUI:sha()
|
||||
return math.random(-worldSha, worldSha) * .5
|
||||
end
|
||||
43
level_editor/object_attributes.lua
Normal file
43
level_editor/object_attributes.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
require "libs/TSerial"
|
||||
|
||||
local targetFolder = "art"
|
||||
|
||||
function get(folder)
|
||||
|
||||
end
|
||||
|
||||
function getAllAssets()
|
||||
local objectnames = {}
|
||||
local topFolder = "art"
|
||||
local files = love.filesystem.getDirectoryItems(topFolder)
|
||||
for _, folder in pairs(files) do
|
||||
if string.sub(folder, 1, 1) ~= "_" then
|
||||
-- we ignore directories which are prepended w/ an underscore
|
||||
if not string.find(folder, "%.") then
|
||||
objectnames[folder] = {}
|
||||
love.filesystem.createDirectory("art/" .. folder)
|
||||
-- this is a folder, probably
|
||||
local newFiles = love.filesystem.getDirectoryItems(topFolder .. "/" .. folder)
|
||||
for _, fileToAnalyze in pairs(newFiles) do
|
||||
if fileToAnalyze:find("_r.png") or fileToAnalyze:find("_g.png") or fileToAnalyze:find("_b.png")then
|
||||
local color
|
||||
|
||||
if fileToAnalyze:find("_r.png") then color = "red"
|
||||
elseif fileToAnalyze:find("_g.png") then color = "green"
|
||||
elseif fileToAnalyze:find("_b.png") then color = "blue" end
|
||||
|
||||
local name = fileToAnalyze:sub(1, fileToAnalyze:len() - 6)
|
||||
if not objectnames[folder][name] then
|
||||
objectnames[folder][name] = {}
|
||||
end
|
||||
objectnames[folder][name][color] = topFolder .. "/" .. folder .. "/" .. fileToAnalyze
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
str = TSerial.pack(objectnames, nil, true)
|
||||
love.filesystem.write("great.sav", str)
|
||||
return objectnames
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue