mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(account): web item giver with colour pickers, den variants, tints and previews
/account/items, linked from the account page and using its sign-in, gives items to the account signed in: - clothing: the item's own colours, or four colours of your own as a picker, #RRGGBB, or AJ's numbers (palette places, or the whole item's colour id signed or unsigned), converted as you type; hex colours not in the palette become an exact custom colour - den items: the variants their art has (lib/den-variants.json, made by tools/den-variants.sh) and a whole-item tint with a strength, kept in the item's version above the variant and drawn by DenItemHelper (build 83) - a preview of each: clothing icons coloured on the page as the game colours them, den items played by Ruffle in a sandboxed frame through public/item-preview.swf (tools/preview-host) a give with a custom colour id that does not exist is refused.
This commit is contained in:
1 parent
44af83f1c5
commit
7cfef493fa
18 files changed
+1958
-7
No files matched your search
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
|
||||
// pictures of items for the web item giver (public/items.html), from the
|
||||
// game's own files on the CDN:
|
||||
//
|
||||
// - clothing: the icon the game shows in a closet (item.SimpleIcon), a
|
||||
// paletted bitmap the page colours itself as the game does
|
||||
// (LayerBitmap.paintFrame), so any four colours show without asking again.
|
||||
// - den items: their art, a SWF, which public/item-preview.html plays with
|
||||
// Ruffle through public/item-preview.swf (tools/preview-host).
|
||||
//
|
||||
// both are the same for everyone, so no sign-in is asked for them.
|
||||
|
||||
const zlib = require("zlib");
|
||||
const amf3 = require("./amf3.js");
|
||||
const cdn = require("./cdn.js");
|
||||
const customItems = require("./customitems.js");
|
||||
const defpacks = require("./defpacks.js");
|
||||
|
||||
const ICON_AVATAR = 1; // the avatar every closet icon is drawn for (Item.makeSmallIcon)
|
||||
const ICON_LARGE = 25; // SimpleIcon.AN_ICON_L
|
||||
const ICON_SMALL = 26; // SimpleIcon.AN_ICON_S
|
||||
const IMAGE_VERSION = 0x7080900; // what ImageServerURL accepts
|
||||
|
||||
// DenItem.getIconId: which of an item's pictures the den shows, by its sort category.
|
||||
const iconId = sortCat => ([0, 99, 6, 5].includes(sortCat) ? 1 : sortCat === 1 ? 2 : [2, 3, 4].includes(sortCat) ? 3 : sortCat + 1);
|
||||
|
||||
// a custom item is drawn as the game's item it was made from.
|
||||
const baseIdOf = (kind, id) => {
|
||||
const entry = customItems.get(kind, id);
|
||||
return entry ? entry.base : Number(id);
|
||||
};
|
||||
|
||||
// a clothing item's closet icon, large if there is one: {w, h, b} with b the
|
||||
// first frame's run-length bytes, base64 (LayerBitmap.paintFrame reads them).
|
||||
// null when it has none.
|
||||
const clothingIcon = async id => {
|
||||
const def = defpacks.itemDef(id);
|
||||
if (!def || !Number.isInteger(Number(def.layerDefId))) {
|
||||
return null;
|
||||
}
|
||||
for (const size of [ICON_LARGE, ICON_SMALL]) {
|
||||
const file = await cdn.get(cdn.hashedPath(`imageArrays/${((ICON_AVATAR << 24) | (size << 16) | Number(def.layerDefId)) >>> 0}`));
|
||||
try {
|
||||
const image = file && amf3.decode(zlib.inflateSync(file));
|
||||
const frame = image && image.v === IMAGE_VERSION && Array.isArray(image.f) && image.f[0];
|
||||
if (frame && Buffer.isBuffer(frame.b) && frame.w > 0 && frame.h > 0) {
|
||||
return {w: frame.w, h: frame.h, b: frame.b.toString("base64")};
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
// not an icon this can read: the next size, or none.
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// a den item's art as the SWF it holds, or null.
|
||||
const denArt = async id => {
|
||||
const def = defpacks.denItemDef(id);
|
||||
const baseId = baseIdOf("den", id);
|
||||
const baseDef = defpacks.denItemDef(baseId);
|
||||
if (!def || !baseDef) {
|
||||
return null;
|
||||
}
|
||||
const file = await cdn.get(cdn.hashedPath(`items/${((baseId << 16) | iconId(Number(baseDef.sortCat))) >>> 0}`));
|
||||
try {
|
||||
const wrapped = file && amf3.decode(file);
|
||||
return wrapped && wrapped.ba ? Buffer.from(wrapped.ba) : null;
|
||||
}
|
||||
catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {clothingIcon, denArt};
|
||||
Reference in new issue
Block a user