Module:ItemBox: Difference between revisions

Vergir (talk | contribs)
Add variants() for stable per-item texture variety (replaces nth-child); add font-table regen recipe to header (with help from vergir-bot LLM)
Vergir (talk | contribs)
m comments update
Line 4: Line 4:
-- ============================================================================
-- ============================================================================
--  Retail Demo (bold) glyph advance widths, in em of the font size.
--  Retail Demo (bold) glyph advance widths, in em of the font size.
--  unitsPerEm = 1000. Measured from File:Retaildemo-bold.woff2
--  unitsPerEm = 1000. Measured from /images/d/d5/Retaildemo-bold.woff2
--  ( /images/d/d5/Retaildemo-bold.woff2 ), the bold face used by .itembox-name.
--   Table can be regenerated with fontforge / fonttools
--
-- THIS TABLE IS FONT-SPECIFIC. If that file is re-uploaded with different
--  metrics, name fitting drifts. Regenerate the table with:
--
--    curl -o rd.woff2 https://deadlock.wiki/images/d/d5/Retaildemo-bold.woff2
--    fontforge -lang=py -c 'import fontforge;f=fontforge.open("rd.woff2");f.generate("rd.ttf")'
--    python3 - << 'PY'
--    from fontTools.ttLib import TTFont; import string
--    f=TTFont("rd.ttf"); upm=f["head"].unitsPerEm; hm=f["hmtx"]; uni={}
--    for t in f["cmap"].tables:
--        if t.isUnicode():
--            for cp,gn in t.cmap.items(): uni.setdefault(cp,gn)
--    for c in string.ascii_uppercase+string.ascii_lowercase+string.digits+" ":
--        gn=uni.get(ord(c))
--        if gn: print(f'    ["{c}"]={hm[gn][0]/upm:.3f},')
--    PY
-- ============================================================================
-- ============================================================================
local WIDTH = {
local WIDTH = {
Line 120: Line 104:
end
end


-- Stable per-item texture variety, replacing position-dependent :nth-child.
-- User for stable per-item texture variety
-- A djb2 hash of the (language-independent) code name picks one of each of the
-- icon-mask / wear / paper-texture variants. Same item -> same look everywhere.
local function hash(s)
local function hash(s)
     local h = 5381
     local h = 5381