Skip to content

The default set ​

The engine brings a complete item tree: six consumables, three starters, ten basics, sixteen intermediates (four of them boots), twelve legendaries and three relics, with the abilities, buffs, units and tags they use (Every default item). A game takes all of it, all but some, some changed, items of its own besides, or none, in code, in data.json or in the editor. The hero spells and the callings are sets of the same kind, chosen the same way.

Quick start ​

ts
import { defaultCallingSet, defaultHeroSpellSet, defaultItemSet, heroesPack, type Rules, useDefaults } from '@v12-engine/engine'

const own: Rules = { id: 'my-game', name: 'My game', units: [], resources: [{ id: 'gold', name: 'Gold', start: 500 }], currency: 'gold', packs: [heroesPack()] }

export const rules = useDefaults(own, [defaultItemSet, defaultHeroSpellSet(), defaultCallingSet()])

Everything of the three sets is in rules: the items with their abilities, buffs, the ward and the wolf, the tags, the hero arena stats (mobaStatsPack) and the pack of the items' own effects (defaultItemsPack) where the game had neither; the nine hero spells with their buffs; the eight callings in the heroes pack.

Common tasks ​

Take all but some ​

ts
useDefaults(own, [defaultItemSet], { items: { except: ['sightWard', 'seersDust'] } })

What a left-out item used alone goes too (its ability, its ward). A shop of yours that lists the set whole sells what you took.

Take only some ​

ts
useDefaults(own, [defaultItemSet], { items: { only: ['healingDraught', 'boots', 'ironSword', 'brutalAxe'] } })

Change some ​

ts
useDefaults(own, [defaultItemSet], {
	items: {
		// fields laid over the set's: deep, a list whole
		change: { boots: { cost: { gold: 250 } }, stoneheart: { name: 'Thornwall', suits: ['vanguard', 'reaver'] } }
	}
})
// or a function of the set's definition
useDefaults(own, [defaultItemSet], { items: { change: { kingsedge: (item) => ({ ...item, cost: { gold: 3400 } }) } } })

Add your own, or replace one of theirs ​

ts
useDefaults(own, [defaultItemSet], { items: { with: [myBlade, { ...myStoneheart, id: 'stoneheart' }] } })

A definition of yours with the id of one of the set's takes its place. Your own items in own.items come first and are never replaced by the set's.

Take none ​

ts
useDefaults(own, [defaultItemSet], { items: 'none' })

Nothing of it, not its tags either. Useful where the game has its own tree but wants the chooser (so data.json and the editor can bring the set back).

Choose again in data.json ​

json
{
	"defaults": { "items": { "except": ["sightWard"] }, "heroSpells": "all", "callings": { "only": ["vanguard", "keeper", "reaver", "ranger"] } },
	"items": { "boots": { "cost": { "gold": 250 } } },
	"tags": { "lifesteal": { "color": "#c04040", "filter": true } },
	"callings": { "vanguard": { "name": "Bulwark" } }
}

defaults lays the data's choice over the code's (all, none, only, except; your with and change stay), then the rest of the file changes what it took, as it changes anything. dataDefaultsProblem says what is wrong with it. layData(rules, dataFile) reads it.

Choose in the editor ​

Data › Default sets: for each set All of it, All but some, Only some or None: start empty, the ids in a list, New for your own; Keep writes defaults to data.json. Tags and callings have lists of their own (Data panel).

Give a hero spell or a calling set of your own ​

The same chooser takes any DefaultSet: a set of your game's that a mod or a data.json may choose from.

ts
import type { DefaultSet, ItemDef } from '@v12-engine/engine'

const relics: DefaultSet<ItemDef> = {
	id: 'relics',
	name: 'Relics of the deep',
	kind: 'items', // the field of the rules the definitions go in
	defs: [ringOfTides, drownedCrown],
	uses: { abilities: [tidesAbility], buffs: [drownedBuff] } // taken along as a chosen definition names them
}
useDefaults(own, [relics], { relics: 'all' })

A set that goes in no list of the rules gives lay(rules, defs) instead, as the callings do (defaultCallingSet remakes the heroes pack with them).

Read what was chosen ​

rules.defaults (ChosenDefaults) keeps the sets, what was chosen of each and what they added, so a later useDefaults(rules, [], { items: 'none' }) takes it out first and chooses again. chooseSet(set, choice) gives the definitions a choice takes, for your own use.

Reference ​

useDefaults(rules, sets, choices?) ​

Choice (SetChoice)What it takes
'all' (or left out)Everything
'none'Nothing
{ only: [...] }These ids
{ except: [...] }All but these
{ with: [...] }Definitions of yours besides, one with a set id in that one's place
{ change: { id: part | fn } }Fields laid over a definition (deep, a list whole), or a function of it

DefaultSet ​

FieldWhat it does
id, nameWhat a choice and the editor name it by
kindThe field of the rules its definitions go in: items, abilities, buffs, units, upgrades, races, tags, or a word of yours
defsThe definitions
usesAbilities, buffs, units and tags they use, taken along as they are named (SetUses)
packsPacks they need, added where the game has none of the id
layLays what was chosen its own way, for a set that goes in no list

The engine's sets ​

SetIdWhat it brings
defaultItemSetitemsThe fifty items, their abilities, buffs, units and tags; mobaStatsPack and defaultItemsPack
defaultHeroSpellSet()heroSpellsThe nine hero spells and their buffs (Hero spells)
defaultCallingSet()callingsThe eight callings, laid into the heroes pack (Callings)

The definitions themselves are plain lists too, for a game that wants them without the chooser: defaultItems, defaultItemTags, defaultItemAbilities, defaultItemBuffs, defaultItemUnits, defaultHeroSpells(), defaultHeroSpellBuffs(), defaultCallings().

Tests: packages/engine/tests/defaultItems.test.ts (each way of choosing, the tree's checks), packages/engine/tests/dataTagsCallings.test.ts (data.json), packages/editor/tests/itemTree.test.ts.