Community Curator/Source/TSWRes GameCM

-- CreateMode --

function GT.SaveUndo if UndoFunction then GT.SaveLevel("Undo") end end

-- Create Mode Touch Action function Touch(TX,TY) GT.PopitMenu(TX,TY) local PopitPress = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) local UndoPress = TRec(32, 32, 96, 96,TX,TY) if PopitPress and not PopitOpen then PopitOpen = true PopitCuMenu = "Home" end if UndoPress then --GT.Undo end if NoticeText ~= "" then MagicMouthTextRemove(TX, TY) end end

-- Undos anything function GT.Undo GT.SaveLevel("Redo") --print("Undoing") Undo = true draw.beginframe Draw.BGs.Default draw.endframe GT.LoadLevel("Undo") end

-- Deletes a Level. function GT.DeleteLevel(Level) Level = Level or GT.Vars.CurrentLevel --print("Removing Level") if type(Level) == "number" then --print(MyMoonLevels) --print(MyMoonLevels["Levels"]) local SLT = MyMoonLevels["SavedLevelTab"] table.remove(SLT, Level) MyMoonLevels["Levels"] = #MyMoonLevels["SavedLevelTab"] print("Saving to MyMoonLevels") Loader.SaveMyMoonLevels end os.remove("LBPLua.Level"..Level..".lualevel") os.remove("LBPLua.Level"..Level..".lualobj") os.remove("LBPLua.Level"..Level..".lualch") print("Ok") end

-- Saves a level. function GT.SaveLevel(Level) Level = Level or GT.Vars.CurrentLevel --print("Saving Level") if type(Level) == "number" then print(MyMoonLevels) print(MyMoonLevels["Levels"]) local SLT = MyMoonLevels["SavedLevelTab"] SLT[Level] = LevelTab MyMoonLevels["Levels"] = #MyMoonLevels["SavedLevelTab"] --print("Saving to MyMoonLevels") Loader.SaveMyMoonLevels end local LObjStr = JSON.EncodeJSON(ObjTab) local LevelStr = JSON.EncodeJSON(LevelTab) local CheStr = JSON.EncodeJSON(ChPtTab) local LevelSave = io.open("LBPLua.Level"..Level..".lualevel", "w") LevelSave:write(LevelStr) LevelSave:close local ObjSave = io.open("LBPLua.Level"..Level..".lualobj", "w") ObjSave:write(LObjStr) ObjSave:close local ChPtSave = io.open("LBPLua.Level"..Level..".lualch", "w") ChPtSave:write(CheStr) ChPtSave:close LoaderTab.LoadMyMoonLevels end

-- Loads a level function GT.LoadLevel(Level) local LevelSave = io.open("LBPLua.Level"..Level..".lualevel") local LSt = LevelSave:read LevelTab = JSON.DecodeJSON(LSt) LevelSave:close local ObjSave = io.open("LBPLua.Level"..Level..".lualobj") ObjTab = (ObjSave:read) ObjSave:close local ChPtSave = io.open("LBPLua.Level"..Level..".lualch") local ChPtStr = ChPtSave:read ChPtSave:close Ok3, ChPtTab = pcall(JSON.DecodeJSON, ChPtStr) --print(string.sub(ObjTab,0, 2000)) Ok2, ObjTab = pcall(JSON.DecodeJSON, ObjTab) if Ok3 == false then error("Error loading level "..Level.." ("..ChPtTab..")") elseif type(ChPtTab) == "string" then error("ChPtTab is of incorrect type ("..type(ChPtTab)..")") end GT.FixIncLTV if not LevelTab["WaterLevel"] then LevelTab["WaterLevel"] = -10000 end CG end

-- Actual Create Mode Stuff

function GT.CMZoom(TX, TY) local ZO = TRec(SizeX-160, SizeY-96, SizeX-128, SizeY-64, TX, TY) local ZI = TRec(SizeX-128, SizeY-96, SizeX-96, SizeY-64, TX, TY) if ZO then Zoom = math.max(Zoom - .1, 0.1) elseif ZI then Zoom = Zoom + .1 end end

function CMHold(TX, TY) CamMove(TX,TY) GT.CMZoom(TX, TY) return TX, TY end

function GT.DrawCMFrame local DrObjInLev = Draw.ObjectsInLevel local OldTime = sys.gettime draw.beginframe Draw.BGs.Default Draw.Level if PCEdgeX ~= nil then draw.rect(PCStartX, PCStartY, PCEdgeX, PCEdgeY, draw.white) end Draw.Thermometer(DrThV, 24, 24, 48, SizeY-48) Draw.DPad(64, SizeY-96, PlayCol1, PlayCol2) draw.rect(SizeX-96, SizeY-96, SizeX-32, SizeY-32, PlayCol1) Draw.Tool(PopitCuTool) Draw.ZoomControls Draw.Popit.Menu local NewTime = sys.gettime local Frame = (NewTime-OldTime) Draw.StatusBar(Frame) if MagicMouthText ~= "" then Draw.MagicMouthText(MagicMouthText) end if NoticeText ~= "" then Draw.MagicMouthText(NoticeText, "Notice") end draw.endframe return Frame end TX,TY = 0,0

function GT.CreateMode(Load) if Load == nil or tonumber(Load) > MyMoonLevels["Levels"] then GT.BlankLevel GT.Vars.CurrentLevel = MyMoonLevels["Levels"] + 1 LevelTab["WaterLevel"] = -10000 else GT.LoadLevel(Load) GT.Vars.CurrentLevel = Load end for i=1, math.huge do     if ToPod then ToPod = nil return end CreateMode = true ToolClosed = false PopitCuTool = nil if Undo == true then Undo = false GT.CreateMode("Undo") return end draw.doevents Frame = GT.DrawCMFrame --print = error -- Actions NTX, NTY = draw.tracktouches(Nil, CMHold ,Touch) if NTX ~= nil then TX, TY = NTX, NTY end if Frame < 1/FR then CG end --sys.sleep((1/FR-(Frame))) sys.sleep(((1/FR)-(Frame))*1000) end end

require "TSWRes GameCM1" require "TSWRes GameCM2"

return