This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Viz Magic is a decentralized browser-based RPG (dApp) running entirely on the VIZ blockchain. It is a static web application (HTML/CSS/ES5 JavaScript) with no build step, no server, no npm, and no framework dependencies. All game logic is deterministic and client-side. The blockchain is the source of truth.
# Serve locally (any HTTP server works)
cd app && python3 -m http.server 8123
# Or open app/index.html directly in a browserThere is no build, lint, or test command. Testing is manual via browser DevTools. The app auto-connects to VIZ blockchain nodes listed in app/js/config.js.
All code uses ES5 IIFE module pattern — no ES modules, no bundler. Each file exposes a single global variable:
var ModuleName = (function() {
'use strict';
// private state
function publicMethod() { /* ... */ }
return { publicMethod: publicMethod };
})();Modules communicate via Helpers.EventBus (pub/sub):
Helpers.EventBus.emit('navigate', 'home');
Helpers.EventBus.on('character:levelup', function(data) { /* ... */ });app/js/engine/— Deterministic game logic (state engine, combat, crafting, duels, guilds, quests, world events). This is the core of the game.state-engine.jsis the central event-sourced state machine that processes blockchain blocks into world state.app/js/ui/screens/— 18 game screens, each an IIFE module with arender()function. Screens are<section id="screen-{name}">elements shown/hidden via.activeCSS class.app/js/ui/components/— Reusable UI pieces (modal, toast, nav, progress bar, battle narrator).app/js/protocols/— Serialization for VM (game actions), VE (mutable state), V (social/Voice) protocol messages sent as VIZ custom operations.app/js/blockchain/— VIZ node connection, account auth, transaction broadcast, invite system.app/js/data/— Game content definitions: creatures, spells, recipes, regions, quests.app/js/i18n/— Localization strings (ru.js,en.js). UseHelpers.t(key, vars)for lookups.app/js/utils/— Helpers (DOM utilities, EventBus, i18n), crypto, accessibility (WCAG 2.1).app/css/—main.css(core),themes.css(light/dark via CSS variables),accessibility.css.app/lib/viz.min.js— VIZ blockchain library (only external dependency).
User Action → Validation (engine/validator.js) → VM Protocol message
→ Sign & Broadcast to VIZ chain → Block poll (every 3s)
→ block-processor.js extracts VM/VE/V ops → state-engine.js processes game logic
→ Checkpoint saved to IndexedDB → EventBus emits events → UI re-renders
- Grimoire: Character data stored on-chain in account
json_metadataunder keyvm. - Inscriptions: Game actions are JSON objects written as VIZ custom operations.
- Fate Entropy: Block hashes provide deterministic randomness for loot, duel outcomes, crafting quality.
- Checkpoint System (
engine/checkpoint.js): IndexedDB snapshots of world state for fast recovery. - Optimistic Updates: UI updates immediately, blockchain confirms within ~3 seconds.
- 4 classes: Stonewarden (tank), Embercaster (DPS), Moonrunner (evasion), Bloomsage (healer)
- 5 magic schools: Ignis, Aqua, Terra, Ventus, Umbra — with an elemental dominance wheel (1.5x/1.0x/0.7x)
- Mana: 0-10000 basis points internally, displayed as 0.00%-100.00% in UI. Full regen in 5 days.
- Duels: Commit-reveal protocol (SHA-256 sealed intent → reveal after N blocks). 4 intents: Strike/Guard/Weave/Mend.
- Leveling: XP formula
1000 * level^1.5, soft cap at level 50.
All game constants are in app/js/config.js (the VizMagicConfig module). This includes VIZ node endpoints, protocol IDs, energy/mana constants, block timing, class/school definitions, action types, and storage keys (prefix: viz_magic_).
vm-protocol-specification.md— Full VM protocol specGAME_DESIGN.md— Game design documentUX_DESIGN.md— UX design documenttests.md— Test report
- ES5 strict mode everywhere — no
let/const, no arrow functions, no template literals. - DOM access via
Helpers.$(id),Helpers.$q(selector),Helpers.$$q(selector). - All strings must be localized via
Helpers.t('key')with entries in bothi18n/ru.jsandi18n/en.js. - Screen modules export
{ render: render }and render into<section id="screen-{name}">. - Accessibility: interactive elements need
role,aria-label,aria-liveattributes. Touch targets min 48x48px.