Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Adding support for correctly displaying which code files will be load…
Browse files Browse the repository at this point in the history
…ed to fix #445, #443, and #442.
  • Loading branch information
jessefreeman committed Jan 14, 2021
1 parent c1f011a commit 2266c17
Show file tree
Hide file tree
Showing 25 changed files with 141 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Content/PixelVisionOS/Tools/LoadTool/code.lua
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/AddScript/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",
"paletteMode":"false",
Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/Button/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/CalculateDistance/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/CalculateIndex/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/CalculatePosition/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/Clamp/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",
"includeLibs":"",
Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/Clear/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/Color/info.json
Expand Up @@ -8,7 +8,7 @@
"soundChip":"PV8",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/ColorsPerSprite/info.json
Expand Up @@ -9,7 +9,7 @@
"paletteMode":"false",
"buildWin":"false",
"buildExtras":"",
"runnerType":"c#",
"runnerType":"lua",
"buildMac":"false",
"buildLinux":"false",

Expand Down
2 changes: 1 addition & 1 deletion Disks/APIExamples/Display/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawPixels/info.json
Expand Up @@ -7,5 +7,5 @@
"cartChip":"PV8",
"soundChip":"PV8",
"paletteMode":"false",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawRect/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawSprite/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawSpriteBlock/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawSprites/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
2 changes: 1 addition & 1 deletion Disks/APIExamples/DrawText/info.json
Expand Up @@ -6,5 +6,5 @@
"gpuChip": "PV8",
"cartChip": "PV8",
"soundChip": "PV8",

"runnerType":"lua"
}
Expand Up @@ -12,7 +12,7 @@ local runnerInfoPanelID = "RunnerInfoPanel"

function InfoTool:CreateRunnerInfoPanel()

self.runnerTypes = {"lua", "c#"}
self.runnerTypes = {"lua", "csharp"}

-- Get runner setting

Expand Down
Expand Up @@ -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)

Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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
)

Expand Down

0 comments on commit 2266c17

Please sign in to comment.