Module: Lich::Common::InstanceSettings

Defined in:
documented/common/settings/instance_settings.rb

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

Class Method Details

.[](name) ⇒ OpenStruct

Retrieves a setting value by name for the current character scope.

Parameters:

  • name (String)

    the name of the setting

Returns:

  • (OpenStruct)

    the setting value



49
50
51
# File 'documented/common/settings/instance_settings.rb', line 49

def self.[](name)
  Settings.get_scoped_setting(character_scope, name, script_name: SCRIPT_NAME)
end

.[]=(name, value) ⇒ Object

Sets a setting value by name for the current character scope.

Parameters:

  • name (String)

    the name of the setting

  • value (OpenStruct)

    the value to set



57
58
59
# File 'documented/common/settings/instance_settings.rb', line 57

def self.[]=(name, value)
  Settings.set_script_settings(character_scope, name, value, script_name: SCRIPT_NAME)
end

.character_proxyOpenStruct

Provides a proxy for accessing character-scoped settings.

Returns:

  • (OpenStruct)

    the character settings proxy



64
65
66
# File 'documented/common/settings/instance_settings.rb', line 64

def self.character_proxy
  Settings.root_proxy_for(character_scope, script_name: SCRIPT_NAME)
end

.character_scopeString

Returns the character scope string for settings access.

Returns:

  • (String)

    the character scope in the format "game:name"



34
35
36
# File 'documented/common/settings/instance_settings.rb', line 34

def self.character_scope
  "#{XMLData.game}:#{XMLData.name}"
end

.gameOpenStruct

Provides access to game-scoped settings.

Returns:

  • (OpenStruct)

    the game settings accessor



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'documented/common/settings/instance_settings.rb', line 78

def self.game
  @game_accessor ||= Module.new do
    extend self

    def self.[](name)
      InstanceSettings.game_proxy[name]
    end

    def self.[]=(name, value)
      proxy = InstanceSettings.game_proxy
      proxy[name] = value
    end

    def self.to_hash
      Settings.current_script_settings(
        InstanceSettings.game_scope,
        script_name: InstanceSettings::SCRIPT_NAME
      )
    end
  end
end

.game_proxyOpenStruct

Provides a proxy for accessing game-scoped settings.

Returns:

  • (OpenStruct)

    the game settings proxy



71
72
73
# File 'documented/common/settings/instance_settings.rb', line 71

def self.game_proxy
  Settings.root_proxy_for(game_scope, script_name: SCRIPT_NAME)
end

.game_scopeString

Returns the game scope string for settings access.

Returns:



41
42
43
# File 'documented/common/settings/instance_settings.rb', line 41

def self.game_scope
  XMLData.game
end

.loadnil

Deprecated.

This method is not applicable.

Loads instance settings (deprecated).

Returns:

  • (nil)

    always returns nil



116
117
118
119
# File 'documented/common/settings/instance_settings.rb', line 116

def self.load
  Lich.deprecated('InstanceSettings.load', 'not using, not applicable,', caller[0], fe_log: true)
  nil
end

.savenil

Deprecated.

This method is not applicable.

Saves instance settings (deprecated).

Returns:

  • (nil)

    always returns nil



125
126
127
128
# File 'documented/common/settings/instance_settings.rb', line 125

def self.save
  Lich.deprecated('InstanceSettings.save', 'not using, not applicable,', caller[0], fe_log: true)
  nil
end

.to_hashHash

Converts the character-scoped settings to a hash.

Returns:

  • (Hash)

    the character settings as a hash



103
104
105
106
107
108
109
110
# File 'documented/common/settings/instance_settings.rb', line 103

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