Module: Lich::Common::PostLoad

Extended by:
Watchable
Defined in:
documented/common/postload.rb

Constant Summary collapse

@@complete =
false
@@game_loaded =
false

Class Method Summary collapse

Methods included from Watchable

watch!

Class Method Details

.complete?Boolean

Checks if the post-load process is complete.

Returns:

  • (Boolean)

    true if complete, false otherwise



45
46
47
# File 'documented/common/postload.rb', line 45

def self.complete?
  @@complete
end

.game_loaded!void

This method returns an undefined value.

Marks the game as loaded.



33
34
35
# File 'documented/common/postload.rb', line 33

def self.game_loaded!
  @@game_loaded = true
end

.game_loaded?Boolean

Checks if the game has been loaded.

Returns:

  • (Boolean)

    true if the game is loaded, false otherwise



39
40
41
# File 'documented/common/postload.rb', line 39

def self.game_loaded?
  @@game_loaded
end

.register(name) { ... } ⇒ Object

Registers a callback with the given name.

Parameters:

  • name (String)

    the name of the callback

Yields:

  • the callback to be executed when conditions are met

Raises:

  • (ArgumentError)

    if no block is given



23
24
25
26
27
28
29
# File 'documented/common/postload.rb', line 23

def self.register(name, &block)
  raise ArgumentError, "PostLoad.register requires a block" unless block_given?

  @mutex.synchronize do
    @callbacks[name.to_s] = block
  end
end

.watch!void

This method returns an undefined value.

Starts watching for game readiness and executes callbacks when ready.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'documented/common/postload.rb', line 51

def self.watch!
  @thread ||= Thread.new do
    begin
      # Phase 1: Wait for base readiness (same as other watchers)
      sleep 0.1 until GameBase::Game.autostarted? &&
                      XMLData.name && !XMLData.name.empty?

      # Phase 2: Wait for game-specific init to signal completion
      sleep 0.1 until @@game_loaded

      # Phase 3: Run registered callbacks
      run_callbacks
    rescue StandardError => e
      respond "--- Lich: error in PostLoad thread: #{e.message}"
      respond e.backtrace.first(5).join("\n") if e.backtrace
    end
  end
end