This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
pixel-vision-os-export-game-v1.lua
executable file
·171 lines (114 loc) · 4.92 KB
/
pixel-vision-os-export-game-v1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function PixelVisionOS:OnExportGame(srcPath, closeModalCallback)
self.OnCloseBuildModalCallback = closeModalCallback
-- local srcPath = self.currentPath
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(infoFile) == 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
-- Add shared library files
-- Get all of the shared library paths
local libPath = SharedLibPaths()
-- Load libs and split
local includedLibs = string.split((metaData["includeLibs"] or ""), ",")
local test = dump(libPath)
for i = 1, #libPath do
local tmpFiles = GetEntities(libPath[i])
for i = 1, #tmpFiles do
local srcFile = tmpFiles[i]
if(srcFile.IsFile and srcFile.GetExtension() == ".lua") then
if(gameFiles[srcFile] ==nil and table.indexOf(includedLibs, srcFile.EntityNameWithoutExtension) > - 1) then
local destFile = NewWorkspacePath("/" .. srcFile.EntityName)
gameFiles[srcFile] = destFile
end
end
end
end
local response = CreateDisk(gameName, gameFiles, destPath, maxSize)
local debugResponse = dump(response)
self.buildingDisk = true
if(self.progressModal == nil) then
--
-- -- Create the model
self.progressModal = ProgressModal:Init("File Action ")
-- Open the modal
pixelVisionOS:OpenModal(self.progressModal)
pixelVisionOS:RegisterUI({name = "UpdateDiskExport"}, "UpdateDiskExport", self, true)
end
end
function PixelVisionOS:UpdateDiskExport()
-- print("UpdateDiskExport")
if(self.buildingDisk) then
local total = ReadExportPercent()
-- print("percent", total)
if(total >=100) then
-- print("Done")
self.buildingDisk = false
pixelVisionOS:CloseModal()
local response = ReadExportMessage()
local success = response.DiskExporter_success
local message = response.DiskExporter_message
local path = response.DiskExporter_path
-- print("response", dump(response))
self.progressModal = nil
-- Remove the callback from the UI update loop
pixelVisionOS:RemoveUI("UpdateDiskExport")
local buttons =
{
{
name = "modalyesbutton",
action = function(target)
target.onParentClose()
self:OpenPath(path)
-- if(self.OnCloseBuildModalCallback ~= nil) then
-- self.OnCloseBuildModalCallback(response)
-- end
end,
key = Keys.Enter,
tooltip = "Press 'enter' to apply the new chip values"
},
{
name = "modalnobutton",
action = function(target)
target.onParentClose()
end,
key = Keys.Escape,
tooltip = "Press 'esc' to not open the build folder"
}
}
pixelVisionOS:ShowMessageModal("Build " .. (success == true and "Complete" or "Failed"), message .. " Do you want to go to the new build folder?", 160, buttons)--false,
-- function()
-- if(success == true) then
-- print("Callback action when closing build after success")
-- -- self:OpenWindow(NewWorkspacePath(path).ParentPath)
-- end
-- end
-- )
else
if(self.progressModal ~= nil) then
local message = "Building new disk.\n\n\nDo not restart or shut down Pixel Vision 8."
self.progressModal:UpdateMessage(message, total/100)
end
end
end
end