This commit is contained in:
2025-03-26 01:49:19 +09:00
parent d3204cd8bb
commit 1477412883

View File

@@ -88,20 +88,12 @@ if settings.startup['PHI-CT'].value then
return math.floor(math.atan2(vec.x, -vec.y) * (4 / math.pi) + 0.5) % 8
end
function math2d.direction.to_vector(dir)
return math2d.direction.vectors[(dir % 8) + 1]
end
function inserter_utils.get_prototype(obj)
if obj.object_name == "LuaEntity" then
return (obj.type == "entity-ghost" and obj.ghost_prototype) or obj.prototype
end
return (obj.object_name == "LuaEntityPrototype" and obj) or nil
return (obj.object_name == 'LuaEntity' and ((obj.type == 'entity-ghost' and obj.ghost_prototype) or obj.prototype)) or ((obj.object_name == 'LuaEntityPrototype' and obj) or nil)
end
function inserter_utils.is_inserter(entity)
return entity and entity.object_name == "LuaEntity" and (entity.type == "inserter" or (entity.type == "entity-ghost" and entity.ghost_type == "inserter"))
return (entity and entity.object_name == 'LuaEntity') and (entity.type == 'inserter' or (entity.type == 'entity-ghost' and entity.ghost_type == 'inserter'))
end
function inserter_utils.get_arm_positions(inserter)
@@ -246,7 +238,7 @@ if settings.startup['PHI-CT'].value then
local old_positions = inserter_utils.get_arm_positions(inserter)
local new_drop_dir = math2d.direction.from_vector(new_positions.drop)
local delta = (new_drop_dir - math2d.direction.from_vector(old_positions.drop)) % 8
new_positions.drop_offset = (not new_positions.drop and old_positions.drop_offset) or (((delta % 2 == 0) and {x = ((delta == 0 or delta == 6) and old_positions.drop_offset.y) or -old_positions.drop_offset.y, y = ((delta == 0 or delta == 2) and old_positions.drop_offset.x) or -old_positions.drop_offset.x}) or math2d.direction.to_vector(new_drop_dir + (new_drop_dir % 2) * 4 ))
new_positions.drop_offset = (not new_positions.drop and old_positions.drop_offset) or (((delta % 2 == 0) and {x = ((delta == 0 or delta == 6) and old_positions.drop_offset.y) or -old_positions.drop_offset.y, y = ((delta == 0 or delta == 2) and old_positions.drop_offset.x) or -old_positions.drop_offset.x}) or math2d.direction.vectors[(new_drop_dir + (new_drop_dir % 2) * 4 % 8) + 1])
inserter_utils.set_arm_positions(inserter, new_positions)
elseif event.button == defines.mouse_button_type.right or (event.button == defines.mouse_button_type.left and (event.control or event.shift)) then
@@ -356,11 +348,11 @@ if settings.startup['PHI-CT'].value then
local max_range = inserter_utils.get_max_range(e.destination)
if math.max(math.abs(arm_positions.drop.x), math.abs(arm_positions.drop.y)) > max_range then
arm_positions.drop = math2d.position.multiply_scalar(math2d.direction.to_vector(math2d.direction.from_vector(arm_positions.drop)), max_range)
arm_positions.drop = math2d.position.multiply_scalar(math2d.direction.vectors[(math2d.direction.from_vector(arm_positions.drop) % 8) + 1], max_range)
end
if math.max(math.abs(arm_positions.pickup.x), math.abs(arm_positions.pickup.y)) > max_range then
arm_positions.pickup = math2d.position.multiply_scalar(math2d.direction.to_vector(math2d.direction.from_vector(arm_positions.pickup)), max_range)
arm_positions.pickup = math2d.position.multiply_scalar(math2d.direction.vectors[(math2d.direction.from_vector(arm_positions.pickup) % 8) + 1], max_range)
end
if math2d.position.equal(arm_positions.pickup, arm_positions.drop) then