Skip to content

Conversation

MorquinDevlar
Copy link
Contributor

@MorquinDevlar MorquinDevlar commented Jul 21, 2025

Summary

This PR introduces a template-based rendering system for item and mob descriptions, replacing hardcoded string generation with template files. The system includes configurable equipment display options and error handling for edge cases.

Changes

Added

  • Template-based rendering system for items and mobs
    • ItemLookData struct with GetLookData() method for building template data
    • MobLookData struct with GetLookData() method for building template data
    • look-item.template and look-item.screenreader.template for item descriptions
    • look-mob.template and look-mob.screenreader.template for mob descriptions
    • Screenreader variants for character description and inventory-look templates
  • Configurable equipment display system
    • UserInterface config section with Formats and Display subsections
    • ShowEmptyEquipmentSlots config option to control equipment visibility
    • ShouldShowEmptyEquipmentSlots() config method
    • Template function showEmptyEquipmentSlots to access config from templates
    • "xxx is not wearing anything" message when mob has no equipment and showEmpty is false
  • Defensive programming
    • Nil checks in Item.GetLookData() to handle nil items
    • Nil checks in Mob.GetLookData() to handle nil mobs
    • Division-by-zero protection for mob health percentage calculations

Changed

  • Look command implementation to use template rendering instead of hardcoded strings
  • Moved TextFormats config section to UserInterface.Formats
  • Default config indentation to use spaces (Every editor I've used wanted to do this automatically with every save - I gave in. Easy to change if it causes issues.)
  • MobLookData Equipment field to pointer type for template method compatibility

Fixed

  • Template conditionals to handle all equipment display scenarios
  • Circular import by passing charmer name as parameter to GetLookData

Removed

  • Hardcoded item and mob description generation in look command

Configuration

The ShowEmptyEquipmentSlots option:

  • true (default): Shows all equipment slots including empty ones
  • false: Only shows equipped items

Breaking Changes

  • TextFormats config section moved to UserInterface.Formats - users with custom config files must update this path manually

Added:
  - ItemLookData struct with GetLookData() method for template data
building
  - MobLookData struct with GetLookData() method for template data
building
  - look-item.template for rendering item descriptions
  - look-mob.template for rendering mob descriptions
  - Screenreader variants for all new templates
  - Character template screenreader variants for description and
inventory-look
  - Conditional equipment display in mob templates (only shows equipped
items)

Changed:
  - Look command to use templates for items and mobs instead of
hardcoded strings
  - MobLookData Equipment field to pointer type for template method
compatibility
  - Mob templates to only display equipment section when items are
equipped

Fixed:
  - Circular import issue by passing charmer name as parameter
  - Container reference removed from items package to avoid dependency
issues
Added:
  - UserInterface config section with Formats and Display subsections
  - ShowEmptyEquipmentSlots config option to control equipment display
  - Config method ShouldShowEmptyEquipmentSlots() for checking the
setting
  - Template function showEmptyEquipmentSlots to access config from
templates
  - GetUserInterfaceConfig() helper function
  - "xxx is not wearing anything" message when mob has no equipment and
showEmpty is false

Changed:
  - Moved TextFormats config under UserInterface.Formats for better
organization
  - Updated mob templates to respect ShowEmptyEquipmentSlots
configuration
  - Equipment display now shows all slots when true (default), only
equipped items when false

Fixed:
  - Template conditionals to properly handle all equipment display
scenarios
  - Both regular and screenreader templates now correctly show equipment
based on config
Added:
  - Nil checks in Item.GetLookData() to handle nil items
  - Nil checks in Mob.GetLookData() to handle nil mobs
  - Division-by-zero protection for mob health calculations

Changed:
  - Consolidated equipment display logic in mob templates from 3 blocks
to 1
  - Used template variables to control equipment slot visibility
  - Reduced code duplication in both standard and screenreader templates

Removed:
  - TextFormats to UserInterface.Formats migration logic
  - Redundant equipment display blocks in mob templates

Breaking Changes:
  - Users with custom config files must manually update TextFormats to
UserInterface.Formats structure
@MorquinDevlar MorquinDevlar self-assigned this Jul 21, 2025
@MorquinDevlar MorquinDevlar added the enhancement New feature or request label Jul 21, 2025
@MorquinDevlar MorquinDevlar requested a review from Volte6 as a code owner July 21, 2025 21:18
@MorquinDevlar MorquinDevlar changed the title Ttemplate-based rendering system for item and mob descriptions Template-based rendering system for item and mob descriptions Jul 21, 2025
Copy link
Member

@Volte6 Volte6 left a comment

Choose a reason for hiding this comment

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

Some comments/questions/discussion - I haven't tested it yet, just going through the code.

@@ -191,6 +192,7 @@ func (c *Config) Validate() {
c.FilePaths.Validate()
c.GamePlay.Validate()
c.Integrations.Validate()
c.UserInterface.Validate()
Copy link
Member

Choose a reason for hiding this comment

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

What do we get for the change from TextFormats to UserInterface?

Aside from a minor difference in naming, it seems like we're introducing some confusion or maintaining two paths? We may need a migration routine if this is the plan going forward, but if the only difference is a naming change, why bother?

Copy link
Contributor Author

@MorquinDevlar MorquinDevlar Aug 8, 2025

Choose a reason for hiding this comment

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

The reason for changing it was to clarify that entries here will change how the game looks to the player.

I've added an option to use the config file to show or hide empty eq slots in mobs and characters. This did not feel like it belonged just in "TextFormats" but at the same time, I wanted a single place for admins to handle look and feel of the game.

I actually made an automatic migration for it, but did not include it here as it felt somewhat overkill for an engine that is not yes in "real" production.

My thinking was that it's a relative simple change to make for game admins using the engine, and while it is breaking, it felt overkill to add extra code just to migrate this when a simple statement in the release notes could ask admins to change a simple thing in their own config override.

I can add a migration for it if you think that makes more sense.

@Jasrags Jasrags requested a review from Copilot August 1, 2025 18:50
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 introduces a template-based rendering system for item and mob descriptions, replacing hardcoded string generation with configurable template files and adding equipment display options.

  • Template-based rendering system with ItemLookData and MobLookData structs for building template data
  • New UserInterface configuration section with configurable equipment display settings
  • Template files for both standard and screenreader-friendly item/mob descriptions

Reviewed Changes

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

Show a summary per file
File Description
internal/usercommands/look.go Updates look command to use template-based rendering instead of hardcoded strings
internal/templates/templatesfunctions.go Adds showEmptyEquipmentSlots template function for config access
internal/mobs/mobs.go Adds MobLookData struct and GetLookData() method for template data
internal/items/items.go Adds ItemLookData struct and GetLookData() method for template data
internal/configs/configs.go Integrates new UserInterface config section
internal/configs/config.userinterface.go New configuration module for user interface settings
_datafiles/world/default/templates/descriptions/* Template files for item and mob descriptions with screenreader variants
_datafiles/config.yaml Updates config structure and moves TextFormats to UserInterface.Formats

Changed:
  - Replaced boolean fields (IsWeapon, IsReadable, etc.) with Type and
Subtype strings
  - Replaced IsCursed/IsEnchanted booleans with extensible Adjectives
map
  - Updated templates to use string equality checks (e.g., {{if eq .Type
"readable"}})

Fixed:
  - Corrected TimeoutMods YAML formatting from multi-line to single-line
@MorquinDevlar
Copy link
Contributor Author

I am making a few more changes to the code, just to clean things up a little. Moving this to a draft while I do it :) Let me know if the migration is still something you feel we should do.

We can do it on the fly when we read the file, keeping compatibility with the old TextFormats but only when reading the config file, or we can make a mere elaborate system where we re-write the actual config file to support the new system permanently.

@MorquinDevlar MorquinDevlar marked this pull request as draft August 9, 2025 23:00
Removed:
  - TextFormats struct definition and field from main Config struct
  - TextFormats.Validate() call from config validation process
  - config.textformats.go file containing backwards compatibility
function
  - Duplicate configuration entries in server output

Changed:
  - All references from GetTextFormatsConfig() to
GetUserInterfaceConfig().Formats
  - Direct TextFormats field access to UserInterface.Formats field
access
  - Config structure to use single source of truth for format settings

Fixed:
  - Duplicate prompt settings appearing in server set command output
  - Confusion from having both TextFormats.Prompt and
UserInterface.Formats.Prompt
  - Inconsistent config access patterns across the codebase

Updated files:
  - internal/configs/configs.go - removed TextFormats field and
validation
  - internal/mobcommands/go.go - updated to use
GetUserInterfaceConfig().Formats
  - internal/usercommands/go.go - updated to use
GetUserInterfaceConfig().Formats
  - internal/usercommands/history.go - updated to use
GetUserInterfaceConfig().Formats
  - internal/usercommands/set.go - updated to use
GetUserInterfaceConfig().Formats
  - internal/usercommands/start.go - updated to use
GetUserInterfaceConfig().Formats
  - internal/users/inbox.go - updated direct access to
UserInterface.Formats
  - internal/users/userrecord.prompt.go - updated to use
GetUserInterfaceConfig().Formats
  - modules/gmcp/gmcp.Game.go - updated direct access to
UserInterface.Formats
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