- [NEW][EDITOR] Cloning stamp
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
editor={
|
editor={
|
||||||
paused=true,
|
paused=true,
|
||||||
cam={x=0,y=0},
|
cam={x=0,y=0},
|
||||||
selected_tile=3,
|
--selected_tile=3,
|
||||||
|
brush={w=1,h=1,tiles={3}},
|
||||||
|
selection=nil,
|
||||||
|
|
||||||
init=function()
|
init=function()
|
||||||
set_update(editor.update)
|
set_update(editor.update)
|
||||||
@@ -27,6 +29,35 @@ editor={
|
|||||||
if y>0 and mget(x,y-1)==t then editor.floodfill(x,y-1,tile) end
|
if y>0 and mget(x,y-1)==t then editor.floodfill(x,y-1,tile) end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
create_stamp=function()
|
||||||
|
local tx1,ty1,tx2,ty2=editor.selection.x1,editor.selection.y1,editor.selection.x2,editor.selection.y2
|
||||||
|
if tx1>tx2 then tx1,tx2=tx2,tx1 end
|
||||||
|
if ty1>ty2 then ty1,ty2=ty2,ty1 end
|
||||||
|
editor.brush.w=tx2-tx1+1
|
||||||
|
editor.brush.h=ty2-ty1+1
|
||||||
|
local w,h=editor.brush.w,editor.brush.h
|
||||||
|
local p=1
|
||||||
|
for y=1,h do
|
||||||
|
for x=1,w do
|
||||||
|
editor.brush.tiles[p]=mget(tx1+x-1,ty1+y-1)
|
||||||
|
--mset(tx+x-1,ty+y-1,editor.brush.tiles[p])
|
||||||
|
p=p+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
|
stamp=function(tx,ty)
|
||||||
|
local w,h=editor.brush.w,editor.brush.h
|
||||||
|
local p=1
|
||||||
|
for y=1,h do
|
||||||
|
for x=1,w do
|
||||||
|
mset(tx+x-1,ty+y-1,editor.brush.tiles[p])
|
||||||
|
p=p+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
update=function()
|
update=function()
|
||||||
cls()
|
cls()
|
||||||
camera(editor.cam.x, editor.cam.y)
|
camera(editor.cam.x, editor.cam.y)
|
||||||
@@ -36,11 +67,35 @@ editor={
|
|||||||
local tx,ty=mx>>3,my>>3
|
local tx,ty=mx>>3,my>>3
|
||||||
local rx,ry=tx<<3,ty<<3
|
local rx,ry=tx<<3,ty<<3
|
||||||
rect(rx-1, ry-1, rx+8, ry+8, 10)
|
rect(rx-1, ry-1, rx+8, ry+8, 10)
|
||||||
|
if editor.selection then
|
||||||
|
local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3
|
||||||
|
if rx1>rx2 then rx1,rx2=rx2,rx1 end
|
||||||
|
if ry1>ry2 then ry1,ry2=ry2,ry1 end
|
||||||
|
rect(rx1-1, ry1-1, rx2+8, ry2+8, 8)
|
||||||
|
end
|
||||||
camera(0,0)
|
camera(0,0)
|
||||||
|
|
||||||
if not editor.paused then
|
if not editor.paused then
|
||||||
if mbtn(1) then
|
if mbtn(1) then
|
||||||
mset(tx,ty,editor.selected_tile)
|
editor.stamp(tx,ty)
|
||||||
|
--mset(tx,ty,editor.brush.tiles[1])
|
||||||
|
end
|
||||||
|
if mbtn(3) then
|
||||||
|
if editor.selection then
|
||||||
|
editor.selection.x2=tx
|
||||||
|
editor.selection.y2=ty
|
||||||
|
else
|
||||||
|
editor.selection={}
|
||||||
|
editor.selection.x1=tx
|
||||||
|
editor.selection.y1=ty
|
||||||
|
editor.selection.x2=tx
|
||||||
|
editor.selection.y2=ty
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if editor.selection then
|
||||||
|
editor.create_stamp()
|
||||||
|
editor.selection=nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if btnp(KEY_RIGHT) then editor.cam.x=editor.cam.x+8 end
|
if btnp(KEY_RIGHT) then editor.cam.x=editor.cam.x+8 end
|
||||||
@@ -48,10 +103,10 @@ editor={
|
|||||||
if btnp(KEY_UP) then editor.cam.y=editor.cam.y-8 end
|
if btnp(KEY_UP) then editor.cam.y=editor.cam.y-8 end
|
||||||
if btnp(KEY_DOWN) then editor.cam.y=editor.cam.y+8 end
|
if btnp(KEY_DOWN) then editor.cam.y=editor.cam.y+8 end
|
||||||
if btnp(KEY_F) then
|
if btnp(KEY_F) then
|
||||||
editor.floodfill(tx,ty,editor.selected_tile)
|
editor.floodfill(tx,ty,editor.brush.tiles[1])
|
||||||
end
|
end
|
||||||
if btnp(KEY_RETURN) then
|
if btnp(KEY_RETURN) then
|
||||||
editor.selected_tile=mget(tx,ty)
|
editor.brush.tiles[1]=mget(tx,ty)
|
||||||
end
|
end
|
||||||
if btnp(KEY_ESCAPE) then
|
if btnp(KEY_ESCAPE) then
|
||||||
editor.paused=true
|
editor.paused=true
|
||||||
@@ -78,7 +133,10 @@ editor={
|
|||||||
|
|
||||||
if mbtnp(1) then
|
if mbtnp(1) then
|
||||||
if tx<16 and ty<16 then
|
if tx<16 and ty<16 then
|
||||||
editor.selected_tile=ty*16+tx
|
editor.brush.w=1
|
||||||
|
editor.brush.h=1
|
||||||
|
editor.brush.tiles={}
|
||||||
|
editor.brush.tiles[1]=ty*16+tx
|
||||||
end
|
end
|
||||||
update=editor.update
|
update=editor.update
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user