Documentation Structure
The TypeScript Modding Tools documentation is divided into three complementary parts:- Main Documentation - Covers general concepts, features, and limitations
- This Technical Guide - Details the toolkit’s architecture and internal implementation
- How-To Guides: A series of practical tutorials for common modding tasks:
Repository Structure
The modding toolkit is organized with a clear separation of concerns:Core Architecture
The toolkit uses a layered architecture combining builder pattern, factory methods, and composable nodes:- Builders - High-level abstractions to create game entities
- Nodes - XML node representations that map to database entries
- Files - File generators that combine nodes into proper XML files
- Mod - Top-level container that manages files and builds the mod
Mod Lifecycle
The typical lifecycle of a mod created with this toolkit:- Create a
Modinstance - Define entities using builders
- Bind related entities together
- Add entities to the mod
- Build the mod, generating all required files
Builder Implementation
All builder classes extend theBaseBuilder class which provides core functionality:
CivilizationBuilder
TheCivilizationBuilder is one of the most complex implementations:
UnitBuilder
TheUnitBuilder demonstrates how specialized builders are implemented:
Constants and Game Data Mapping
The constants in the toolkit are directly mapped from game files to TypeScript enums. These ensure type safety and help with autocomplete.Constants Structure
Constants are organized into categories matching game systems:Mapping to Game Data
To understand how constants are derived from game data, let’s compare with actual game files:- CONSTRUCTIBLE_TYPE_TAG - Maps to
TypeTagsin constructibles.xml:
- EFFECT - Maps to modifier effects defined in the game:
- ACTION_GROUP - Controls when files are loaded:
Comprehensive Constants Coverage
The toolkit includes constants for:- Basic Game Elements: Units, buildings, districts, civilizations
- Modifiers: Collections, effects, requirements
- Yields: Production, food, gold, science, culture, etc.
- Terrains and Features: Mountains, rivers, forests, etc.
- Resources: Strategic and luxury resources
- Action Groups: File loading and database actions
Node System Implementation
The node system represents the backbone of the XML generation process. Each node corresponds to a database entry or XML element.Node Base Class
All nodes inherit from a base class that provides XML conversion:DatabaseNode
TheDatabaseNode represents a complete database XML file:
Specialized Nodes
Each game entity has its own node type:File Generation Process
The toolkit generates two primary types of files:- XmlFile - XML database files with game data
- ImportFile - Asset files like icons or SQL scripts
XmlFile Implementation
ImportFile Implementation
Mod Class Implementation
TheMod class orchestrates the entire mod generation process:
Technical Case Study: Creating a Civilization
To illustrate the complete process, let’s walk through the creation of a civilization with the toolkit:1. Builder Initialization
2. Node Creation (Inside Initialize)
3. Binding Related Entities
4. File Generation
5. Mod Building
6. Generated XML (Example)
Performance Considerations
The toolkit’s performance is highly optimized through several techniques:- Lazy Evaluation - Nodes are only converted to XML when needed
- Reuse of String Constants - String constants are defined once and reused
- Minimal Dependencies - No external dependencies for the core functionality
- Efficient File I/O - Files are written in parallel when possible
Extension Points
The toolkit is designed to be extended through several mechanisms:- Creating Custom Builders - Extend
BaseBuilderfor specialized builders - Adding Custom Nodes - Create new node types for game elements
- Extending Constants - Add new constants as game content expands
- Custom File Types - Implement additional file types beyond XML and assets
Related Documentation
- Main Documentation - General overview and features
- How-To Guides - Step-by-step tutorials for common tasks
- Modding Architecture Overview - General Civilization VII modding framework