This commit is contained in:
2026-01-06 20:25:55 -06:00
parent 50bee7a5c0
commit 0522b967ca
21 changed files with 724 additions and 1244 deletions

View File

@@ -161,12 +161,12 @@ function create_image(path){
var raw = decode_image(bytes, ext);
/* ── Case A: single surface (from make_texture) ────────────── */
if(raw && raw.width && raw.pixels && !isa(raw, array)) {
if(raw && raw.width && raw.pixels && !is_array(raw)) {
return new graphics.Image(raw)
}
/* ── Case B: array of surfaces (from make_gif) ────────────── */
if(isa(raw, array)) {
if(is_array(raw)) {
// Single frame GIF returns array with one surface
if(raw.length == 1 && !raw[0].time) {
return new graphics.Image(raw[0])
@@ -175,16 +175,16 @@ function create_image(path){
return makeAnim(wrapFrames(raw), true);
}
if(typeof raw == 'object' && !raw.width) {
if(is_object(raw) && !raw.width) {
if(raw.surface)
return new graphics.Image(raw.surface)
if(raw.frames && isa(raw.frames, array) && raw.loop != null)
if(raw.frames && is_array(raw.frames) && raw.loop != null)
return makeAnim(wrapFrames(raw.frames), !!raw.loop);
def anims = {};
for(def [name, anim] of Object.entries(raw)){
if(anim && isa(anim.frames, array))
if(anim && is_array(anim.frames))
anims[name] = makeAnim(wrapFrames(anim.frames), !!anim.loop);
else if(anim && anim.surface)
anims[name] = new graphics.Image(anim.surface);
@@ -250,7 +250,7 @@ graphics.from_surface = function(surf)
graphics.from = function(id, data)
{
if (typeof id != 'string')
if (!is_text(id))
throw new Error('Expected a string ID')
if (data instanceof ArrayBuffer)
@@ -260,7 +260,7 @@ graphics.from = function(id, data)
graphics.texture = function texture(path) {
if (path instanceof graphics.Image) return path
if (typeof path != 'string')
if (!is_text(path))
throw new Error('need a string for graphics.texture')
var parts = path.split(':')
@@ -269,7 +269,7 @@ graphics.texture = function texture(path) {
var frameIndex = parts[2]
// Handle the case where animName is actually a frame index (e.g., "gears:0")
if (animName != null && frameIndex == null && !isa(number(animName), null)) {
if (animName != null && frameIndex == null && !is_null(number(animName))) {
frameIndex = number(animName)
animName = null
}
@@ -294,7 +294,7 @@ graphics.texture = function texture(path) {
// Handle frame index without animation name (e.g., "gears:0")
if (!animName && frameIndex != null) {
// If cached is a single animation (has .frames property)
if (cached.frames && isa(cached.frames, array)) {
if (cached.frames && is_array(cached.frames)) {
var idx = number(frameIndex)
if (idx == null) return cached
// Wrap the index
@@ -318,7 +318,7 @@ graphics.texture = function texture(path) {
}
// If cached is a single animation (has .frames property)
if (cached.frames && isa(cached.frames, array)) {
if (cached.frames && is_array(cached.frames)) {
if (frameIndex != null) {
var idx = number(frameIndex)
if (isNaN(idx)) return cached
@@ -331,7 +331,7 @@ graphics.texture = function texture(path) {
}
// If cached is an object of multiple animations
if (typeof cached == 'object' && !cached.frames) {
if (is_object(cached) && !cached.frames) {
var anim = cached[animName]
if (!anim)
throw new Error(`animation ${animName} not found in ${id}`)
@@ -343,7 +343,7 @@ graphics.texture = function texture(path) {
if (anim instanceof graphics.Image) {
// Single image animation - any frame index returns the image
return anim
} else if (anim.frames && isa(anim.frames, array)) {
} else if (anim.frames && is_array(anim.frames)) {
// Multi-frame animation - wrap the index
idx = idx % anim.frames.length
return anim.frames[idx].image
@@ -412,8 +412,8 @@ var fontcache = {}
var datas = []
graphics.get_font = function get_font(path) {
if (isa(path, object)) return path
if (!isa(path, text))
if (is_object(path)) return path
if (!is_text(path))
throw new Error(`Can't find font with path: ${path}`)
var parts = path.split('.')