Files
wownerogue/html/js/render/catSprites.js
T
jwinterm cdd379c5e4 feat(render): composite object tiles over a base tile (pipeline) + bigger cat
The black boxes around furniture/windows were transparent object tiles drawn
straight onto the dark canvas. Fix at the pipeline level, not as a tavern one-off:

- tileRenderer: a tile kind whose legend declares `over` (the ground it sits on)
  now draws that base tile FIRST, then the object on top — so the object's
  transparent areas show the floor/wall. Works for any scene, atlas or flat-colour
  fallback. Wall-grounding shadow strip now only applies to real walls, not objects.
- sceneModel TAVERN_LEGEND: declares over='floor' for bar/keg/shelf/table/chair/
  barrel/crate/rug and over='wall' for windows.
- catSprites: the cat occupies ~40% of its 50x50 frame, so scale to ~2x the cell
  and centre it — it now reads about tile-sized instead of tiny.

Client-only. Suite 57 suites / 413 tests green.
2026-07-11 07:07:55 -04:00

47 lines
1.9 KiB
JavaScript

(function (root) {
'use strict';
var RK = root.RK = root.RK || {};
// Pet Cats Pack (CC-0). Each idle strip is 10 frames of 50x50 laid out horizontally.
var FRAMES = 10, FW = 50, FH = 50, FRAME_MS = 150;
var CATS = ['cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6'];
var images = {};
function imgFor(id) {
if (!CATS.includes(id)) id = 'cat3';
if (!images[id]) {
var im = new Image();
im.src = 'assets/cats/' + id + '-idle.png';
images[id] = im;
}
return images[id];
}
RK.catIds = function () { return CATS.slice(); };
RK.randomCatId = function () { return CATS[Math.floor(Math.random() * CATS.length)]; };
RK.isCat = function (id) { return CATS.indexOf(id) !== -1; };
// Draw an animated cat centered in its cell, feet near the bottom of the tile. Flips to face left.
RK.drawCatCanvas = function (ctx, e, cell, now) {
var im = imgFor(e.catSprite || 'cat3');
if (!im.complete || !im.naturalWidth) return false;
var frame = Math.floor((now || 0) / FRAME_MS) % FRAMES;
var sx = frame * FW;
// The cat occupies only ~40% of its 50x50 frame (lots of transparent padding), so scale
// the frame to ~2x the cell and centre it — the visible cat then reads about tile-sized.
var size = cell * 2.0;
var dx = e.x * cell + (cell - size) / 2;
var dy = e.y * cell + (cell - size) / 2 + cell * 0.2; // centred, nudged down onto the tile
ctx.save();
ctx.imageSmoothingEnabled = false;
if (e.facing === 'left') {
ctx.translate(dx + size, dy); ctx.scale(-1, 1);
ctx.drawImage(im, sx, 0, FW, FH, 0, 0, size, size);
} else {
ctx.drawImage(im, sx, 0, FW, FH, dx, dy, size, size);
}
ctx.restore();
return true;
};
})(window);