rubyx/lib/risc/position/object_position.rb
Torsten Ruger 21a9c56ba9 change position event code to use util
general purpose event fireing
can then be used for several event types
2018-05-31 19:05:53 +03:00

43 lines
954 B
Ruby

require "util/eventable"
module Risc
module Position
class ObjectPosition
include Util::Eventable
attr_reader :at , :object
def initialize( object, at)
@at = at
@object = object
@listeners = []
raise "not int #{self}-#{at}" unless @at.is_a?(Integer)
end
def +(offset)
offset = offset.at if offset.is_a?(ObjectPosition)
@at + offset
end
def -(offset)
offset = offset.at if offset.is_a?(ObjectPosition)
@at - offset
end
def to_s
"0x#{@at.to_s(16)}"
end
# just a callback after creation AND insertion
def init(pos , is_nil)
end
def reset_to(pos , guaranteed_nil )
return false if pos == at
if((at - pos).abs > 1000)
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"
end
@at = pos
true
end
end
end
end