Class: PFM::Message::Instructions

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb

Overview

Parse & List all the instructions to draw the message box content

Defined Under Namespace

Modules: NewLine Classes: Marker, Text

Constant Summary collapse

MARKER_REGEXP =

Regexp used to detect markers

/([\x01-\x0F]\[[^\]]+\])/
MARKER_DATA =

Regexp to grab the marker data

/\[([^\]]+)\]/
SPACE_SPLIT_PRESERVE_REGEXP =

Regexp that split text with space but preserver space in split output

/( )/
IMAGE_MARKER_ID =

ID of image marker

15
BIG_TEXT_MARKER_ID =

ID of big text marker

4

Instance Method Summary collapse

Constructor Details

#initialize(properties, width, width_computer) ⇒ Instructions

Create a new Instructions instance

Parameters:

  • properties (Properties)

    Message box properties

  • width (Integer)

    width of the surface used to draw the message

  • width_computer (WidthComputer)

    object helping to compute the width of the words



22
23
24
25
26
27
28
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 22

def initialize(properties, width, width_computer)
  @properties = properties
  @width = width
  @width_computer = width_computer
  @is_big = false
  @lines = []
end

Instance Method Details

#current_line_widthInteger

Get the width of the current line

Returns:



75
76
77
78
79
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 75

def current_line_width
  return 0 if done_processing?

  return @lines[@line].sum(&:width)
end

#done_processing?Boolean

Tell if processing is done

Returns:

  • (Boolean)


52
53
54
55
56
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 52

def done_processing?
  return true unless @line && @index

  return @lines[@line].nil?
end

#getText, ...

Get current instruction and prepare next instruction

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 60

def get
  return nil if done_processing?

  instruction = @lines[@line][@index]
  @index += 1
  if @lines[@line].size <= @index
    @index = 0
    @line += 1
  end

  return instruction
end

#parse

Parse the message



31
32
33
34
35
36
37
38
39
40
41
42
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 31

def parse
  @total_width = 0
  @current_line = []
  split_text_and_markers.each do |data|
    next parse_marker(data) if marker?(data)

    next parse_text(data)
  end
  push_line # Ensure the current line gets pushed if message does not terminate with \n
  @lines.pop while @lines.any? && (@lines.last.empty? || @lines.last.first == NewLine) # Remove all non-necessary lines
  @lines.last.pop if @lines.any? && @lines.last.any? && @lines.last.last == NewLine # Remove the last new line (unecessary)
end

#start_processing

Start instruction procesing



45
46
47
48
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00003 Instructions.rb', line 45

def start_processing
  @line = 0
  @index = 0
end