Module: Lich::Common::XMLParserDelta

Defined in:
documented/common/xmlparser/game_delta.rb

Overview

Game-specific deltas for the shared server-stream parser (XMLParser), composed the way lib/common/map is: the common behavior and the hook interface live here, and each game supplies only what genuinely differs in its own file (lib/gemstone/xml_delta.rb, lib/dragonrealms/xml_delta.rb), which GameLoader requires alongside that game's map delta.

XMLParser asks XMLParserDelta.for for the current game's delta at the point of use instead of being extended once. XMLData exists before the game is known, survives XMLParser#reset, and specs drive bare parsers with a stubbed XMLData.game; resolving per call keeps all of those working.

Hooks cover game semantics only. Differences that are really about the stream dialect (Saga identity vs legacy Wrayth handshake) branch on XMLData.stream_feature? instead.

Defined Under Namespace

Modules: Base, Default

Class Method Summary collapse

Class Method Details

.for(game) ⇒ Module

Returns the registered delta for game, or Default.

Parameters:

  • game (String, nil) —

    XMLData.game

Returns:

  • (Module) —

    the registered delta for game, or Default



48
49
50
51
# File 'documented/common/xmlparser/game_delta.rb', line 48

def self.for(game)
  @registry.each { |pattern, delta| return delta if game.to_s =~ pattern }
  Default
end

.register(pattern, delta) ⇒ void

This method returns an undefined value.

Registers a game's delta module.

Parameters:

  • pattern (Regexp) —

    matched against XMLData.game (e.g. /^DR/)

  • delta (Module) —

    a module extended with Base



41
42
43
44
# File 'documented/common/xmlparser/game_delta.rb', line 41

def self.register(pattern, delta)
  @registry.reject! { |pat, _| pat == pattern }
  @registry << [pattern, delta]
end