damdara
v0.8.4
Published
Dragon Quest Core Module, created in Rust.
Downloads
102
Maintainers
Readme
Damdara WASM
Dragon Quest core module compiled to WebAssembly. Experience the classic "Fukkatsu no Jumon" (Revival Password) system and turn-based battle mechanics in your browser or Node.js application.
Features
- 🔐 Password System - Generate and decode 20-character hiragana passwords
- ⚔️ Battle System - Turn-based combat with monsters
- 📊 Character Management - Player stats, equipment, and progression
- 🎮 Master Data - Complete database of monsters, items, spells, and equipment
- 🦀 Pure Rust - Compiled to WebAssembly for performance
- 📦 Zero Dependencies - Standalone WASM module
Installation
npm install damdaraor
yarn add damdaraUsage
Basic Example
import init, { WasmGame } from 'damdara';
// Initialize the WASM module
await init();
// Create a new game instance
const game = new WasmGame();
// Create a player
const playerState = game.create_player("ゆうてい");
console.log(playerState);
// {
// summary: { name: "ゆうてい", level: 1, hp: 15, mp: 0, ... },
// strength_status: { strength: 4, agility: 4, ... },
// items: []
// }Password System
// Generate a password from current player state
const password = game.generate_password();
console.log(password); // "あいうえお..." (20 hiragana characters)
// Load player from password
const loadedState = game.load_from_password("あいうえおかきくけこ...");
console.log(loadedState);Battle System
// Queue battle actions
game.queue_battle_action("attack");
game.queue_battle_action("attack");
game.queue_battle_action("spell");
game.queue_battle_input(1); // Spell selection
// Run battle against monster ID 0 (Slime)
const result = game.run_battle(0);
console.log(result);
// {
// player_survived: true,
// monster_defeated: true,
// player_escaped: false,
// monster_escaped: false,
// messages: ["スライムがあらわれた!", ...],
// final_player_state: { ... }
// }Master Data Access
// Get all monsters
const monsters = game.get_monsters();
console.log(monsters);
// [
// { id: 0, name: "スライム", hp: 3, attack: 5, defense: 3, ... },
// { id: 1, name: "スライムベス", hp: 4, attack: 7, ... },
// ...
// ]
// Get all weapons
const weapons = game.get_weapons();
// Get all spells
const spells = game.get_spells();
// Get status progression table
const statusTable = game.get_status_table();API Reference
WasmGame
Main game interface.
Constructor
new WasmGame()- Create a new game instance
Player Management
create_player(name: string): PlayerState- Create a new playerget_player_state(): PlayerState- Get current player statehas_player(): boolean- Check if player existsgenerate_password(): string- Generate 20-character passwordload_from_password(password: string): PlayerState- Load from password
Battle System
queue_battle_action(action: string): void- Queue action ("attack", "spell", "item", "escape")queue_battle_input(value: number): void- Queue numeric input (menu selection)run_battle(monster_id: number): BattleResult- Execute battleclear_battle_input(): void- Clear action queue
Master Data
get_monsters(): MonsterData[]- Get all monstersget_weapons(): EquipmentData[]- Get all weaponsget_armors(): EquipmentData[]- Get all armorget_shields(): EquipmentData[]- Get all shieldsget_items(): EquipmentData[]- Get all itemsget_spells(): SpellData[]- Get all spellsget_status_table(): StatusData[]- Get level progression data
Messages
get_messages(): string[]- Get accumulated messagesclear_messages(): void- Clear message buffer
TypeScript Support
This package includes TypeScript definitions out of the box:
import init, { WasmGame, PlayerState, BattleResult } from 'damdara';
await init();
const game: WasmGame = new WasmGame();
const state: PlayerState = game.create_player("ゆうてい");Browser Compatibility
- Chrome/Edge 90+
- Firefox 89+
- Safari 15+
Requires WebAssembly support.
Node.js Usage
import { readFile } from 'fs/promises';
import init, { WasmGame } from 'damdara';
// Load WASM file explicitly in Node.js
const wasmBuffer = await readFile('./node_modules/damdara/damdara_bg.wasm');
await init(wasmBuffer);
const game = new WasmGame();
// ... use normallyExamples
See the live demo for a complete web application example.
Source code: GitHub Repository
License
MIT © Daisuke Takayama
