Skip to content

Commit 0a09c66

Browse files
committed
Add docstrings and refine the code in CharacterStats and GrowthStats
1 parent 7ac003f commit 0a09c66

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

godot/combat/battlers/stats/CharacterStats.gd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Represents a Battler's actual stats: health, strength, etc.
3+
See the child class GrowthStats.gd for stats growth curves
4+
and lookup tables
5+
"""
16
extends Resource
27

38
class_name CharacterStats
@@ -91,9 +96,7 @@ func _get_experience() -> int:
9196
return experience
9297

9398
func _set_experience(value):
94-
if value == null or value < 0:
95-
value = 0
96-
experience = value
99+
experience = max(0, value)
97100

98101
func _get_level() -> int:
99102
return level

godot/combat/battlers/stats/GrowthStats.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
extends "res://combat/battlers/stats/CharacterStats.gd"
1+
"""
2+
Uses curves and lookup tables to calculate a battler's stats
3+
4+
"""
5+
extends CharacterStats
26

37
class_name GrowthStats
48

9+
# level as a percentage of the max_level, in the [0.0, 1.0] range
510
var _interpolated_level : float
611

712
export var level_lookup : Array = []
@@ -16,7 +21,7 @@ func _set_experience(value : int = 0):
1621
Calculate level, which updates all stats
1722
"""
1823
var max_level = len(level_lookup)
19-
experience = value
24+
experience = max(0, value)
2025
var l = level
2126
while l + 1 < max_level && experience > level_lookup[l+1]:
2227
l += 1

0 commit comments

Comments
 (0)