Module: Lich::Common::InstanceSettings
- Defined in:
- documented/common/settings/instance_settings.rb
Overview
Settings accessor for core Lich functionality that runs outside Script context.
Provides character-scoped and game-scoped settings access via a fixed 'core' script name, allowing data persistence in DRParser, command handlers, and other contexts where Script.current is unavailable.
Constant Summary collapse
- SCRIPT_NAME =
Script name used for core Lich functionality This allows Settings API to work without Script.current context
'core'
Class Method Summary collapse
-
.[](name) ⇒ Object
Get a value from character-scoped settings.
-
.[]=(name, value) ⇒ Object
Set a value in character-scoped settings.
-
.character_proxy ⇒ SettingsProxy
Returns a root proxy for character-scoped settings Use this for complex nested operations that auto-persist.
-
.character_scope ⇒ String
Returns the character-specific scope string (game:name).
-
.game ⇒ Module
Convenience accessor for game-scoped data Returns a module that provides [] and []= for game-scoped access.
-
.game_proxy ⇒ SettingsProxy
Returns a root proxy for game-scoped settings (see the note at the top of this file about several sessions).
-
.game_scope ⇒ String
Returns the game-wide scope string (game only).
-
.load ⇒ Object
Deprecated no-op methods for compatibility.
-
.save ⇒ nil
deprecated
private
Deprecated.
Settings are auto-persisted; explicit save is not applicable
-
.to_hash ⇒ Hash
Returns a hash snapshot of character-scoped settings Note: This returns a copy; modifications won't auto-persist.
Class Method Details
.[](name) ⇒ Object
Get a value from character-scoped settings
68 69 70 |
# File 'documented/common/settings/instance_settings.rb', line 68 def self.[](name) Settings.get_scoped_setting(character_scope, name, script_name: SCRIPT_NAME) end |
.[]=(name, value) ⇒ Object
Set a value in character-scoped settings
75 76 77 |
# File 'documented/common/settings/instance_settings.rb', line 75 def self.[]=(name, value) Settings.set_script_settings(character_scope, name, value, script_name: SCRIPT_NAME) end |
.character_proxy ⇒ SettingsProxy
Returns a root proxy for character-scoped settings Use this for complex nested operations that auto-persist
82 83 84 |
# File 'documented/common/settings/instance_settings.rb', line 82 def self.character_proxy Settings.root_proxy_for(character_scope, script_name: SCRIPT_NAME) end |
.character_scope ⇒ String
Returns the character-specific scope string (game:name)
55 56 57 |
# File 'documented/common/settings/instance_settings.rb', line 55 def self.character_scope "#{XMLData.game}:#{XMLData.name}" end |
.game ⇒ Module
Convenience accessor for game-scoped data Returns a module that provides [] and []= for game-scoped access
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'documented/common/settings/instance_settings.rb', line 96 def self.game @game_accessor ||= Module.new do extend self # Retrieves a value from game-scoped settings. # # @param name [String, Symbol] the key to retrieve # @return [Object, nil] the stored value, or nil if not found def self.[](name) InstanceSettings.game_proxy[name] end # Stores a value in game-scoped settings. # # @param name [String, Symbol] the key to store # @param value [Object] the value to persist # @return [Object] the value stored def self.[]=(name, value) proxy = InstanceSettings.game_proxy proxy[name] = value end # Returns a hash snapshot of all game-scoped settings. # # @return [Hash] a copy of the game settings; modifications won't auto-persist def self.to_hash Settings.current_script_settings( InstanceSettings.game_scope, script_name: InstanceSettings::SCRIPT_NAME ) end end end |
.game_proxy ⇒ SettingsProxy
Returns a root proxy for game-scoped settings (see the note at the top of this file about several sessions)
89 90 91 |
# File 'documented/common/settings/instance_settings.rb', line 89 def self.game_proxy Settings.root_proxy_for(game_scope, script_name: SCRIPT_NAME) end |
.game_scope ⇒ String
Returns the game-wide scope string (game only)
61 62 63 |
# File 'documented/common/settings/instance_settings.rb', line 61 def self.game_scope XMLData.game end |
.load ⇒ Object
Deprecated no-op methods for compatibility
143 144 145 146 |
# File 'documented/common/settings/instance_settings.rb', line 143 def self.load Lich.deprecated('InstanceSettings.load', 'not using, not applicable,', caller[0], fe_log: true) nil end |
.save ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Settings are auto-persisted; explicit save is not applicable
Deprecated no-op method retained for compatibility.
153 154 155 156 |
# File 'documented/common/settings/instance_settings.rb', line 153 def self.save Lich.deprecated('InstanceSettings.save', 'not using, not applicable,', caller[0], fe_log: true) nil end |
.to_hash ⇒ Hash
Returns a hash snapshot of character-scoped settings Note: This returns a copy; modifications won't auto-persist
133 134 135 136 137 138 139 140 |
# File 'documented/common/settings/instance_settings.rb', line 133 def self.to_hash Settings.wrap_value_if_container( Settings.current_script_settings(character_scope, script_name: SCRIPT_NAME), character_scope, [], script_name: SCRIPT_NAME ) end |