Core Module Documentation
Overview
The core/ directory contains the fundamental systems for the idle game. It provides:
- Numeric Foundation:
BigNumberfor handling huge idle game values - Game State Management:
GameStateautoload for all persistent state - Currency System: Database and tracking for multiple currency types
- Generator System: Automated resource production with scaling costs
- Buff System: Upgrades that modify generator behavior
- Goal System: Achievement tracking and unlock triggers
- Prestige System: Rebirth mechanics with permanent multipliers
Architecture
core/
├── big_number.gd # Core numeric API
├── game_state.gd # Main state management autoload
├── buff_database.gd # Buff registration system
├── currency_database.gd # Currency registration system
├── currency/ # Currency data structures
├── generator/ # Generator logic and data
├── goals/ # Goal/achievement system
└── prestige/ # Prestige/rebirth system
Data Flow
- Game Start:
GameState._ready()initializes currencies, loads save - Player Action: Generator bought →
GameStateupdated → signals emitted - UI Reaction: Listeners respond to signals → update display
- Goal Check: Currency changed → goals evaluated → buffs unlocked
- Save:
GameState.save_game()→ JSON touser://idle_save.json
Save Format
Version: 3
{
"save_format_version": 3,
"currencies": {
"<currency_id>": {
"current": {"m": float, "e": int},
"total": {"m": float, "e": int},
"all_time": {"m": float, "e": int}
}
},
"generator_states": {
"<generator_id>": {
"owned": int,
"purchased_count": int,
"unlocked": bool,
"available": bool
}
},
"buff_levels": {
"<buff_id>": int
},
"buff_unlocked": {
"<buff_id>": true
},
"buff_active": {
"<buff_id>": true
},
"goals": {
"completed": ["<goal_id>", ...]
},
"last_save_time": unix_timestamp
}
Key Signals
| Signal | Emitted When |
|---|---|
currency_changed(currency_id, new_amount) |
Any currency balance changes |
generator_state_changed(generator_id, state) |
Generator owned/unlocked changes |
generator_buff_level_changed(gen_id, buff_id, level) |
Buff level increased |
buff_unlocked_changed(buff_id, unlocked) |
Buff unlock state changed |
goal_completed(goal_id) |
Goal criteria met |
BigNumber Serialization
All large numbers use scientific notation internally:
# Value = mantissa * 10^exponent
var num = BigNumber.new(1.5, 24) # 1.5e24
var dict = num.serialize() # {"m": 1.5, "e": 24}
var restored = BigNumber.deserialize(dict)
Extending the Core
Adding a New Currency
- Create
res://sandbox/currencies/<name>.tresextendingCurrency - Set
id,display_name, andicon - Auto-discovered by
CurrencyDatabase
Adding a New Generator
- Create
res://sandbox/generators/<name>.tresextendingCurrencyGeneratorData - Configure costs, production, and unlock goals
- Instance
CurrencyGeneratorscene with this data
Adding a New Buff
- Create
res://sandbox/buffs/<name>.tresextendingGeneratorBuffData - Set
target_ids,kind,effect_increment, andcost - Auto-discovered by
BuffDatabase
See Also
currency/- Currency data structuresgenerator/- Generator production systemgoals/- Achievement systemprestige/- Rebirth mechanics