Skip to content

Conversation

Jasrags
Copy link
Contributor

@Jasrags Jasrags commented Jul 7, 2025

Description

#210

This PR centralizes stat field access by introducing accessor methods and replacing direct struct field references.

  • Added GetStatInfoNames and Get(name) for dynamic stat handling.
  • Updated status command to use dynamic stat list and generic getters.
  • Replaced all direct Stats.X accesses with Stats.Get("X") calls in character logic.

Changes

  • internal/usercommands/status.go
    • Use GetStatInfoNames and generic getters instead of hardcoded lists and switch
  • internal/stats/stats.go
    • Added GetStatInfoNames and Get(name) methods to Statistics
  • internal/characters/character.go
    • Replaced direct Stats.X property accesses with Stats.Get("X") calls

@Jasrags Jasrags self-assigned this Jul 7, 2025
@Jasrags Jasrags added the enhancement New feature or request label Jul 7, 2025
@Jasrags Jasrags changed the title Use accessors for mob/player stats DRAFT: Use accessors for mob/player stats Jul 7, 2025
@Jasrags Jasrags requested a review from Copilot July 7, 2025 14:54
Copilot

This comment was marked as outdated.

@Jasrags Jasrags requested a review from Copilot July 7, 2025 19:00
Copilot

This comment was marked as outdated.

@Jasrags Jasrags requested a review from Copilot July 7, 2025 19:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes stat field access by introducing accessor methods and updating all references to use these generic getters.

  • Added GetStatInfoNames and Get(name) for dynamic stat handling
  • Refactored the status command and templates to use the new accessors
  • Replaced direct Stats.X references with Stats.Get("X") across character logic

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/usercommands/status.go Use GetStatInfoNames for prompts and replace the manual switch with Stats.Get
internal/templates/templatesfunctions.go Added template helper funcs (charStat*) for stat fields
internal/stats/stats.go Introduced GetStatInfoNames and Get; added strings import
internal/characters/character.go Swapped all Stats.X field accesses for Stats.Get("X") calls
_datafiles/world/default/templates/character/status.template Updated template to use charStatValue instead of direct .Stats.X access
Comments suppressed due to low confidence (7)

_datafiles/world/default/templates/character/status.template:9

  • [nitpick] The stat literals use mixed casing ("Vitality" vs lowercase "vitality"); consider normalizing to a consistent case for clarity.
 │ <ansi fg="yellow">Area:   </ansi>{{ printf "%-22s" .Character.Zone              }}│ │ <ansi fg="yellow">Strength: </ansi>{{ printf "<ansi fg=\"stat\">%-4d</ansi><ansi fg=\"statmod\">(%-3d)</ansi>" (charStatValue .Character "strength") (.Character.StatMod "strength") }} <ansi fg="yellow">Vitality:  </ansi>{{  printf "<ansi fg=\"stat\">%-4d</ansi><ansi fg=\"statmod\">(%-3d)</ansi>" (charStatValue .Character "Vitality") (.Character.StatMod "vitality")   }} │

internal/stats/stats.go:24

  • Add unit tests for GetStatInfoNames and Get to verify correct ordering, casing, and behavior on invalid inputs.
func (s *Statistics) GetStatInfoNames() []string {

internal/stats/stats.go:4

  • The import "math" is unused in this file and will cause a compilation error; consider removing it.
	"math"

internal/usercommands/status.go:64

  • The variable 'selection' is undefined; you likely meant to use the 'match' value returned from FindMatchIn.
		before = user.Character.Stats.Get(selection).Value - user.Character.Stats.Get(selection).Mods

internal/usercommands/status.go:64

  • This code always increments Training and spends a point regardless of whether the selection was valid; add validation to ensure 'match' is non-empty and the stat can actually be trained.
		before = user.Character.Stats.Get(selection).Value - user.Character.Stats.Get(selection).Mods

internal/usercommands/status.go:65

  • [nitpick] To avoid repeated lookups on the same stat, cache the result of Stats.Get(match) in a local variable before updating it.
		user.Character.Stats.Get(selection).Training += 1

internal/characters/character.go:1393

  • [nitpick] Consider removing these commented-out assignments to eliminate dead code and improve readability.
		// c.Stats.Get("Strength").Base = raceInfo.Stats.Get("Strength").Base

@Volte6
Copy link
Member

Volte6 commented Jul 27, 2025

What's the state of this draft PR currently? Does it need testing or anything?

@Jasrags
Copy link
Contributor Author

Jasrags commented Jul 27, 2025

What's the state of this draft PR currently? Does it need testing or anything?

I’m still planning on continuing it but like others life has been getting in the way.

@Volte6
Copy link
Member

Volte6 commented Jul 27, 2025

What's the state of this draft PR currently? Does it need testing or anything?

I’m still planning on continuing it but like others life has been getting in the way.

NP, just wanted to make sure you weren't waiting on me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants