Remove dead code
This commit is contained in:
@@ -10,30 +10,26 @@ specific generators and can be enhanced with purchasable buffs that increase XP
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `research_xp_tracker.gd` | Accumulates XP from production and handles auto-leveling (Node) |
|
||||
| `research_catalogue.gd` | Resource holding all research configurations |
|
||||
| `research_panel.gd` | UI panel showing all research tracks |
|
||||
| `research_row.gd` | UI row component for individual research display |
|
||||
| `../generator/research_buff_calculator.gd` | Static utility for buff multiplier calculations |
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
LevelGameState (Node2D)
|
||||
├── ResearchXPTracker (child node)
|
||||
│ ├── Receives production_tick signals
|
||||
│ ├── Applies buff multipliers
|
||||
│ ├── Awards XP to research tracks
|
||||
│ └── Auto-levels when thresholds reached
|
||||
├── research_xp: Dictionary
|
||||
├── research_levels: Dictionary
|
||||
└── research_catalogue: ResearchCatalogue
|
||||
└── ResearchPanel (UI, always visible)
|
||||
├── ResearchRow (for each research track)
|
||||
│ ├── Name & icon
|
||||
│ ├── Level display
|
||||
│ ├── Progress bar (percentage)
|
||||
│ ├── Multiplier indicator
|
||||
│ └── Active buff display
|
||||
├── research_catalogue: ResearchCatalogue
|
||||
│ └── ResearchPanel (UI, always visible)
|
||||
│ ├── ResearchRow (for each research track)
|
||||
│ │ ├── Name & icon
|
||||
│ │ ├── Level display
|
||||
│ │ ├── Progress bar (percentage)
|
||||
│ │ ├── Multiplier indicator
|
||||
│ │ └── Active buff display
|
||||
└── (buff calculation delegated to ResearchBuffCalculator static methods)
|
||||
```
|
||||
|
||||
## Data Flow
|
||||
@@ -42,12 +38,13 @@ LevelGameState (Node2D)
|
||||
Generator Production (currency_per_cycle)
|
||||
│
|
||||
▼
|
||||
ResearchXPTracker
|
||||
LevelGameState.add_research_xp()
|
||||
1. base_xp = currency_produced * xp_per_currency_produced
|
||||
2. actual_xp = base_xp * buff_multiplier
|
||||
3. research_xp += actual_xp
|
||||
4. Check level threshold → auto-level
|
||||
5. Emit research_level_up signal
|
||||
2. buff_multiplier = ResearchBuffCalculator.apply_buffs(research, buffs)
|
||||
3. actual_xp = base_xp * buff_multiplier
|
||||
4. research_xp += actual_xp
|
||||
5. Check level threshold → auto-level
|
||||
6. Emit research_level_up signal
|
||||
│
|
||||
▼
|
||||
ResearchState {xp: 150.5, level: 3}
|
||||
@@ -143,38 +140,61 @@ func get_all_research() -> Array[ResearchData]
|
||||
|
||||
Referenced directly by `LevelGameState` via `@export var research_catalogue: ResearchCatalogue`.
|
||||
|
||||
## ResearchXPTracker
|
||||
## ResearchBuffCalculator
|
||||
|
||||
Child node of `LevelGameState` that accumulates XP from production and applies buff multipliers.
|
||||
Static utility class for calculating research XP buff multipliers.
|
||||
|
||||
### Signals
|
||||
### Location
|
||||
|
||||
```gdscript
|
||||
signal research_xp_changed(research_id: StringName, new_xp: float)
|
||||
signal research_level_up(research_id: StringName, old_level: int, new_level: int)
|
||||
```
|
||||
`res://core/generator/research_buff_calculator.gd`
|
||||
|
||||
### Key Methods
|
||||
|
||||
```gdscript
|
||||
func add_xp_with_buffs(research_id: StringName, base_xp: BigNumber) -> BigNumber:
|
||||
"""Apply buff multipliers and award XP. Returns actual XP after buffs (BigNumber)."""
|
||||
var buff_multiplier: float = game_state.get_research_xp_multiplier(research_id)
|
||||
var multiplier_bn: BigNumber = BigNumber.from_float(buff_multiplier)
|
||||
var actual_xp: BigNumber = base_xp.multiply(multiplier_bn)
|
||||
game_state.add_research_xp(research_id, actual_xp)
|
||||
return actual_xp
|
||||
static func apply_buffs(research: ResearchData, game_state: LevelGameState) -> float:
|
||||
"""Calculate total buff multiplier for research XP gain. Returns multiplicative factor."""
|
||||
var multiplier: float = 1.0
|
||||
if research.associated_buff_id.is_empty():
|
||||
return multiplier
|
||||
|
||||
var buff: GeneratorBuffData = game_state.get_buff(research.associated_buff_id)
|
||||
if buff != null and game_state.is_buff_active(buff.id):
|
||||
var buff_level: int = game_state.get_buff_level(buff.id)
|
||||
multiplier *= ResearchBuffCalculator._calculate_buff_multiplier(buff, buff_level)
|
||||
|
||||
return multiplier
|
||||
|
||||
func _on_generator_produced(generator_id: StringName, amount: BigNumber) -> void:
|
||||
var research: ResearchData = _get_research_for_generator(generator_id)
|
||||
var amount_float: float = amount.mantissa * pow(10.0, float(amount.exponent))
|
||||
var base_xp: BigNumber = BigNumber.from_float(research.xp_per_currency_produced * amount_float)
|
||||
add_xp_with_buffs(research.id, base_xp)
|
||||
static func _calculate_buff_multiplier(buff: GeneratorBuffData, level: int) -> float:
|
||||
"""Calculate buff effect multiplier at given level."""
|
||||
return buff.get_effect_multiplier(level)
|
||||
```
|
||||
|
||||
### Connection
|
||||
### Usage
|
||||
|
||||
Connected to `LevelGameState` via `generator_produced` signal.
|
||||
Called from `LevelGameState.add_research_xp()`:
|
||||
|
||||
```gdscript
|
||||
func add_research_xp(research_id: StringName, xp: BigNumber) -> void:
|
||||
var research: ResearchData = research_catalogue.get_research_by_id(research_id)
|
||||
if research == null:
|
||||
return
|
||||
|
||||
# Apply buff multipliers
|
||||
var buff_multiplier: float = ResearchBuffCalculator.apply_buffs(research, self)
|
||||
var multiplier_bn: BigNumber = BigNumber.from_float(buff_multiplier)
|
||||
var actual_xp: BigNumber = xp.multiply(multiplier_bn)
|
||||
|
||||
# Store XP and check for level-up
|
||||
var old_level: int = get_research_level(research_id)
|
||||
research_xp[research_id] = research_xp.get(research_id, BigNumber.new(0.0, 0)).add(actual_xp)
|
||||
var new_level: int = research.get_level_for_xp(research_xp[research_id])
|
||||
|
||||
if new_level > old_level:
|
||||
research_levels[research_id] = new_level
|
||||
research_level_up.emit(research_id, old_level, new_level)
|
||||
|
||||
research_xp_changed.emit(research_id, research_xp[research_id])
|
||||
```
|
||||
|
||||
## LevelGameState Extensions
|
||||
|
||||
@@ -182,7 +202,7 @@ Connected to `LevelGameState` via `generator_produced` signal.
|
||||
```gdscript
|
||||
var research_xp: Dictionary = {} # {research_id: BigNumber}
|
||||
var research_levels: Dictionary = {} # {research_id: level_int}
|
||||
var research_tracker: ResearchXPTracker
|
||||
# research_tracker removed - buff calculation moved to static utility
|
||||
```
|
||||
|
||||
### Signals
|
||||
@@ -208,21 +228,27 @@ func get_research_multiplier(research_id: StringName) -> float:
|
||||
return research.get_multiplier_for_level(level)
|
||||
|
||||
func add_research_xp(research_id: StringName, xp: BigNumber) -> void:
|
||||
"""Add XP (BigNumber) and auto-level if threshold reached"""
|
||||
"""Add XP (BigNumber) with buff multipliers applied, auto-level if threshold reached"""
|
||||
var research: ResearchData = research_catalogue.get_research_by_id(research_id)
|
||||
if research == null:
|
||||
return
|
||||
|
||||
var old_level: int = get_research_level(research_id)
|
||||
var current_xp: BigNumber = get_research_xp(research_id)
|
||||
research_xp[research_id] = current_xp.add(xp)
|
||||
new_level = research.get_level_for_xp(research_xp[research_id])
|
||||
|
||||
# Apply buff multipliers via static utility
|
||||
var buff_multiplier: float = ResearchBuffCalculator.apply_buffs(research, self)
|
||||
var multiplier_bn: BigNumber = BigNumber.from_float(buff_multiplier)
|
||||
var actual_xp: BigNumber = xp.multiply(multiplier_bn)
|
||||
|
||||
research_xp[research_id] = current_xp.add(actual_xp)
|
||||
var new_level: int = research.get_level_for_xp(research_xp[research_id])
|
||||
|
||||
if new_level > old_level:
|
||||
research_levels[research_id] = new_level
|
||||
research_level_up.emit(research_id, old_level, new_level)
|
||||
|
||||
func get_research_xp_multiplier(research_id: StringName) -> float:
|
||||
"""Returns multiplicative buff for research XP gain"""
|
||||
var multiplier: float = 1.0
|
||||
var buff: GeneratorBuffData = get_buff(research.associated_buff_id)
|
||||
if is_buff_active(buff.id):
|
||||
multiplier *= buff.get_effect_multiplier(get_buff_level(buff.id))
|
||||
return multiplier
|
||||
|
||||
research_xp_changed.emit(research_id, research_xp[research_id])
|
||||
```
|
||||
|
||||
### Save/Load Integration
|
||||
@@ -272,11 +298,11 @@ func _grant_cycle_income(cycle_count: int) -> void:
|
||||
_add_currency(produced)
|
||||
production_tick.emit(produced, cycle_count, owned)
|
||||
|
||||
# Award research XP (BigNumber)
|
||||
# Award research XP (BigNumber) - buff multipliers applied in LevelGameState
|
||||
if data.research_data != null:
|
||||
var amount_float: float = produced.mantissa * pow(10.0, float(produced.exponent))
|
||||
var xp: BigNumber = BigNumber.from_float(data.research_data.xp_per_currency_produced * amount_float)
|
||||
research_tracker.add_xp_with_buffs(data.research_data.id, xp)
|
||||
game_state.add_research_xp(data.research_data.id, xp)
|
||||
```
|
||||
|
||||
### Research Multiplier
|
||||
@@ -425,7 +451,7 @@ actual_xp = base_xp * xp_multiplier
|
||||
| Decision | Value |
|
||||
|----------|-------|
|
||||
| ResearchCatalogue reference | Direct `@export var research_catalogue: ResearchCatalogue` in LevelGameState |
|
||||
| ResearchXPTracker location | Child of `LevelGameState` (receives signals via connection) |
|
||||
| Buff calculation | Static utility (`ResearchBuffCalculator`) - no dedicated tracker node |
|
||||
| Progress bar display | Percentage format (e.g., "75%") |
|
||||
| Buff display | Shows buff name and effect (e.g., "Mining Expert: +20% XP") |
|
||||
| Research unlock | Starts unlocked |
|
||||
@@ -438,8 +464,8 @@ actual_xp = base_xp * xp_multiplier
|
||||
## System Behavior
|
||||
|
||||
1. **Generator produces currency** → `production_tick` signal emitted
|
||||
2. **ResearchXPTracker receives signal** → calculates base XP from production amount
|
||||
3. **Buff multipliers applied** → checks for active RESEARCH_XP_MULTIPLIER buffs
|
||||
2. **CurrencyGenerator calls** → `game_state.add_research_xp()` with base XP
|
||||
3. **LevelGameState applies buffs** → `ResearchBuffCalculator.apply_buffs()` calculates multiplier
|
||||
4. **XP awarded** → stored in `research_xp` dictionary
|
||||
5. **Level check** → if XP exceeds threshold, auto-level and emit `research_level_up`
|
||||
6. **Multiplier applied** → `get_research_multiplier()` returns updated production bonus
|
||||
@@ -458,4 +484,5 @@ On prestige reset:
|
||||
- `core/level_game_state.gd` - Research state storage and management
|
||||
- `core/generator/currency_generator_data.gd` - Links to ResearchData
|
||||
- `core/generator/generator_buff_data.gd` - RESEARCH_XP_MULTIPLIER buff type
|
||||
- `core/generator/research_buff_calculator.gd` - Static buff calculation utility
|
||||
- `core/research/research_catalogue.gd` - Research configuration resource
|
||||
|
||||
Reference in New Issue
Block a user