Skip to content

Tag my items and filter the shop by them ​

A tag is a word on an item (tags: ['attack', 'early']); a TagDef names it, colours it and makes it a filter chip in the shop.

ts
// in src/items.ts
import type { ItemDef, TagDef } from '@v12-engine/engine'

export const items: ItemDef[] = [
	{ id: 'quickDagger', name: 'Quick Dagger', tier: 'basic', cost: { gold: 300 }, bonus: { percent: { attackSpeed: 0.15 } }, tags: ['attack-speed', 'early'] },
	{ id: 'keenGlass', name: 'Keen Glass', tier: 'basic', cost: { gold: 800 }, bonus: { stats: { critChance: 0.15 } }, tags: ['crit'] },
	{ id: 'wolfsbane', name: 'Wolfsbane', tier: 'intermediate', cost: { gold: 1200 }, from: ['quickDagger'], bonus: { stats: { attackDamage: 25 } }, tags: ['attack', 'anti-heal', 'jungle'] }
]

// in the rules' `tags`
export const tags: TagDef[] = [
	{ id: 'attack-speed', name: 'Attack speed', description: 'Attacks more often', color: '#e0b04f', filter: true },
	{ id: 'crit', name: 'Critical strike', color: '#e04f4f', filter: true },
	{ id: 'anti-heal', name: 'Anti-heal', description: 'Less healing for the enemies it hurts', color: '#a04060', filter: true },
	{ id: 'jungle', name: 'Jungle', description: 'Clearing creeps’ camps', color: '#6f9f3f', filter: true }
	// `attack` and `early` have no TagDef: shown as their own words, not filters
]

Done: the shop window offers Attack speed, Critical strike, Anti-heal and Jungle as chips; a click narrows the wares to items with that tag; typing #jungle finds Wolfsbane; each item's tooltip lists its tags in their colours.

Filter by what suits the hero ​

suits: ['ranger'] on an item, callings: { ranger: 3 } on the hero: the window's For this hero row and the calling chips use them (Callings). hud: { shop: { filters: false } } on the view takes the chips away; recommend: false the row.

Find them in code ​

ts
import { itemsTagged } from '@v12-engine/engine'
import { searchItems } from '@v12-engine/client/kit'

itemsTagged(world.registry, 'jungle') // [wolfsbane]
searchItems(registry, '#anti-heal', { tier: 'intermediate' }) // hits, the best first, with the letters that matched

Tag in the editor, or in data.json ​

Data › an item's Tags chips (a picker offers the tags in use); Shift+click several and Tag them; Data › Tags names them and ticks A shop's filter; Keep writes tags to data.json:

json
{ "tags": { "jungle": { "name": "Jungle", "color": "#6f9f3f", "filter": true } }, "items": { "wolfsbane": { "tags": ["attack", "anti-heal", "jungle", "late"] } } }

Tags has the whole of it; the engine's tree brings a vocabulary of seventeen you may use (The tags).