Skip to content

Commit 86a8a68

Browse files
committed
Update poki.editor_script
1 parent 82cc878 commit 86a8a68

File tree

1 file changed

+37
-156
lines changed

1 file changed

+37
-156
lines changed

poki-sdk/editor/poki.editor_script

Lines changed: 37 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,53 @@
1-
-- https://defold.com/manuals/editor-scripts/
2-
31
local M = {}
42

5-
local ui = editor.ui
6-
7-
local SETTINGS = {}
8-
9-
local function value_change_callback(id, cb)
10-
return function(value)
11-
SETTINGS[id] = value
12-
if cb then cb(id, value) end
3+
local function poki_errors(config)
4+
if not next(config.architectures) then
5+
return "At least one architecture must be selected."
136
end
147
end
158

16-
local function merge(t1, t2)
17-
local t = {}
18-
for k,v in pairs(t1 or {}) do t[k] = v end
19-
for k,v in pairs(t2 or {}) do t[k] = v end
20-
return t
21-
end
22-
23-
local function button(text, cb, props)
24-
local comp = {
25-
text = text,
26-
on_pressed = cb
27-
}
28-
return ui.text(merge(comp, props))
29-
end
30-
31-
local function label(text, props)
32-
local comp = {
33-
text = text,
34-
alignment = ui.ALIGNMENT.RIGHT
35-
}
36-
return ui.label(merge(comp, props))
37-
end
38-
39-
local function select_box(id, options, cb, props)
40-
local comp = {
41-
options = options,
42-
on_value_changed = value_change_callback(id, cb),
43-
value = options[1]
44-
}
45-
return ui.select_box(merge(comp, props))
46-
end
47-
48-
local function check_box(id, text, cb, props)
49-
local comp = {
50-
text = text,
51-
on_value_changed = value_change_callback(id, cb),
52-
value = SETTINGS[id]
53-
}
54-
return ui.check_box(merge(comp, props))
55-
end
56-
57-
local function vertical(children, props)
58-
local comp = {
59-
children = children
60-
}
61-
return ui.vertical(merge(comp, props))
62-
end
63-
64-
65-
local bundle_dialog = ui.component(function(props)
66-
local wasm_web, set_wasm_web = ui.use_state(SETTINGS.wasm_web)
67-
local js_web, set_js_web = ui.use_state(SETTINGS.js_web)
68-
69-
return ui.dialog({
70-
title = "Build and Submit for QA",
71-
header = vertical({
72-
label("Submit for Poki QA", { alignment = ui.ALIGNMENT.LEFT }),
73-
label("Proceed to submit for QA", { alignment = ui.ALIGNMENT.LEFT })
9+
local poki_bundle_dialog = editor.ui.component(function(props)
10+
local config, set_config = editor.ui.use_state(props.config)
11+
local architecture_error = poki_errors(config)
12+
return editor.bundle.dialog("Bundle and Submit for QA", config, nil, architecture_error, {
13+
editor.bundle.grid_row("Architectures", {
14+
editor.bundle.set_element_check_box(config, set_config, "architectures", "js-web", "asm.js", architecture_error),
15+
editor.bundle.set_element_check_box(config, set_config, "architectures", "wasm-web", "WebAssembly (wasm)", architecture_error)
7416
}),
75-
content = ui.grid({
76-
padding = ui.PADDING.LARGE, -- add padding around dialog edges
77-
columns = {{}, { grow = true }}, -- make 2nd column grow
78-
children = {
79-
{
80-
label("Architectures", { alignment = ui.ALIGNMENT.TOP_RIGHT}),
81-
vertical({
82-
check_box("wasm_web", "wasm-web", set_wasm_web),
83-
check_box("js_web", "js-web", set_js_web)
84-
})
85-
},
86-
{
87-
label("Variant"),
88-
select_box("variant", { "Debug", "Release" }),
89-
},
90-
{
91-
label("Texture Compression"),
92-
select_box("texture_compression", { "Enabled", "Disabled" }),
93-
},
94-
{
95-
label(""),
96-
check_box("debug_symbols", "Generate debug symbols"),
97-
},
98-
{
99-
label(""),
100-
check_box("build_report", "Generate build report"),
101-
},
102-
{
103-
label(""),
104-
check_box("live_update", "Publish Live Update content"),
105-
}
106-
}
107-
}),
108-
buttons = {
109-
ui.dialog_button({
110-
text = "Cancel",
111-
cancel = true,
112-
result = false
113-
}),
114-
ui.dialog_button({
115-
text = "Submit",
116-
default = true,
117-
result = true,
118-
enabled = (wasm_web == true) or (js_web == true),
119-
})
120-
}
17+
editor.bundle.common_variant_grid_row(config, set_config),
18+
editor.bundle.texture_compression_grid_row(config, set_config),
19+
editor.bundle.check_boxes_grid_row(config, set_config)
12120
})
12221
end)
12322

23+
local function bundle_poki(show_dialog)
24+
local config = editor.bundle.config(show_dialog, "bundle.poki", poki_bundle_dialog, poki_errors)
25+
local js = config.architectures["js-web"]
26+
local wasm = config.architectures["wasm-web"]
27+
local output_subdir = (js and wasm and "universal-web") or (js and "js-web") or "wasm-web"
28+
local output_directory = editor.bundle.output_directory(show_dialog, output_subdir)
29+
local architectures = (js and wasm and "js-web,wasm-web") or (js and "js-web") or "wasm-web"
30+
editor.bundle.create(config, output_directory, {platform = "js-web", architectures = architectures})
31+
32+
local port = 8000
33+
editor.execute("bash", "poki-sdk/editor/starthttpserver.sh", output_directory, tostring(port))
34+
--editor.browser("https://app.poki.dev/upload-defold?project=MYPROJECT&zipfile=http://127.0.0.1:" .. port .. "/poki.zip")
35+
end
12436

12537
function M.get_commands()
12638
return {
127-
{
128-
label = "Bundle for Poki QA",
129-
locations = { "View" },
130-
run = function()
131-
SETTINGS = {
132-
wasm_web = true
133-
}
134-
local result = ui.show_dialog(bundle_dialog({}))
135-
print('Perform action:', result)
136-
if result == false then
137-
return
138-
end
139-
140-
local bundle_output = "build/bundle_web"
141-
editor.delete_directory("/" .. bundle_output)
142-
editor.create_directory("/" .. bundle_output)
143-
144-
print("Bundling", SETTINGS.build_report)
145-
local options = {
146-
["archive"] = true,
147-
["verbose"] = true,
148-
["platform"] = "js-web",
149-
["architectures"] = nil,
150-
["with-symbols"] = SETTINGS.debug_symbols,
151-
["build-report-json"] = SETTINGS.build_report and "report.json" or nil,
152-
["build-report-html"] = SETTINGS.build_report and "report.html" or nil,
153-
["bundle-output"] = bundle_output,
154-
}
155-
local architectures = {}
156-
if SETTINGS.wasm_web then architectures[#architectures + 1] = "wasm-web" end
157-
if SETTINGS.js_web then architectures[#architectures + 1] = "js-web" end
158-
options.architectures = table.concat(architectures, ",")
159-
160-
editor.bob(options, "build", "bundle")
161-
print("Bundle completed")
39+
editor.bundle.command("Poki QA...", "bundle-poki", bundle_poki)
40+
}
41+
end
16242

163-
print("Starting webserver")
164-
local port = 8000
165-
editor.execute("bash", "poki-sdk/editor/starthttpserver.sh", bundle_output, tostring(port))
166-
--editor.browser("https://app.poki.dev/upload-defold?project=MYPROJECT&zipfile=http://127.0.0.1:" .. port .. "/poki.zip")
167-
print("Done")
168-
end
169-
}
43+
function M.get_prefs_schema()
44+
return {
45+
["bundle.poki"] = editor.bundle.config_schema(editor.bundle.common_variant_schema, {
46+
architectures = editor.prefs.schema.set({
47+
item = editor.prefs.schema.enum({values = {"js-web", "wasm-web"}}),
48+
default = {["wasm-web"] = true}
49+
})
50+
}),
17051
}
17152
end
17253

0 commit comments

Comments
 (0)