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

Commit

Permalink
Rebuilding Info Tool to support switching between C# and Lua Runners.…
Browse files Browse the repository at this point in the history
… Also mfixed issues in text editor with saving, showing line numbers, and highlighting call backs.
  • Loading branch information
jessefreeman committed Jan 6, 2021
1 parent 477772a commit d95280a
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 260 deletions.
Expand Up @@ -17,7 +17,7 @@ function EditorUI:CreateTextEditor(rect, text, toolTip, font, colorOffset)
comment = 6, --
string = 11, --
api = 7, --
callback = 15, --
callback = 8, --
escape = 15, --
disabled = 5, --
}
Expand Down
222 changes: 222 additions & 0 deletions Disks/PixelVisionOS/System/Tools/InfoTool/code-build-panel.lua
@@ -0,0 +1,222 @@
--[[
Pixel Vision 8 - Draw Tool
Copyright (C) 2017, Pixel Vision 8 (http://pixelvision8.com)
Created by Jesse Freeman (@jessefreeman)
Please do not copy and distribute verbatim copies
of this license document, but modifications without
distributing is allowed.
]]--

local buildInfoPanelID = "BuildInfoPanel"

function InfoTool:CreateBuildInfoPanel()

local buildFlagWin = editorUI:CreateToggleButton({x = 200, y = 176+ 24, w = 8, h = 8}, "checkbox", "Create a Windows executable.")

buildFlagWin.onAction = function(value)

self:InvalidateData()

end

local winRunnerExists = PathExists(NewWorkspacePath(self.buildTemplatePaths[1].path))

if(winRunnerExists) then
editorUI:ToggleButton(buildFlagWin, gameEditor:ReadMetadata(self.buildFlagLabels[1]) == "true")
end

editorUI:Enable(buildFlagWin, winRunnerExists)

table.insert(self.buildFlagCheckboxes, buildFlagWin)

local buildFlagMac = editorUI:CreateToggleButton({x = 200, y = 184+ 24, w = 8, h = 8}, "checkbox", "Create a Mac App.")


buildFlagMac.onAction = function(value)

self:InvalidateData()

end

local macRunnerExists = PathExists(NewWorkspacePath(self.buildTemplatePaths[2].path))

if(macRunnerExists) then
editorUI:ToggleButton(buildFlagMac, gameEditor:ReadMetadata(self.buildFlagLabels[2]) == "true")
end

editorUI:Enable(buildFlagMac, macRunnerExists)

table.insert(self.buildFlagCheckboxes, buildFlagMac)

local buildFlagLinux = editorUI:CreateToggleButton({x = 200, y = 192+ 24, w = 8, h = 8}, "checkbox", "Create a Linux executable.")

buildFlagLinux.onAction = function(value)

self:InvalidateData()

end

local linuxRunnerExists = PathExists(NewWorkspacePath(self.buildTemplatePaths[3].path))

if(linuxRunnerExists) then
editorUI:ToggleButton(buildFlagLinux, gameEditor:ReadMetadata(self.buildFlagLabels[3]) == "true")
end

editorUI:Enable(buildFlagLinux, linuxRunnerExists)


table.insert(self.buildFlagCheckboxes, buildFlagLinux)


local buildFlagExtras = editorUI:CreateToggleButton({x = 200, y = 208, w = 8, h = 8}, "checkbox", "Create a Linux executable.")

editorUI:ToggleButton(buildFlagExtras, gameEditor:ReadMetadata(self.buildFlagLabels[4]) == "true")

buildFlagExtras.onAction = function(value)

self:InvalidateData()

end

-- These UI elements live outside of the panel

self.buildButtonData = editorUI:CreateButton({x = 216, y = 32}, "buildbutton", "Build the game disk.")
self.buildButtonData.onAction = function(value)

self.libFilesToCopy = {}

for i = 1, #self.filePaths do
-- print("Include", dump(filePaths[i]))
if(self.filePaths[i].selected == true) then

table.insert(self.libFilesToCopy, self.filePaths[i].name)
end
end

-- buildFlagWin

pixelVisionOS:ShowMessageModal("Build Game", "Are you sure you want to build ".. self.nameInputData.text .."'? This will create a new PV8 disk and executables for any selected platforms.", 160, true,
function()

if(pixelVisionOS.messageModal.selectionValue == true) then

self:OnExportGame()
-- TODO need to call the build function
-- OnInstall()

end

end
)

end

-- self.cleanCheckboxData = editorUI:CreateToggleButton({x = 216, y = 56, w = 8, h = 8}, "radiobutton", "Toggles doing a clean build and removes all previous builds.")

-- editorUI:ToggleButton(self.cleanCheckboxData, gameEditor:ReadMetadata("clear", "false") == "true", false)

-- self.cleanCheckboxData.onAction = function(value)

-- -- print("Clean build", value)

-- if(value == false) then
-- self:InvalidateData()
-- return
-- end

-- pixelVisionOS:ShowMessageModal("Warning", "Are you sure you want to do a clean build? This will delete the build directory before creating the PV8 disk. Old builds will be deleted. This can not be undone.", 160, true,
-- function()


-- if(pixelVisionOS.messageModal.selectionValue == false) then

-- -- Force the checkbox back into the false state
-- editorUI:ToggleButton(self.cleanCheckboxData, false, false)

-- else
-- -- Force the checkbox back into the false state
-- editorUI:ToggleButton(self.cleanCheckboxData, true, false)
-- end

-- -- Force the button to redraw since restoring the modal will show the old state
-- editorUI:Invalidate(self.cleanCheckboxData)
-- self:InvalidateData()
-- end
-- )

-- end


pixelVisionOS:RegisterUI({name = buildInfoPanelID}, "BuildInfoPanelUpdate", self)

end

function InfoTool:BuildInfoPanelUpdate()

for i = 1, #self.buildFlagCheckboxes do
editorUI:UpdateButton(self.buildFlagCheckboxes[i])
end

editorUI:UpdateButton(self.buildButtonData)
-- editorUI:UpdateButton(self.cleanCheckboxData)

end

function InfoTool:OnExportGame()

local srcPath = NewWorkspacePath(self.rootDirectory)
local destPath = srcPath.AppendDirectory("Builds")
local infoFile = srcPath.AppendFile("info.json")
local dataFile = srcPath.AppendFile("data.json")

-- TODO need to read game name from info file
if(PathExists(srcPath.AppendDirectory("info.json")) == false) then
SaveText(infoFile, "{\"name\":\""..srcPath.EntityName.."\"}")
end

local metaData = ReadJson(infoFile)

local gameName = (metaData ~= nil and metaData["name"] ~= nil) and metaData["name"] or srcPath.EntityName


local systemData = ReadJson(dataFile)

local maxSize = 512

if(systemData["GameChip"]) then

if(systemData["GameChip"]["maxSize"]) then
maxSize = systemData["GameChip"]["maxSize"]
end
end

-- Manually create a game disk from the current folder's files
local srcFiles = GetEntities(srcPath)
local pathOffset = #srcPath.Path

local gameFiles = {}

for i = 1, #srcFiles do
local srcFile = srcFiles[i]
local destFile = NewWorkspacePath(srcFile.Path:sub(pathOffset))
gameFiles[srcFile] = destFile
end

local response = CreateDisk(gameName, gameFiles, destPath, maxSize)

self.buildingDisk = true

if(self.progressModal == nil) then
--
-- -- Create the model
self.progressModal = ProgressModal:Init("File Action ", editorUI)

-- Open the modal
pixelVisionOS:OpenModal(self.progressModal)

end

-- end

end
106 changes: 102 additions & 4 deletions Disks/PixelVisionOS/System/Tools/InfoTool/code-drop-down-menu.lua
Expand Up @@ -8,13 +8,12 @@
distributing is allowed.
]]--

function InfoTool:CreateDropDownMenu()
SaveShortcut = 5

-- Get a list of all the editors
local editorMapping = pixelVisionOS:FindEditors()
function InfoTool:CreateDropDownMenu()

-- Find the json editor
self.textEditorPath = editorMapping["json"]
self.textEditorPath = pixelVisionOS:FindEditors()["json"]

local menuOptions =
{
Expand All @@ -31,3 +30,102 @@ function InfoTool:CreateDropDownMenu()
pixelVisionOS:CreateTitleBarMenu(menuOptions, "See menu options for this tool.")

end

function InfoTool:OnEditJSON()

if(self.invalid == true) then

pixelVisionOS:ShowMessageModal("Unsaved Changes", "You have unsaved changes. Do you want to save your work before you edit the raw data file?", 160, true,
function()

if(pixelVisionOS.messageModal.selectionValue == true) then
-- Save changes
self:OnSave()

end

-- Quit the tool
self:EditJSON()

end
)

else
-- Quit the tool
self:EditJSON()
end

end

function InfoTool:EditJSON()

local metaData = {
directory = self.rootDirectory,
file = self.rootDirectory .. "info.json",
}

LoadGame(self.textEditorPath, metaData)

end

function InfoTool:OnQuit()

if(self.invalid == true) then

pixelVisionOS:ShowMessageModal("Unsaved Changes", "You have unsaved changes. Do you want to save your work before you edit the raw data file?", 160, true,
function()

if(pixelVisionOS.messageModal.selectionValue == true) then
-- Save changes
self:OnSave()

end

-- Quit the tool
QuitCurrentTool()

end
)

else
-- Quit the tool
QuitCurrentTool()
end

end

function InfoTool:OnSave()

local flags = {SaveFlags.Meta}

local includeString = ""

for i = 1, #self.filePaths do

local file = self.filePaths[i]

if(file.selected == true) then
includeString = includeString .. file.name .. ","
end

end

-- gameEditor:WriteMetadata("clear", tostring(self.cleanCheckboxData.selected))

gameEditor:WriteMetadata("runnerType", self.runnerType)

gameEditor:WriteMetadata("includeLibs", includeString:sub(1, - 2))

-- Add the build flags
for i = 1, #self.buildFlagCheckboxes do
gameEditor:WriteMetadata(self.buildFlagLabels[i], tostring(self.buildFlagCheckboxes[i].selected))
end

gameEditor:Save(self.rootDirectory, flags)

-- Display that the data was saved and reset invalidation
pixelVisionOS:DisplayMessage("The game's 'data.json' file has been updated.", 5)

self:ResetDataValidation()

end

0 comments on commit d95280a

Please sign in to comment.