Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions poki-sdk/editor/poki.editor_script
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
local M = {}

local POKI_ZIP = "poki.zip"
local POKI_HTML5_OUTPUT = "build/default_html5/"
local POKI_HTML5_LAUNCH_DIR = POKI_HTML5_OUTPUT .. "__htmlLaunchDir"
local POKI_INSPECTOR = "https://inspector.poki.dev/"

local function project_title()
return editor.get("/game.project", "project.title")
end

-- https://help.interfaceware.com/code/details/urlcode-lua
local function urlencode(str)
Expand Down Expand Up @@ -31,7 +38,7 @@ local poki_bundle_dialog = editor.ui.component(function(props)
end)

local function bundle_poki(show_dialog)
local project_title = editor.get("/game.project", "project.title")
local title = project_title()

local config = editor.bundle.config(show_dialog, "bundle.poki", poki_bundle_dialog, poki_errors)
local js = config.architectures["js-web"]
Expand All @@ -43,16 +50,61 @@ local function bundle_poki(show_dialog)

-- zip bundle output directory
zip.pack(POKI_ZIP, {
{ output_directory .. "/" .. project_title, project_title }
{ output_directory .. "/" .. title, title }
})

-- browse to poki uploader
local urlfmt = "https://app.poki.dev/upload-defold?project=%s&zipfile=http://127.0.0.1:%s/poki/%s"
local url = string.format(urlfmt, urlencode(project_title), http.server.port, POKI_ZIP)
local url = string.format(urlfmt, urlencode(title), http.server.port, POKI_ZIP)
print("Opening", url)
editor.browse(url)
end

local function ensure_directory(path)
if not editor.external_file_attributes(path).exists then
if editor.platform:sub(-#"win32") == "win32" then
editor.execute("cmd.exe", "/c", "mkdir", path:gsub("/", "\\"), {reload_resources = false})
else
editor.execute("mkdir", "-p", path, {reload_resources = false})
end
end
return editor.external_file_attributes(path).path
end

local function build_poki_html5()
local title = project_title()
local launch_dir = ensure_directory(POKI_HTML5_LAUNCH_DIR)
ensure_directory(launch_dir .. "/" .. title)
ensure_directory(POKI_HTML5_OUTPUT)
local build_server = editor.prefs.get("extensions.build-server")
if build_server == nil or build_server == "" then
build_server = "https://build.defold.com"
end
local bob_opts = {
architectures = "wasm-web",
output = POKI_HTML5_OUTPUT,
auth = "",
email = "",
root = editor.external_file_attributes(".").path,
build_server = build_server,
archive = true,
texture_compression = editor.prefs.get("build.texture-compression"),
bundle_output = launch_dir,
platform = "js-web",
verbose = true,
variant = "debug",
defoldsdk = "cddb6eb43c32e4930257fcbbb30f19cf28deb081",
}

editor.bob(bob_opts, "build", "bundle")

local url = string.format("%s%s", http.server.url, "/html5")
url = url:gsub("0%.0%.0%.0", "localhost")
local open_url = POKI_INSPECTOR.."?game=external-"..url
print("Open:"..open_url)
editor.browse(open_url)
end

function M.get_http_server_routes()
return {
http.server.route("/poki/" .. POKI_ZIP, "GET", function(request)
Expand All @@ -67,6 +119,14 @@ end

function M.get_commands()
return {
editor.command({
label = "Build Poki HTML5",
id = "poki.build-html5",
locations = { "Project" },
run = function()
build_poki_html5()
end
}),
editor.bundle.command("Poki", "bundle-poki", bundle_poki)
}
end
Expand All @@ -82,4 +142,4 @@ function M.get_prefs_schema()
}
end

return M
return M
2 changes: 1 addition & 1 deletion poki-sdk/manifests/web/engine_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<link rel="dns-prefetch" href="//api.poki.com" />
<link rel="dns-prefetch" href="//a.poki-cdn.com" />
<script defer src="//game-cdn.poki.com/scripts/v2/poki-sdk.js" onload="poki_sdk_loaded()"></script>
<script defer src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js" onload="poki_sdk_loaded()"></script>
</head>

<body>
Expand Down
Loading