Module: Lich::DragonRealms::CustomSubstitutions Private
- Extended by:
- Common::UserDefs
- Defined in:
- documented/dragonrealms/custom_substitutions.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Merges a player's own substitution/normalization entries (from their character settings) on top of core Lich's built-in defaults, so a player can teach Lich about their own problematic scrolls, creatures, boxes, etc. without waiting for a Lich release.
Core Lich keeps the authoritative default lists as frozen constants; those
are passed in as defaults and are also the fallback when no dr-scripts /
no user additions are present. Only the user's additions are read from
settings and validated here -- defaults are trusted.
The validation, timeout, reporting and memo rules live in Common::UserDefs; this module supplies the settings-backed reading and the per-type dispatch. Every user entry is validated before it is merged. Invalid entries are dropped individually (lenient per-entry: one bad entry never disables the rest) and each rejection is reported to the player through Messaging with the exact key, index, offending value, reason, and consequence.
Results are memoized per settings key (built once, on first use) so hot
parse paths do not repeatedly call get_settings or recompile regexes.
Call Common::UserDefs#reset! to rebuild after a settings reload.
Constant Summary collapse
- MESSAGE_PREFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Prefix on every player-facing message so the source is unambiguous.
'[CustomSubstitutions]'- REGEX_TIMEOUT_SECONDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Per-regex evaluation budget (seconds) applied to every user-supplied pattern. Kept here for callers that reference it; the value is owned by Common::UserDefs::REGEX_TIMEOUT_SECONDS.
Lich::Common::UserDefs::REGEX_TIMEOUT_SECONDS
- SUPPORTED_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Supported validation shapes, dispatched on by resolve and validate_entry:
:pairs--[from, to]literal String substitution pairs:names-- bare canonical-name Strings:regexes-- regular-expression Strings (or pre-compiled Regexps)
%i[pairs names regexes].freeze
Class Method Summary collapse
-
.resolve(key, defaults, type:) ⇒ Array
private
Returns
defaultsmerged with the validated user additions found atkeyin the player's settings, deduplicated and memoized.
Methods included from Common::UserDefs
apply_regexes, extended, reset!
Class Method Details
.resolve(key, defaults, type:) ⇒ Array
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.
Returns defaults merged with the validated user additions found at
key in the player's settings, deduplicated and memoized.
76 77 78 79 80 |
# File 'documented/dragonrealms/custom_substitutions.rb', line 76 def resolve(key, defaults, type:) raise ArgumentError, "unsupported type #{type.inspect}" unless SUPPORTED_TYPES.include?(type) memoize(key) { (Array(defaults) + validated_additions(key, type)).uniq } end |