Class: Battle::Logic::ChangeHandlerBase

Inherits:
Object
  • Object
show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb

Overview

Class responsive of describing the minimum functionality of change handlers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logic, scene) ⇒ ChangeHandlerBase

Create a new ChangeHandler

Parameters:



14
15
16
17
18
19
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 14

def initialize(logic, scene)
  @logic = logic
  @scene = scene
  # @type [Proc]
  @reason = nil
end

Instance Attribute Details

#logicBattle::Logic (readonly)

Get the logic

Returns:



7
8
9
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 7

def logic
  @logic
end

#sceneBattle::Scene (readonly)

Get the scene

Returns:



10
11
12
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 10

def scene
  @scene
end

Instance Method Details

#prevent_change(&reason) ⇒ :prevent

Function that register a reason why the change is not possible

Parameters:

  • reason (Proc)

    reason that will be registered

Returns:

  • (:prevent)

    :prevent to make easier the return of hooks



34
35
36
37
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 34

def prevent_change(&reason)
  @reason = reason
  return :prevent
end

#process_prevention_reason

Process the reason a change could not be done



22
23
24
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 22

def process_prevention_reason
  @reason&.call
end

#reset_prevention_reason

Reset the reason why change cannot be done



27
28
29
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01000 ChangeHandler.rb', line 27

def reset_prevention_reason
  @reason = nil
end