Community Curator/Source/TSWRes Tool1

ToolRes = {}

function math.round(N) if (N - math.floor(N)) < .5 then return math.floor(N) end return math.ceil(N) end

function OCTouch(TX, TY) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) CorTab = ObjSelected if PopitClosed or Undo then ObjSelected = nil CorTab = nil PopitCuTool = nil return true end local TDirH, TDirV = TDPad(64, SizeY-96,TX,TY) CamX, CamY = CamX + TDirH, CamY + TDirV if TDirH == 0 and TDirV == 0 then if LTV + TherAdd <= MT then GT.SaveUndo ObjTab[#ObjTab+1] = GT.CreObjTab(CorTab, TX + CamX, TY - CamY, Size, TherAdd, false, SelectedMaterial) LTV = LTV + TherAdd PopitRes.PlaceSound else PopitRes.UnavailSound end end end

function ToolRes.ObjectCursor(CorTab) Undo = false PopitCuTool = "Object Cursor" TherAdd, Size = 0, ObjRes.SizeTab[CorTab] or 16 local Resizeable = ObjRes.SizeTab[CorTab] == nil ObjSelected = CorTab if type(CorTab) == "table" then TherAdd = 10*#CorTab else TherAdd = ObjRes.TherTab[CorTab] or 0 end for i=1, math.huge do     GT.DrawCMFrame draw.doevents local TX, TY = draw.tracktouches(Nil, CamMove, OCTouch) if PopitCuTool == nil then GT.SaveUndo return end collectgarbage end end

function FixObjCorn(CorTab) local StartX, EndX = math.huge, 0 local StartY, EndY = math.huge, 0 for k,v in pairs(CorTab) do     StartX = math.min(v[1], StartX) StartY = math.min(v[2], StartY) end for k,v in pairs(CorTab) do     v[1] = v[1] - (StartX) v[2] = v[2] - (StartY) end for k,v in pairs(CorTab) do     EndX = math.max(v[1], EndX) EndY = math.max(v[2], EndY) end for k,v in pairs(CorTab) do     v[1] = ((v[1] / math.max(EndX, EndY))) v[2] = ((v[2] / math.max(EndX, EndY))) end return StartX, StartY, EndX, EndY end

function FixObjCorn2(CorTab, Size) local EndX = 0 local EndY = 0 for k,v in pairs(CorTab) do     EndX = math.max(v[1], EndX) EndY = math.max(v[2], EndY) end for k,v in pairs(CorTab) do     v[1] = (v[1]*Size) v[2] = (v[2]*Size) end return EndX, EndY end

function FixObj(ObjTab) local StartX, StartY, EndX, EndY = FixObjCorn(ObjTab["CorTab"]) ObjTab["Size"] = (ObjTab["Size"] * math.max(EndX, EndY)) ObjTab["X"] = ObjTab["X"] + StartX --(math.max(EndX, EndY)) ObjTab["Y"] = ObjTab["Y"] + StartY -- (math.max(EndX, EndY)) end

function FixObj2(ObjTab) local EndX, EndY = FixObjCorn2(ObjTab["CorTab"], ObjTab["Size"]) ObjTab["Size"] = 1 ObjTab["X"] = ObjTab["X"] - (math.max(EndX, EndY)*.5) ObjTab["Y"] = ObjTab["Y"] + (math.max(EndX, EndY)*.5) end

function ObjSel(TX, TY) --if TX == nil then --  return TX, TY   --end local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) if PopitClosed then ToolClosed = true return end for k,v in pairs(ObjTab) do     local ObjTap = TRec(v["X"]- 16 -CamX, v["Y"]- 16 +CamY, (v["X"] + v["Size"])+ 4-CamX, (v["Y"] + v["Size"])+ 4+CamY, TX, TY) if ObjTap == true then if k > 4 then ObjSelected = k        end end end end

function CETouch(TX, TY) --print("Touched "..TX, TY) assert(TX) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) if ObjSelected == nil then if PopitClosed then ToolClosed = true return end ObjSel(TX, TY) return TX, TY  elseif CorSel == nil then if PopitClosed then Object = ObjTab[ObjSelected] FixObj(Object) Object["TVal"] = #Object["CorTab"] * 10 GT.FixIncLTV ObjSelected = nil Fixed = nil return end end Object = ObjTab[ObjSelected] assert(ObjSelected, "ObjSelected is missing") if CorSel ~= nil then CETouchC(TX, TY) return TX, TY  end if type(Object["CorTab"]) ~= "table" then Object["CorTab"] = {{0,0}, {0,1}, {1,1}, {1,0}} end assert(ObjSelected ~= nil) assert(type(Object["CorTab"]) == "table") if type(Object["CorTab"]) == "table" and not Fixed then FixObj2(Object) Fixed = true end CorSel = nil local SB = 24 local Size = Object["Size"] for k, v in ipairs(Object["CorTab"]) do     local IsSel = TRec(((v[1]*Size)-16)+(Object["X"]), ((v[2]*Size)-16)+(Object["Y"]), ((v[1]*Size)+16)+(Object["X"]), ((v[2]*Size)+16)+(Object["Y"]), TX+CamX, TY-CamY) if IsSel then CorSel = k        --print("CorSel"..CorSel) return TX, TY     end end if CorSel == nil then CorSel = #Object["CorTab"]+1 end return TX, TY end

function CETouchC(TX, TY) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) CorTab = ObjTab[ObjSelected] CorTab =CorTab["CorTab"] if PopitClosed and CorTab[CorSel] ~= nil then --print("Deleting "..tostring(CorSel)) table.remove(CorTab, CorSel) CorSel = nil PopitRes.DeleteSound return elseif PopitClosed and CorTab[CorSel] == nil then CorSel = nil return end CorTab[CorSel] = {} SCor = CorTab[CorSel] if not Grid then SCor[1] = (-((-TX+(Object["X"]))/Object["Size"]))+(CamX/Object["Size"]) SCor[2] = (-((-TY+(Object["Y"]))/Object["Size"]))- (CamY/Object["Size"]) else SCor[1] = math.round((-((-TX+(Object["X"]))/Object["Size"]))+(CamX/Object["Size"])) SCor[2] = math.round((-((-TY+(Object["Y"]))/Object["Size"]))- (CamY/Object["Size"])) end --print((TX+(Object["X"]))/Object["Size"]) PopitRes.PlaceSound CorSel = nil end

function CornerShow if ObjSelected == nil then return end local Object = ObjTab[ObjSelected] local CorTab = Object["CorTab"] local Cor = CorTab[CorSel] --print("Corner "..CorSel, "X: "..Cor[1], "Y: "..Cor[2]) if Cor ~= nil then draw.beginframe local Size = Object["Size"] draw.fillcircle(((Cor[1]*Size)+(Object["X"]))-CamX, ((Cor[2]*Size)+(Object["Y"]))+CamY, 16, PlayCol1) --print("CorSel"..CorSel) draw.endframe end end

function ToolRes.CorEditor PopitCuTool = "Corner Editor" ObjSelected = nil Mode = 0 draw.tracktouches(Nil, CamMove, CETouch) for i=1, math.huge do     GT.DrawCMFrame if CorSel ~= nil then CornerShow end draw.doevents if ToolClosed then return end --[[if ObjSelected == nil then        if TDirH == 0 and TDirV == 0 then

end else local Object = ObjTab[ObjSelected] print(ObjSelected) local TDirH, TDirV = TDPad(64, SizeY-96,TX,TY) CamX, CamY = CamX + TDirH, CamY + TDirV if PopitClosed then table.remove(ObjTab, ObjSelected) PopitRes.DeleteSound end if TDirH == 0 and TDirV == 0 then if CorSel == nil then CETouch(TX, TY) else CETouchC(TX, TY) end end end]] collectgarbage("stop") end end

PopitRes.ObjectCursor = ToolRes.ObjectCursor PopitRes.CorEditor = ToolRes.CorEditor

require "TSWRes Tool2"

return