diff --git a/Content/PixelVisionOS/Tools/LoadTool/code.lua b/Content/PixelVisionOS/Tools/LoadTool/code.lua index 2103a64b..24c68446 100755 --- a/Content/PixelVisionOS/Tools/LoadTool/code.lua +++ b/Content/PixelVisionOS/Tools/LoadTool/code.lua @@ -293,7 +293,7 @@ function Draw() runnerType = ReadMetadata( "runnerType", "none" ) - if(runnerType == "c#") then runnerType = "csharp" end + if(runnerType == "csharp") then runnerType = "csharp" end if(_G["runner"..runnerType] ~= nil) then DrawSprites( _G["runner"..runnerType].spriteIDs, 116, 72, _G["runner"..runnerType].width) diff --git a/Disks/APIExamples/AddScript/info.json b/Disks/APIExamples/AddScript/info.json index b50d50af..e14707b0 100755 --- a/Disks/APIExamples/AddScript/info.json +++ b/Disks/APIExamples/AddScript/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", "paletteMode":"false", diff --git a/Disks/APIExamples/Button/info.json b/Disks/APIExamples/Button/info.json index f0767b76..a42ef621 100755 --- a/Disks/APIExamples/Button/info.json +++ b/Disks/APIExamples/Button/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/CalculateDistance/info.json b/Disks/APIExamples/CalculateDistance/info.json index bf03a79f..bda86fca 100755 --- a/Disks/APIExamples/CalculateDistance/info.json +++ b/Disks/APIExamples/CalculateDistance/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/CalculateIndex/info.json b/Disks/APIExamples/CalculateIndex/info.json index 230e2470..1e2212ec 100755 --- a/Disks/APIExamples/CalculateIndex/info.json +++ b/Disks/APIExamples/CalculateIndex/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/CalculatePosition/info.json b/Disks/APIExamples/CalculatePosition/info.json index 45148551..1a343464 100755 --- a/Disks/APIExamples/CalculatePosition/info.json +++ b/Disks/APIExamples/CalculatePosition/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/Clamp/info.json b/Disks/APIExamples/Clamp/info.json index 33e4ac4a..6d59796b 100755 --- a/Disks/APIExamples/Clamp/info.json +++ b/Disks/APIExamples/Clamp/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", "includeLibs":"", diff --git a/Disks/APIExamples/Clear/info.json b/Disks/APIExamples/Clear/info.json index 327e4288..1c17d124 100755 --- a/Disks/APIExamples/Clear/info.json +++ b/Disks/APIExamples/Clear/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/Color/info.json b/Disks/APIExamples/Color/info.json index 5376dc96..7ba4c6dd 100755 --- a/Disks/APIExamples/Color/info.json +++ b/Disks/APIExamples/Color/info.json @@ -8,7 +8,7 @@ "soundChip":"PV8", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/ColorsPerSprite/info.json b/Disks/APIExamples/ColorsPerSprite/info.json index 2a4aba43..d1528cc2 100755 --- a/Disks/APIExamples/ColorsPerSprite/info.json +++ b/Disks/APIExamples/ColorsPerSprite/info.json @@ -9,7 +9,7 @@ "paletteMode":"false", "buildWin":"false", "buildExtras":"", - "runnerType":"c#", + "runnerType":"lua", "buildMac":"false", "buildLinux":"false", diff --git a/Disks/APIExamples/Display/info.json b/Disks/APIExamples/Display/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/Display/info.json +++ b/Disks/APIExamples/Display/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawPixels/info.json b/Disks/APIExamples/DrawPixels/info.json index 4e02ab04..6219d647 100755 --- a/Disks/APIExamples/DrawPixels/info.json +++ b/Disks/APIExamples/DrawPixels/info.json @@ -7,5 +7,5 @@ "cartChip":"PV8", "soundChip":"PV8", "paletteMode":"false", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawRect/info.json b/Disks/APIExamples/DrawRect/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/DrawRect/info.json +++ b/Disks/APIExamples/DrawRect/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawSprite/info.json b/Disks/APIExamples/DrawSprite/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/DrawSprite/info.json +++ b/Disks/APIExamples/DrawSprite/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawSpriteBlock/info.json b/Disks/APIExamples/DrawSpriteBlock/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/DrawSpriteBlock/info.json +++ b/Disks/APIExamples/DrawSpriteBlock/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawSprites/info.json b/Disks/APIExamples/DrawSprites/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/DrawSprites/info.json +++ b/Disks/APIExamples/DrawSprites/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/APIExamples/DrawText/info.json b/Disks/APIExamples/DrawText/info.json index 679dca17..2be896b0 100755 --- a/Disks/APIExamples/DrawText/info.json +++ b/Disks/APIExamples/DrawText/info.json @@ -6,5 +6,5 @@ "gpuChip": "PV8", "cartChip": "PV8", "soundChip": "PV8", - + "runnerType":"lua" } \ No newline at end of file diff --git a/Disks/PixelVisionOS/System/Tools/InfoTool/code-runner-panel.lua b/Disks/PixelVisionOS/System/Tools/InfoTool/code-runner-panel.lua index 531cbbb9..335f2187 100644 --- a/Disks/PixelVisionOS/System/Tools/InfoTool/code-runner-panel.lua +++ b/Disks/PixelVisionOS/System/Tools/InfoTool/code-runner-panel.lua @@ -12,7 +12,7 @@ local runnerInfoPanelID = "RunnerInfoPanel" function InfoTool:CreateRunnerInfoPanel() - self.runnerTypes = {"lua", "c#"} + self.runnerTypes = {"lua", "csharp"} -- Get runner setting diff --git a/Disks/PixelVisionOS/System/Tools/TextEditorTool/code-drop-down-menu.lua b/Disks/PixelVisionOS/System/Tools/TextEditorTool/code-drop-down-menu.lua index faafb891..3cd33b87 100755 --- a/Disks/PixelVisionOS/System/Tools/TextEditorTool/code-drop-down-menu.lua +++ b/Disks/PixelVisionOS/System/Tools/TextEditorTool/code-drop-down-menu.lua @@ -46,7 +46,7 @@ end function TextTool:OnRunGame() - local data = {runnerType = self.extension == ".lua" and "lua" or "c#"} + local data = {runnerType = self.extension == ".lua" and "lua" or "csharp"} print("runnerType", data["runnerType"], self.extension) diff --git a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/CodeTemplates/main-code.cs b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/CodeTemplates/main-code.cs index 59643ee4..73b83507 100644 --- a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/CodeTemplates/main-code.cs +++ b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/CodeTemplates/main-code.cs @@ -20,7 +20,7 @@ public class CustomGameChip : GameChip { public override void Init() { - BackgroundColor(12); + var message = "EMPTY C# GAME\n\n\nThis is an empty game template.\n\n\nVisit 'www.pixelvision8.com' to learn more about creating games from scratch."; var wrap = WordWrap(message, (display.X / 8) - 2); diff --git a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-drop-down-menu.lua b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-drop-down-menu.lua index ee24c37d..10a9d156 100755 --- a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-drop-down-menu.lua +++ b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-drop-down-menu.lua @@ -178,10 +178,8 @@ end function WorkspaceTool:CreateNewCodeFile(defaultPath) - local templatePath = NewWorkspacePath(ReadMetadata("RootPath", "/")).AppendDirectory(ReadMetadata("GameName", "untitled")).AppendDirectory("CodeTemplates") - defaultPath = defaultPath or self.currentPath local fileName = "code" @@ -199,26 +197,15 @@ function WorkspaceTool:CreateNewCodeFile(defaultPath) ext = data["runnerType"] ~= "lua" and ".cs" or ".lua" end - -- else + elseif(PathExists(defaultPath.AppendFile("code.cs"))) then - -- -- Create a lua file by default - -- fileName = fileName .. ".lua" + ext = ".cs" end local empty = PathExists(defaultPath.AppendFile(fileName .. ext)) - -- -- Test to see if a the code file already exists - -- fileName = (PathExists(defaultPath.AppendFile(fileName)) and "empty-" or "main-").. fileName - - - - - -- TODO read the info file - -- TODO if no info file exists, copy over the lua file - -- TODO if info file exists and is C# copy over the C# file - - print("Create new code file at", defaultPath, fileName) + print("Create new code file at", defaultPath, fileName, ext) if(empty ~= true) then @@ -241,41 +228,42 @@ function WorkspaceTool:CreateNewCodeFile(defaultPath) pixelVisionOS:OpenModal(newFileModal, function() - local newPath = UniqueFilePath(defaultPath.AppendFile(newFileModal.inputField.text .. ext)) - - CopyTo(templatePath.AppendFile("empty-" .. fileName .. ext), newPath) - -- local filePath = UniqueFilePath(defaultPath.AppendFile(newFileModal.inputField.text .. "." .. ext)) + -- Check to see if ok was pressed on the model + if(newFileModal.selectionValue == true) then - -- print("Create and rename", filePath) + local newPath = UniqueFilePath(defaultPath.AppendFile(newFileModal.inputField.text .. ext)) + + local templatePath = templatePath.AppendFile("empty-" .. fileName .. ext) - self:RefreshWindow(true) + -- TODO if this is a C# file, we need to rename the class + if(ext == ".cs") then - self:SelectFile(newPath) + local codeTemplate = ReadTextFile(templatePath) - -- local tmpPath = defaultPath.AppendFile(filePath.EntityName) + local newClassName = newPath.EntityNameWithoutExtension:sub(1,1):upper() .. newPath.EntityNameWithoutExtension:gsub('%W',' '):gsub("%W%l", string.upper):sub(2):gsub('%W','') .. "Class" - -- Check for lua files first since we always want to make them empty - -- if(ext == "lua") then + codeTemplate = codeTemplate:gsub( "CustomClass", newClassName) - -- TODO need to see if a code.lua file exists first and decide to copy template over or make an empty file - -- if(PathExists(self.currentPath.AppendFile("code.lua"))) then + print("newClassName", newClassName) + + SaveTextToFile(newPath, codeTemplate) - -- SaveText(filePath, "-- Empty code file") - -- else + else - -- CopyTo(tmpPath, filePath) - - -- end + -- Just copy the Lua template as is + CopyTo(templatePath, newPath) - -- elseif(ext == "cs") then + end - -- TODO need to see if a code.lua file exists first and decide to copy template over or make an empty file + + self:RefreshWindow(true) + + self:SelectFile(newPath) - -- SaveText(filePath, "-- Empty code file") + end - -- end end ) diff --git a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-window.lua b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-window.lua index cb1cbc56..53696cab 100755 --- a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-window.lua +++ b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/code-window.lua @@ -59,7 +59,8 @@ function WorkspaceTool:OpenWindow(path, scrollTo, selection) -- Clear the window refresh time self.refreshTime = 0 self.refreshDelay = 5 - + self.runnerType = "none" + -- Make sure the last selections are cleared self:ClearSelections() @@ -168,6 +169,7 @@ function WorkspaceTool:OpenWindow(path, scrollTo, selection) -- Reset the last start id self.lastStartID = 0 + -- TODO this shouldn't be called since it's handled in the window refresh but throws an error when taken out self:UpdateFileList() -- Update the slider @@ -184,7 +186,7 @@ function WorkspaceTool:OpenWindow(path, scrollTo, selection) -- TODO restore any selections -- Redraw the window - self:RefreshWindow() + self:RefreshWindow(true) end @@ -351,6 +353,48 @@ end function WorkspaceTool:RefreshWindow(updateFileList) + local infoPath = self.currentPath.AppendFile("info.json") + + self.runnerType = "none" + + if(PathExists(infoPath)) then + + local data = ReadJson(infoPath) + + if(data["runnerType"] ~= nil) then + + if(data["runnerType"] == "lua" and PathExists(self.currentPath.AppendFile("code.lua"))) then + + self.runnerType = "lua" + elseif(data["runnerType"] == "csharp" and PathExists(self.currentPath.AppendFile("code.cs"))) then + + self.runnerType = "csharp" + end + + elseif(PathExists(self.currentPath.AppendFile("code.cs"))) then + + self.runnerType = "csharp" + + elseif(PathExists(self.currentPath.AppendFile("code.lua"))) then + + self.runnerType = "lua" + + end + + else + + if(PathExists(self.currentPath.AppendFile("code.cs"))) then + + self.runnerType = "csharp" + + elseif(PathExists(self.currentPath.AppendFile("code.lua"))) then + + self.runnerType = "lua" + + end + + end + -- Check to see if we need to refresh the file list if(updateFileList == true) then @@ -359,6 +403,15 @@ function WorkspaceTool:RefreshWindow(updateFileList) end + + -- print("RefreshWindow", "Runner Type", self.runnerType) + + -- TODO test to see if this is a game project + + -- TODO read info file + + -- TODO determin code mode + -- Invalidate the component so it redraws at the end of the frame editorUI:Invalidate(self) @@ -568,17 +621,14 @@ function WorkspaceTool:OnWindowIconClick(id) -- Check to see if the file is an executable elseif(type == "run") then - -- TODO need to read the info file and see what runner to use - - -- TODO need to pass the main code file to the metat data + if(self.runnerType == nil) then - local metaData = { - codeFile = "code.cs" - } + -- TODO You shouldn't be able to run a game if the runnerType is not set + return - print("Load Game", dump(metaData)) + end - LoadGame(path, metaData) + LoadGame(path, { runnerType = self.runnerType }) elseif(type == "pv8") then @@ -976,8 +1026,28 @@ end function WorkspaceTool:GetIconSpriteName(item) local iconName = FileTypeMap[item.type] - -- -- print("name", name, iconName) - return iconName == nil and "fileunknown" or FileTypeMap[item.type] + + -- print("name", name, iconName) + + if(iconName == "filecodelua") then + + if(self.runnerType == "none" or self.runnerType == "csharp") then + + iconName = "filedisabledcodelua" + + end + + elseif(iconName == "filecodecsharp") then + + if(self.runnerType == "none" or self.runnerType == "lua") then + + iconName = "filedisabledcodecsharp" + + end + + end + + return iconName == nil and "fileunknown" or iconName end @@ -1077,8 +1147,6 @@ function WorkspaceTool:GetDirectoryContents(workspacePath) local srcSeg = workspacePath.GetDirectorySegments() - -- print("ValidateGameInDir", dump(srcSeg)) - local totalSeg = #srcSeg local codeFilename = "code.lua" @@ -1087,8 +1155,11 @@ function WorkspaceTool:GetDirectoryContents(workspacePath) codeFilename = "code.cs" end + local showRunner = self.runnerType ~= "none" and pixelVisionOS:ValidateGameInDir(workspacePath, {codeFilename}) + + print("self.runnerType", self.runnerType) -- Check to see if this is a game directory and we should display the run exe - if(pixelVisionOS:ValidateGameInDir(workspacePath, {codeFilename}) and self:TrashOpen() == false) then + if(showRunner and self:TrashOpen() == false) then if((srcSeg[1] == "Disks") or (srcSeg[1] == "Workspace" and totalSeg ~= 1)) then @@ -1130,7 +1201,7 @@ function WorkspaceTool:GetDirectoryContents(workspacePath) -- TODO copy 3 x 3 sprites out of it into memory - local spriteIDs = {} + -- local spriteIDs = {} self.customSpriteStartIndex = 767 diff --git a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/sb-sprites.lua b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/sb-sprites.lua index db44d14c..2b564d5c 100644 --- a/Disks/PixelVisionOS/System/Tools/WorkspaceTool/sb-sprites.lua +++ b/Disks/PixelVisionOS/System/Tools/WorkspaceTool/sb-sprites.lua @@ -16,10 +16,12 @@ cursorwait9={width=2,spriteIDs={455,456,468,469}} diskemptyopenup={width=3,spriteIDs={506,507,508,523,524,525,535,536,537}} diskemptyselectedup={width=3,spriteIDs={465,466,467,480,481,482,493,494,495}} diskemptyup={width=3,spriteIDs={424,425,426,440,441,442,452,453,454}} -filecodecsharpdisabled={width=3,spriteIDs={273,274,275,286,287,288,297,298,93}} filecodecsharpselectedup={width=3,spriteIDs={270,271,272,283,284,285,263,296,111}} filecodecsharpup={width=3,spriteIDs={267,268,269,280,281,282,294,295,93}} -filecodeluadisabled={width=3,spriteIDs={276,277,278,289,290,291,299,300,301}} +filedisabledcodecsharpselectedup={width=3,spriteIDs={270,271,272,283,284,285,263,296,111}} +filedisabledcodecsharpup={width=3,spriteIDs={273,274,275,286,287,288,297,298,93}} +filedisabledcodeluaselectedup={width=3,spriteIDs={206,207,208,235,236,237,258,259,260}} +filedisabledcodeluaup={width=3,spriteIDs={276,277,278,289,290,291,299,300,301}} filecodeluaselectedup={width=3,spriteIDs={206,207,208,235,236,237,258,259,260}} filecodeluaup={width=3,spriteIDs={138,139,140,167,168,169,190,191,192}} filecolorselectedup={width=3,spriteIDs={209,210,211,238,239,240,252,110,111}} diff --git a/Resources/Tools/WorkspaceTool/workspace-tool-design-v2.ase b/Resources/Tools/WorkspaceTool/workspace-tool-design-v2.ase index 8d13cfc5..2851c415 100755 Binary files a/Resources/Tools/WorkspaceTool/workspace-tool-design-v2.ase and b/Resources/Tools/WorkspaceTool/workspace-tool-design-v2.ase differ diff --git a/SDK/Runner/DesktopRunner.cs b/SDK/Runner/DesktopRunner.cs index a1540219..b97d6a10 100755 --- a/SDK/Runner/DesktopRunner.cs +++ b/SDK/Runner/DesktopRunner.cs @@ -936,7 +936,7 @@ public virtual void StartNextPreload() var engine = ActiveEngine as PixelVisionEngine; - if(engine != null) + if(engine != null && ((PixelVisionEngine)_tmpEngine).MetaData.ContainsKey("runnerType")) { if(engine.MetaData.ContainsKey("runnerType")) { @@ -1148,7 +1148,7 @@ public void ConfigureEngine(Dictionary metaData = null) // Console.WriteLine("Configure Runner Type " + metaData["runnerType"]); // LuaMode = Array.IndexOf(GameFiles, "code.cs") == -1; - if (metaData.ContainsKey("runnerType") && metaData["runnerType"] != "c#") + if (metaData.ContainsKey("runnerType") && metaData["runnerType"] != "csharp") { CreateLuaService(); @@ -1495,7 +1495,7 @@ public override void RunGame() { // Console.WriteLine("MetaData Code File " + metaData["runnerType"]); - ignoreExtension = metaData["runnerType"] == "c#" ? ".lua" : ".cs"; + ignoreExtension = metaData["runnerType"] == "csharp" ? ".lua" : ".cs"; } // Read the game's meta file to see if the runner is defined there else if(Array.IndexOf(GameFiles, "/Game/info.json") != -1) @@ -1509,7 +1509,7 @@ public override void RunGame() if (Json.Deserialize(json) is Dictionary data && data.ContainsKey("runnerType")) { - ignoreExtension = (string) data["runnerType"] == "c#" ? ".lua" : ".cs"; + ignoreExtension = (string) data["runnerType"] == "csharp" ? ".lua" : ".cs"; runnerType = (string) data["runnerType"]; @@ -1521,7 +1521,7 @@ public override void RunGame() // Check to see if there is a CS file because the engine will always default to that if(GameFiles.Where(p => p.EndsWith(".cs")).ToArray().Length > 0) { - runnerType = "c#"; + runnerType = "csharp"; // Console.WriteLine("File Type " + runnerType); }