2018-05-31 19:05:53 +03:00
|
|
|
require "util/eventable"
|
|
|
|
|
2018-05-10 20:56:12 +03:00
|
|
|
module Risc
|
|
|
|
module Position
|
|
|
|
class ObjectPosition
|
2018-05-31 19:05:53 +03:00
|
|
|
include Util::Eventable
|
|
|
|
|
2018-05-11 18:36:45 +03:00
|
|
|
attr_reader :at , :object
|
2018-05-10 20:56:12 +03:00
|
|
|
|
2018-05-23 21:34:49 +03:00
|
|
|
def initialize( object, at)
|
2018-05-10 20:56:12 +03:00
|
|
|
@at = at
|
2018-05-20 15:52:13 +03:00
|
|
|
@object = object
|
2018-05-31 17:01:23 +03:00
|
|
|
@listeners = []
|
2018-05-10 20:56:12 +03:00
|
|
|
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
|
2018-05-25 19:04:48 +03:00
|
|
|
def init(pos , is_nil)
|
2018-05-10 20:56:12 +03:00
|
|
|
end
|
2018-05-25 19:04:48 +03:00
|
|
|
def reset_to(pos , guaranteed_nil )
|
2018-05-10 20:56:12 +03:00
|
|
|
return false if pos == at
|
2018-05-31 20:41:04 +03:00
|
|
|
trigger(:position_changed , self)
|
2018-05-10 20:56:12 +03:00
|
|
|
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
|