Can expand and reduce canvass with lctrl and lshift. (Bug: all tiles get erased :c)
This commit is contained in:
parent
727592ac55
commit
e1bfd4f7f5
|
@ -115,34 +115,35 @@ function EditorDoEdit()
|
||||||
and LevelTiles[vertical][horizontal] ~= nil
|
and LevelTiles[vertical][horizontal] ~= nil
|
||||||
and love.keyboard.isDown("lshift") ~= true
|
and love.keyboard.isDown("lshift") ~= true
|
||||||
and love.keyboard.isDown("lctrl") ~= true
|
and love.keyboard.isDown("lctrl") ~= true
|
||||||
|
then
|
||||||
|
if Keybind:CheckDown(Keybind.generic.lclick)
|
||||||
and selecting_tile ~= nil
|
and selecting_tile ~= nil
|
||||||
then
|
then
|
||||||
if Keybind:CheckDown(Keybind.generic.lclick) then
|
SetTile(vertical,horizontal,selecting_tile)
|
||||||
InstanceTile(vertical,horizontal,selecting_tile)
|
|
||||||
elseif Keybind:CheckDown(Keybind.generic.rclick) then
|
elseif Keybind:CheckDown(Keybind.generic.rclick) then
|
||||||
InstanceTile(vertical,horizontal,0)
|
SetTile(vertical,horizontal,0)
|
||||||
end
|
end
|
||||||
LevelReloadTiles()
|
LevelReloadTiles()
|
||||||
--[[
|
|
||||||
elseif love.keyboard.isDown("lshift") then
|
elseif Keybind:HasPressed(Keybind.generic.lshift) then
|
||||||
--ExpandCanvas(math.sign(expand_h),math.sign(expand_v))
|
LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v))
|
||||||
|
|
||||||
if expand_h < 0 then
|
if expand_h < 0 then
|
||||||
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
Camera.pos.x = Camera.pos.x - math.sign(expand_h)*tileProperties.scale*tileProperties.width
|
||||||
end
|
end
|
||||||
if expand_v < 0 then
|
if expand_v < 0 then
|
||||||
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
Camera.pos.y = Camera.pos.y - math.sign(expand_v)*tileProperties.scale*tileProperties.height
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif love.keyboard.isDown("lctrl") then
|
elseif Keybind:HasPressed(Keybind.generic.lctrl) then
|
||||||
--ReduceCanvas(math.sign(expand_h),math.sign(expand_v))
|
LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v))
|
||||||
|
|
||||||
if expand_h < 0 then
|
if expand_h < 0 then
|
||||||
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
Camera.pos.x = Camera.pos.x - math.sign(expand_h)*tileProperties.scale*tileProperties.width
|
||||||
end
|
end
|
||||||
if expand_v < 0 then
|
if expand_v < 0 then
|
||||||
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
Camera.pos.y = Camera.pos.y - math.sign(expand_v)*tileProperties.scale*tileProperties.height
|
||||||
end]]
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,6 +71,8 @@ function Keybind:Default()
|
||||||
-- Generic
|
-- Generic
|
||||||
Keybind.generic.lclick = { keys = {1}}
|
Keybind.generic.lclick = { keys = {1}}
|
||||||
Keybind.generic.rclick = { keys = {2}}
|
Keybind.generic.rclick = { keys = {2}}
|
||||||
|
Keybind.generic.lshift = { keys = {"lshift"}}
|
||||||
|
Keybind.generic.lctrl = { keys = {"lctrl"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set default values at start
|
-- Set default values at start
|
||||||
|
|
|
@ -19,6 +19,86 @@ function LevelLoadTiles()
|
||||||
TileCreateObjects()
|
TileCreateObjects()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function LevelExpandCanvas(horizontal,vertical)
|
||||||
|
local h = LevelGetTileWidth()
|
||||||
|
local v = LevelGetTileHeight()
|
||||||
|
|
||||||
|
-- get new canvas size
|
||||||
|
local newCanvasH = h + math.abs(horizontal)
|
||||||
|
local newCanvasV = v + math.abs(vertical)
|
||||||
|
|
||||||
|
-- lets make a new temporal canvas
|
||||||
|
local ExpandedLevel = {}
|
||||||
|
for i = 1, newCanvasV do
|
||||||
|
ExpandedLevel[i] = {}
|
||||||
|
for j = 1, newCanvasH do
|
||||||
|
ExpandedLevel[i][j] = InstanceTile(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- lets guess how the new canvas and positions are offset
|
||||||
|
local expand_h = 0
|
||||||
|
if horizontal < 0 then
|
||||||
|
expand_h = -horizontal
|
||||||
|
end
|
||||||
|
|
||||||
|
local expand_v = 0
|
||||||
|
if vertical < 0 then
|
||||||
|
expand_v = -vertical
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get data from old canvas to new canvas
|
||||||
|
for i = 1, #LevelTiles do
|
||||||
|
for j = 1, #LevelTiles[i] do
|
||||||
|
ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use new canvas
|
||||||
|
LevelTiles = ExpandedLevel
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function LevelReduceCanvas(horizontal,vertical)
|
||||||
|
local h = LevelGetTileWidth()
|
||||||
|
local v = LevelGetTileHeight()
|
||||||
|
|
||||||
|
-- get new canvas size
|
||||||
|
local newCanvasH = h - math.abs(horizontal)
|
||||||
|
local newCanvasV = v - math.abs(vertical)
|
||||||
|
|
||||||
|
-- lets make a new temporal canvas
|
||||||
|
local ExpandedLevel = {}
|
||||||
|
for i = 1, newCanvasV do
|
||||||
|
ExpandedLevel[i] = {}
|
||||||
|
for j = 1, newCanvasH do
|
||||||
|
ExpandedLevel[i][j] = InstanceTile(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- lets guess how the new canvas and positions are offset
|
||||||
|
local expand_h = 0
|
||||||
|
if horizontal < 0 then
|
||||||
|
expand_h = -horizontal
|
||||||
|
end
|
||||||
|
|
||||||
|
local expand_v = 0
|
||||||
|
if vertical < 0 then
|
||||||
|
expand_v = -vertical
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get data from old canvas to new canvas
|
||||||
|
for i = 1, #ExpandedLevel do
|
||||||
|
for j = 1, #ExpandedLevel[i] do
|
||||||
|
ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use new canvas
|
||||||
|
LevelTiles = ExpandedLevel
|
||||||
|
end
|
||||||
|
|
||||||
function LevelGetTileData()
|
function LevelGetTileData()
|
||||||
for k, v in pairs(tileset) do
|
for k, v in pairs(tileset) do
|
||||||
if v == LevelData.tileset then
|
if v == LevelData.tileset then
|
||||||
|
@ -79,7 +159,7 @@ function LevelIndexTiles()
|
||||||
-- instance level tiles according to the Properties
|
-- instance level tiles according to the Properties
|
||||||
for i = 1, #LevelTiles do
|
for i = 1, #LevelTiles do
|
||||||
for j = 1, #LevelTiles[i] do
|
for j = 1, #LevelTiles[i] do
|
||||||
InstanceTile(i,j,LevelTiles[i][j])
|
SetTile(i,j,LevelTiles[i][j])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -117,9 +197,8 @@ function TileDataInitialize()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function InstanceTile(i,j,id)
|
function InstanceTile(id)
|
||||||
LevelTiles[i][j] = {}
|
local tile = {}
|
||||||
local tile = LevelTiles[i][j]
|
|
||||||
|
|
||||||
tile.id = id
|
tile.id = id
|
||||||
local Properties = TileData[tile.id]
|
local Properties = TileData[tile.id]
|
||||||
|
@ -137,6 +216,12 @@ function InstanceTile(i,j,id)
|
||||||
tile.display = Properties.force
|
tile.display = Properties.force
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return tile
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetTile(i,j,id)
|
||||||
|
LevelTiles[i][j] = InstanceTile(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TileGetType(tile)
|
function TileGetType(tile)
|
||||||
|
|
Loading…
Reference in New Issue