Skip to content

Commit

Permalink
take the export window title from the output name; webapp: drop all e…
Browse files Browse the repository at this point in the history
…xts when converting input->output and use p8.png/rom instead of .png/rom
  • Loading branch information
thisismypassport committed Oct 16, 2023
1 parent 6df9176 commit 015b3d8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
31 changes: 16 additions & 15 deletions pico_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def dump_file(m, dest, fmt, misc, i, name, cdata):
super().dump_file(dest, fmt, misc, i, name, cdata)

@classmethod
def create(cls, pico8_dat, cart=None, **_):
def create(cls, pico8_dat, cart=None, export_name="", **_):
m = PodExport(PodFile.create().data)

boot_cart = read_cart_from_source(pico8_dat.find_named(m.k_pod_names[0]).decode())
Expand All @@ -594,17 +594,16 @@ def create(cls, pico8_dat, cart=None, **_):
content = e.content

if pod_i == 1 and i == 4:
if cart:
# this one may just be a bug...
assert content.format.bpp == 8
x, y = 0, 0
pixels = content.pixels
for ch in path_no_extension(cart.name):
pixels[x, y] = ord(ch)
x += 1
if x == content.width:
x = 0
y += 1
# this is the window title - it's reinterpreted to a bitmap
assert content.format.bpp == 8
x, y = 0, 0
pixels = content.pixels
for ch in export_name + "\0":
pixels[x, y] = ord(ch)
x += 1
if x == content.width:
x = 0
y += 1

elif pod_i == 1 and i == 6:
if cart and cart.label:
Expand All @@ -621,8 +620,9 @@ def __init__(m, pico8_dat, cart):
m.cart = cart

@classmethod
def create(cls, pico8_dat, cart=None, export_name=None, **opts):
def create(cls, pico8_dat, cart=None, export_name="", **opts):
opts["cart"] = cart
opts["export_name"] = export_name

m = FullExport(pico8_dat, cart)
m.html_pod = PodFile(pico8_dat.find_named("pod/f_html5.pod"))
Expand Down Expand Up @@ -783,8 +783,6 @@ def zip_copy(zip, dir, pod, exclude=None):

dir_ensure_exists(path)
basename = m.export_name
if not basename:
basename = path_basename_no_extension(path)

label_bmpdata = None
label_icnsdata = None
Expand Down Expand Up @@ -920,6 +918,9 @@ def read_from_cart_export(path, format, cart_name=None, extra_carts=None, **opts
def write_to_cart_export(path, cart, format, extra_carts=None, cart_name=None, target_name=None, cart_op=None,
target_export=None, export_name=None, pico8_dat=None, **opts):
"""Create or edit a CartExport in the given path, depending on cart_op/cart_args arguments"""
if not export_name:
export_name = path_basename_no_extension(path)

if cart_op is None:
assert isinstance(pico8_dat, PodFile)
export = create_cart_export(format, pico8_dat, cart=cart, export_name=export_name)
Expand Down
2 changes: 1 addition & 1 deletion shrinko8.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pico_tokenize import k_hint_split_re
import argparse

k_version = 'v1.1.2e'
k_version = 'v1.1.2f'

def SplitBySeps(val):
return k_hint_split_re.split(val)
Expand Down
2 changes: 1 addition & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<option value="tiny-rom">Tiny .ROM file (Code only)</option>
<option value="url">Edu URL (Code & gfx only)</option>
<option value="" disabled>──────────</option>
<option value="bin">All HTML + Binary exports (in testing)</option>
<option value="bin">All HTML + Binary exports</option>
<option value="js">.JS file (Advanced)</option>
<option value="pod">.POD file (Advanced)</option>
</select>
Expand Down
7 changes: 5 additions & 2 deletions site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ async function saveOutputFile() {
if (ext == "tiny-rom") {
ext = "rom";
}
if (ext == "png" || ext == "rom") {
ext = "p8." + ext;
}

let name = getNoExt(inputMgr.fileName);
let name = getWithoutAllExts(inputMgr.fileName);
if (!name) {
name = "output";
}
Expand Down Expand Up @@ -591,7 +594,7 @@ async function doMinify() {
}

if (isFormatExport(format)) {
args.push("--export-name", getNoExt(inputMgr.fileName));
args.push("--export-name", getWithoutAllExts(inputMgr.fileName));
args.push("--output-cart", inputMgr.fileName);
}

Expand Down
7 changes: 4 additions & 3 deletions site/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

// Get the lowercase extension of a path
function getLowExt(path) {
let match = path.match(/\.([^\.]+)$/);
let match = path.match(/\.([^\.\/]+)$/);
return match ? match[1].toLowerCase() : "";
}

function getNoExt(path) {
let match = path.match(/(.*)\.[^\.]+$/);
// Remove all extensions of a path
function getWithoutAllExts(path) {
let match = path.match(/(.*?)\.[^\/]*$/);
return match ? match[1] : path;
}

Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ def list_set(list, i, val, defval = None):
def list_unpack(list, n, defval = None):
"""Return the 'n' first elements in the list, padding with 'defval' if needed"""
for i in range(n):
yield list_get(list, i)
yield list_get(list, i, defval)

def tuple_insert(tuple, i, newval):
"""Return a new tuple based on 'tuple' with 'newval' inserted at index 'i'"""
Expand Down

0 comments on commit 015b3d8

Please sign in to comment.