diff --git a/.prosperon/imgui.ini b/.prosperon/imgui.ini deleted file mode 100644 index 6c933f2e..00000000 --- a/.prosperon/imgui.ini +++ /dev/null @@ -1,183 +0,0 @@ -[Window][Debug##Default] -Pos=60,60 -Size=400,400 - -[Window][TEST WINDOW] -Pos=156,6 -Size=366,275 - -[Window][editor] -Pos=558,248 -Size=274,177 - -[Window][Editor] -Pos=-113,317 -Size=184,174 - -[Window][Map Editor] -Pos=96,74 -Size=312,398 - -[Window][Edit Tile] -Pos=120,99 -Size=356,275 - -[Window][Level Editor] -Pos=60,45 -Size=283,332 -Collapsed=1 - -[Window][Brush Selector] -Pos=189,35 -Size=203,474 -Collapsed=1 - -[Window][Tool Selector] -Pos=300,25 -Size=247,474 -Collapsed=1 - -[Window][FPS: 12] -Pos=60,60 -Size=32,35 - -[Window][FPS: 87] -Pos=60,60 -Size=32,35 - -[Window][FPS: 59] -Pos=60,60 -Size=32,35 - -[Window][FPS: 107] -Pos=60,60 -Size=32,35 - -[Window][FPS: 135] -Pos=60,60 -Size=32,35 - -[Window][FPS: 136] -Pos=60,60 -Size=51,48 - -[Window][FPS: 140] -Pos=60,60 -Size=51,48 - -[Window][FPS: 137] -Pos=60,60 -Size=51,48 - -[Window][FPS: 138] -Pos=60,60 -Size=51,48 - -[Window][FPS: 141] -Pos=60,60 -Size=51,48 - -[Window][FPS: 143] -Pos=60,60 -Size=51,48 - -[Window][FPS: 142] -Pos=60,60 -Size=51,48 - -[Window][FPS: 144] -Pos=60,60 -Size=32,35 - -[Window][FPS: 139] -Pos=60,60 -Size=51,48 - -[Window][FPS: 133] -Pos=60,60 -Size=32,35 - -[Window][FPS: 134] -Pos=60,60 -Size=51,48 - -[Window][FPS: 131] -Pos=60,60 -Size=51,48 - -[Window][FPS: 130] -Pos=60,60 -Size=51,48 - -[Window][FPS: 128] -Pos=60,60 -Size=51,48 - -[Window][FPS: 126] -Pos=60,60 -Size=51,48 - -[Window][FPS: 123] -Pos=60,60 -Size=32,35 - -[Window][FPS: 124] -Pos=60,60 -Size=32,35 - -[Window][FPS: 121] -Pos=60,60 -Size=32,35 - -[Window][FPS: 122] -Pos=60,60 -Size=32,35 - -[Window][FPS: 119] -Pos=60,60 -Size=51,48 - -[Window][FPS: 117] -Pos=60,60 -Size=32,35 - -[Window][FPS: 118] -Pos=60,60 -Size=32,35 - -[Window][FPS: 116] -Pos=60,60 -Size=32,35 - -[Window][FPS: 108] -Pos=60,60 -Size=32,35 - -[Window][FPS: 109] -Pos=60,60 -Size=51,48 - -[Window][FPS: 115] -Pos=60,60 -Size=51,48 - -[Window][FPS: 114] -Pos=60,60 -Size=51,48 - -[Window][FPS: 113] -Pos=60,60 -Size=51,48 - -[Window][FPS: 110] -Pos=60,60 -Size=51,48 - -[Window][FPS: 112] -Pos=60,60 -Size=51,48 - -[Window][FPS: 111] -Pos=60,60 -Size=51,48 - diff --git a/prosperon/clay.cm b/prosperon/clay.cm index 2ea7cbc2..4ee26c94 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -283,6 +283,7 @@ clay.draw_commands = function draw_commands(cmds, pos = {x:0,y:0}) if (config.text) draw.text(config.text, content, config.font, config.color, config.size.width) + if (config.image) draw.image(config.image, content, 0, config.color) } diff --git a/scripts/graphics.cm b/scripts/graphics.cm index 7381ba20..acab9a2f 100644 --- a/scripts/graphics.cm +++ b/scripts/graphics.cm @@ -300,16 +300,73 @@ graphics.texture = function texture(path) { if (typeof path != 'string') throw new Error('need a string for graphics.texture') - var id = path //.split(':')[0] - if (cache[id]) return cache[id] + var parts = path.split(':') + var id = parts[0] + var animName = parts[1] + var frameIndex = parts[2] - var ipath = res.find_image(id) - if (!ipath) - throw new Error(`unknown image ${id}`) + if (!cache[id]) { + var ipath = res.find_image(id) + if (!ipath) + throw new Error(`unknown image ${id}`) + + var result = create_image(ipath) + cache[id] = result + } - var result = create_image(ipath) - cache[id] = result - return result // Can be Image, animation, or collection of animations + var cached = cache[id] + + // No further path specifiers - return the whole thing + if (!animName) return cached + + // If cached is a single Image, treat it as a single-frame animation + if (cached instanceof graphics.Image) { + if (frameIndex != null) { + // For single images, any frame index just returns the image + return cached + } + // animName without frameIndex for single image - return the image + return cached + } + + // If cached is a single animation (has .frames property) + if (cached.frames && Array.isArray(cached.frames)) { + if (frameIndex != null) { + var idx = parseInt(frameIndex) + if (isNaN(idx)) return cached + // Wrap the index + idx = idx % cached.frames.length + return cached.frames[idx].image + } + // Just animation name for single animation - return the animation + return cached + } + + // If cached is an object of multiple animations + if (typeof cached == 'object' && !cached.frames) { + var anim = cached[animName] + if (!anim) + throw new Error(`animation ${animName} not found in ${id}`) + + if (frameIndex != null) { + var idx = parseInt(frameIndex) + if (isNaN(idx)) return anim + + if (anim instanceof graphics.Image) { + // Single image animation - any frame index returns the image + return anim + } else if (anim.frames && Array.isArray(anim.frames)) { + // Multi-frame animation - wrap the index + idx = idx % anim.frames.length + return anim.frames[idx].image + } + } + + // Just animation name - return the animation + return anim + } + + return cached } graphics.texture[cell.DOC] = ` :param path: A string path to an image file or an already-loaded image object.