Skip to content

๐ŸŽฎ TypeScript game numeric engine for RPG & strategy games. Zero dependencies, type-safe formula parsing, battle system simulation, and expression evaluation. ๅŸบไบŽ TypeScript ็š„ๆธธๆˆๆ•ฐๅ€ผๅผ•ๆ“Ž๏ผŒไธ“ไธบ RPG ๅ’Œ็ญ–็•ฅๆธธๆˆ่ฎพ่ฎกใ€‚้›ถไพ่ต–ใ€็ฑปๅž‹ๅฎ‰ๅ…จ็š„ๅ…ฌๅผ่งฃๆžใ€ๆˆ˜ๆ–—็ณป็ปŸๆจกๆ‹Ÿๅ’Œ่กจ่พพๅผ่ฎก็ฎ—ใ€‚

License

Notifications You must be signed in to change notification settings

soonfx-engine/core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

86 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

SoonFx Runtime

The TypeScript-first numeric engine for games.
Decouple logic from code, manage complex formulas with ease, and build robust RPG/SLG/Card systems.

npm version npm downloads CI License: Apache 2.0 TypeScript

Installation ยท Quick Start ยท Documentation ยท Examples ยท Roadmap ยท Online Demo

English | ็ฎ€ไฝ“ไธญๆ–‡


โ“ What is SoonFx?

SoonFx Editor Preview

SoonFx is a TypeScript-first numeric engine designed specifically for games. It addresses the common challenge of managing complex game logic, formulas, and numeric relationships that often become hardcoded "spaghetti code."

๐Ÿšซ The Problem

In many game projects, damage calculations, resource production rates, and other numeric logic are hardcoded directly into the source code.

  • Hard to maintain: Formulas are buried in nested if-else statements.
  • Slow iteration: Designers need engineers to change a simple constant or formula structure.
  • Bug prone: Copy-pasting logic leads to subtle errors.

โœ… The Solution

SoonFx decouples logic from code.

  1. Logic as Data: Formulas and relationships are defined as data (JSON).
  2. Runtime Execution: The engine parses and executes this data safely at runtime.
  3. Visual Tooling: Designers use the SoonFx Editor to visually build these relationships.

๐ŸŽจ Visual Editor Driven

Stop hardcoding formulas. Build them visually.

SoonFx Runtime is the engine that powers the SoonFx Editor. It allows game designers to configure complex logic without writing a single line of code, while developers can safely execute it at runtime.

The Workflow

  1. Design: Designers create formulas, skill effects, and attribute relationships in the Visual Editor.
  2. Export: The editor generates a JSON configuration file.
  3. Run: The SoonFx Runtime loads this JSON and executes the logic in your game.

Note: While SoonFx Runtime can be used standalone for math and expressions, its true power is unlocked when paired with the Editor.

SoonFx Editor

๐Ÿ’ก Use Cases

SoonFx is designed for numeric-heavy game genres:

  • โš”๏ธ RPG Systems: Skill damage, character stats growth, equipment bonuses, combat power (CP) calculations.
  • ๐Ÿฐ SLG / Strategy: Resource production rates, building upgrade timers, marching times, tech tree requirements.
  • ๐Ÿƒ Card Games: Dynamic card values, synergy effects, deck balancing simulation.
  • ๐Ÿ“Š Simulation: Complex economy models, probability calculations.

๐Ÿ“ธ Demo

Demo Demo

โœจ Features

  • โšก 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

๐Ÿš€ For Users

To use this library in your project:

npm install @soonfx/engine

๐Ÿ“ฆ Development Setup

Clone 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 examples
npm install
npm run dev

๐ŸŽฏ Quick Start

Basic Usage

import { 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.14

Event System

import { 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]);

๐Ÿ“š Core API

Mathematical Utilities (fx)

Vector and Geometry Operations

// 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);

Game Characters (Player)

The Player class provides character attributes, battle calculations, and combat simulation. See the Examples section below for complete battle system demonstrations.

๐Ÿ—๏ธ System Architecture

@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

๐Ÿ“– Examples

Check out the example project for complete development examples.

Example Contents:

  • โš”๏ธ Battle system simulation
  • ๐Ÿ“Š Character attribute calculations
  • ๐ŸŽฏ PVE data generation
  • ๐Ÿ“ˆ Multi-battle comparison analysis
  • ๐ŸŽฎ Complete game numeric system demonstration

Run Examples Locally:

See the Getting Started section in Contributing for setup instructions.

๐Ÿ› ๏ธ TypeScript Support

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

Type Definition Features:

  • โœ… Complete TypeScript type definitions (.d.ts)
  • โœ… Intelligent code completion
  • โœ… Type checking and error hints
  • โœ… Parameter type inference
  • โœ… Return type inference

๐Ÿ”ง Browser and Environment Support

Supported Environments

  • โœ… 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

Module Systems

  • โœ… ESM (ES Modules) - Recommended
  • โœ… CommonJS - Node.js environment

๐Ÿค Contributing

We welcome all forms of contributions!

Getting Started

First, clone the repository:

git clone https://github.com/soonfx-engine/core.git
cd core

To Run Examples:

# Navigate to examples directory
cd examples

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

To Contribute Code:

# Install dependencies
npm install

# Build the project
npm run build

# Run tests (if available)
npm test

๐Ÿ—บ๏ธ Roadmap

See our Roadmap for planned features and improvements.

๐Ÿ“ Changelog

View the complete changelog

๐Ÿ“„ License

This project is licensed under the Apache 2.0 License. You are free to use, modify, and distribute this project.

๐Ÿ”— Links

๐Ÿ“ž Getting Help

If you encounter any issues:

โญ Star History

If this project helps you, please give us a Star! It means a lot to us.

Star History Chart


โฌ† Back to Top

Made with โค๏ธ by SoonFx Team

Copyright ยฉ 2025 SoonFx Team. All rights reserved.

About

๐ŸŽฎ TypeScript game numeric engine for RPG & strategy games. Zero dependencies, type-safe formula parsing, battle system simulation, and expression evaluation. ๅŸบไบŽ TypeScript ็š„ๆธธๆˆๆ•ฐๅ€ผๅผ•ๆ“Ž๏ผŒไธ“ไธบ RPG ๅ’Œ็ญ–็•ฅๆธธๆˆ่ฎพ่ฎกใ€‚้›ถไพ่ต–ใ€็ฑปๅž‹ๅฎ‰ๅ…จ็š„ๅ…ฌๅผ่งฃๆžใ€ๆˆ˜ๆ–—็ณป็ปŸๆจกๆ‹Ÿๅ’Œ่กจ่พพๅผ่ฎก็ฎ—ใ€‚

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks