Fix segfault by moving "register" to the update call, rather than the draw one
This commit is contained in:
parent
d9bcf32e17
commit
70f888196f
1 changed files with 18 additions and 9 deletions
27
main.rb
27
main.rb
|
|
@ -217,10 +217,12 @@ class Hex
|
|||
@hexid = SecureRandom.uuid
|
||||
@dead = false
|
||||
end
|
||||
|
||||
def draw
|
||||
def update
|
||||
amidead?
|
||||
$hex_bgs.register(@hexid, @text_props.bg_color)
|
||||
end
|
||||
def draw
|
||||
amidead?
|
||||
$hex_bgs[@text_props.bg_color].draw(
|
||||
@x, @y, 0, 1, 1, Gosu::Color::WHITE
|
||||
) # layer 0: hex-bg
|
||||
|
|
@ -284,7 +286,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
@old_text = [0,'',0]
|
||||
|
||||
# Hexes
|
||||
@xexes = ((width-$hex_x_offset) / $hex_width).floor # xexes = 'x's of hexes
|
||||
@xexes = ((width-$hex_x_offset) / $hex_width).floor # xexes = 'x's of hexes
|
||||
@yexes = ((height-$hex_tip) / $hex_y_offset ).floor # yexes = 'y's of hexes
|
||||
@next_row_is_shifted = false
|
||||
@hexes = []
|
||||
|
|
@ -301,7 +303,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
|
||||
# Clear the screen
|
||||
@hexes.each do |rex|
|
||||
rex.each do |hex|
|
||||
rex.each do |hex|
|
||||
hex.char = ' '
|
||||
end
|
||||
end
|
||||
|
|
@ -323,7 +325,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
new_text = [
|
||||
self.text_input.selection_start,
|
||||
self.text_input.text,
|
||||
self.text_input.text,
|
||||
self.text_input.caret_pos
|
||||
]
|
||||
if @old_text != new_text
|
||||
|
|
@ -344,6 +346,13 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
print "\x1b[G\x1b[2K#{out}\x1b[#{new_text[2]+1}G"
|
||||
end
|
||||
|
||||
# End of update should call hex updates
|
||||
@hexes.each do |rex|
|
||||
rex.each do |hex|
|
||||
hex.update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
|
|
@ -354,7 +363,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
)
|
||||
# Draw the hexes
|
||||
@hexes.each do |rex| # rex=row of hexes
|
||||
rex.each do |hex|
|
||||
rex.each do |hex|
|
||||
hex.draw
|
||||
end
|
||||
end
|
||||
|
|
@ -404,7 +413,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
Gosu::Color::WHITE
|
||||
]
|
||||
@hexes.each do |rex|
|
||||
rex.each do |hex|
|
||||
rex.each do |hex|
|
||||
hex.y -= $hex_y_offset
|
||||
end
|
||||
end
|
||||
|
|
@ -417,9 +426,9 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
for i in 0..@xexes-1
|
||||
@active_styling.bg_color = Gosu::Color::BLACK
|
||||
@hexes[-1] << Hex.new(
|
||||
(i*$hex_width) + (@next_row_is_shifted? $hex_x_offset : 0),
|
||||
(i*$hex_width) + (@next_row_is_shifted? $hex_x_offset : 0),
|
||||
(@yexes-1)*$hex_y_offset,
|
||||
" ", TextProps.new(@font, @active_styling))
|
||||
" ", TextProps.new(@font, @active_styling))
|
||||
end
|
||||
@next_row_is_shifted = !@next_row_is_shifted
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue