TypeScript-first game numeric engine for RPG and strategy games
A lightweight, type-safe formula engine designed for game developers who need reliable battle calculations, character attributes, and expression parsing - with zero dependencies.
Installation ยท Quick Start ยท Documentation ยท Examples ยท Online Demo
- โก Zero Dependencies - Lightweight and fast, less than 50KB minified
- ๐ก๏ธ Type-Safe - Full TypeScript support with strict typing and intelligent code completion
- ๐ Expression Engine - Parse and evaluate complex mathematical expressions with RPN conversion
- ๐ฎ Battle System - Built-in RPG battle simulation with character attributes and damage calculation
- ๐ง Extensible - Flexible operator system supporting complex game logic and formula combinations
- ๐ฆ Tree-shakable - Modern ESM support with CommonJS fallback
To use this library in your project:
npm install @soonfx/engineClone and setup the development environment:
# Clone the repository
git clone https://github.com/soonfx-engine/core.git
cd core
# Install dependencies
npm install
# Build the project
npm run build
# Run examples
cd docs/examples
npm install
npm run devimport { fx } from '@soonfx/engine';
// 1. Mathematical utilities
const distance = fx.distance(0, 0, 10, 10);
console.log('Distance between points:', distance); // 14.142135623730951
// 2. Expression evaluation
const result = fx.evaluateExpression('(2 + 3) * 4');
console.log('Expression result:', result); // 20
// 3. Numeric processing
const fixed = fx.fixedDecimal(3.14159, 2);
console.log('Fixed to 2 decimals:', fixed); // 3.14import { Eve, Call, CallCenter } from '@soonfx/engine';
// Create event call center
const callCenter = new CallCenter();
// Listen to events
callCenter.addEventListener(Eve.SHIFT_ADD_BOARD, (data) => {
console.log('Board added event triggered:', data);
});
// Send events
Call.send(Eve.ADD_DATABASE_DATA, [data, body, index]);// Calculate distance between two points
const distance = fx.distance(x1, y1, x2, y2);
// Vector dot product
const dotProduct = fx.dot(p1x, p1y, p2x, p2y);
// Vector cross product
const crossProduct = fx.cross(p1x, p1y, p2x, p2y);
// Calculate vector length
const length = fx.length(a, b);
// Coordinate transformation
const coord = fx.coordinate(x, y, angle, distance);The Player class provides character attributes, battle calculations, and combat simulation. See the Examples section below for complete battle system demonstrations.
@soonfx/fx
โโโ Core Systems (core/)
โ โโโ EventManager Event management
โ โโโ System System base class
โ โโโ Types Type definitions
โ
โโโ Mathematical Modules
โ โโโ Vector Vector operations (dot, cross, distance)
โ โโโ Numeric Numeric processing (fixedDecimal, currencyConversion)
โ โโโ Geometry Geometric calculations (coordinate, length)
โ
โโโ Expression System
โ โโโ Parser Expression parser
โ โโโ RPN Converter Reverse Polish Notation converter
โ โโโ Evaluator Evaluation engine
โ
โโโ Data Management (data/)
โ โโโ Layers Layer system
โ โโโ Metadata Metadata management
โ โโโ Models Data models
โ โโโ Storage Storage system
โ
โโโ Game Systems (game/)
โ โโโ FXCentre Game engine core
โ โโโ Player Player character system
โ โโโ Formulas Formula calculation system
โ
โโโ Communication (communication/)
โ โโโ Events Event system
โ โโโ Call Event calling
โ โโโ Message Message passing
โ
โโโ Utilities (utils/)
โโโ ExtendsUtil Extension utilities
- ๐ฒ Turn-based Games - Complex numeric calculations and battle systems
- โ๏ธ Role-Playing Games (RPG) - Character attributes, skills, and equipment systems
- ๐ Strategy Games - Numerical balance and formula systems
- ๐ฎ Card Games - Card attribute calculation and effect systems
- ๐ Simulation Games - Complex numerical simulation and calculations
- โ Character attribute calculations (attack, defense, HP, etc.)
- โ Battle damage calculation and combat simulation
- โ Equipment and item effect calculations
- โ Skill and buff systems
- โ Level and experience systems
- โ Game balance testing
Check out the example project for complete development examples.
- โ๏ธ Battle system simulation
- ๐ Character attribute calculations
- ๐ฏ PVE data generation
- ๐ Multi-battle comparison analysis
- ๐ฎ Complete game numeric system demonstration
See the Getting Started section in Contributing for setup instructions.
SoonFx provides complete TypeScript type definitions:
// Automatic type inference
const distance: number = fx.distance(0, 0, 10, 10);
// Full IntelliSense support
fx. // IDE will show all available methods- โ Complete TypeScript type definitions (.d.ts)
- โ Intelligent code completion
- โ Type checking and error hints
- โ Parameter type inference
- โ Return type inference
- โ Node.js >= 14.0.0
- โ
Modern Browsers (ES2015+)
- Chrome, Firefox, Safari, Edge (latest versions)
- โ
Build Tools
- esbuild (recommended, used in this project)
- Webpack, Vite, Rollup, and other modern bundlers
- โ ESM (ES Modules) - Recommended
- โ CommonJS - Node.js environment
We welcome all forms of contributions!
First, clone the repository:
git clone https://github.com/soonfx-engine/core.git
cd core# Navigate to examples directory
cd docs/examples
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build# Install dependencies
npm install
# Build the project
npm run build
# Run tests (if available)
npm testView the complete changelog
This project is licensed under the Apache 2.0 License. You are free to use, modify, and distribute this project.
- ๐ฆ npm Package
- ๐ป GitHub Repository
- ๐ Online Demo
- ๐ Issue Tracker
- ๐ฌ Discussions
If you encounter any issues:
- ๐ฌ GitHub Discussions - Ask questions and discuss
- ๐ GitHub Issues - Bug reports and feature requests
- ๐ง jiyisoon@163.com - Email contact
If this project helps you, please give us a Star! It means a lot to us.
