Class: Hokusai::Automation::DriverCommands::Base

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/automation/driver_commands/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Base

Returns a new instance of Base.



17
18
19
20
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 17

def initialize(hash)
  @state = hash
  @last_parent = nil
end

Instance Attribute Details

#last_parentObject

Returns the value of attribute last_parent.



4
5
6
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 4

def last_parent
  @last_parent
end

#request_idObject

Returns the value of attribute request_id.



4
5
6
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 4

def request_id
  @request_id
end

#stateObject (readonly)

Returns the value of attribute state.



5
6
7
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 5

def state
  @state
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 4

def status
  @status
end

Instance Method Details

#execute(blocks, canvas, input) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 34

def execute(blocks, canvas, input)
  raise NotImplementedError.new("Must implement #{self.class}#execute")
end

#matches_block(block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 38

def matches_block(block)
  return false unless block.node.portal
  
  if location == block.node.portal.uuid.to_s
    
    return true
  end

  false
end

#matches_blocks(blocks) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 49

def matches_blocks(blocks)
  if matches_block(blocks[0]) || (last_parent == blocks[1] && !last_parent.nil?)
    self.last_parent = blocks[0]

    return true
  end

  false
end

#mouse_center(canvas, input) ⇒ Object



60
61
62
63
64
65
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 60

def mouse_center(canvas, input)
  x = canvas.x + (canvas.width / 2)
  y = canvas.y + (canvas.height / 2)
  
  mouse_move(x, y, input)
end

#mouse_move(x, y, input) ⇒ Object



67
68
69
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 67

def mouse_move(x, y, input)
  LibHokusai.hoku_input_set_mouse_position(input, vec2(x, y))
end

#on_complete(&block) ⇒ Object

Raises:

  • (NotImplementedError)


30
31
32
# File 'ui/src/hokusai/automation/driver_commands/base.rb', line 30

def on_complete(&block)
  raise NotImplementedError.new("Must implement #{self.class}#on_complete")
end