private ConveyorLineSegment[] Slice(int offset, int length) { var copy = new ConveyorLineSegment[length]; Array.Copy(segments, offset, copy, 0, length); return(copy); }
public override void Init(World world) { segment = new ConveyorLineSegment(machinePos.pos, 3, dh, machinePos.direction.Relative(bend), machinePos.direction); world.conveyors.AddSegment(segment); attachment?.Init(world); base.Init(world); }
public void RemoveSegment(ConveyorLineSegment segment) { var split = Array.IndexOf(segments, segment); if (split == -1) { return; } if (split == 0 && segments.Length == 1) { builder.ConveyorLineRemove(this); return; } if (split == 0) { segments = Slice(1, segments.Length - 1); } else if (split == segments.Length - 1) { segments = Slice(0, segments.Length - 1); } else { var part2 = Slice(split + 1, segments.Length - split - 1); segments = Slice(0, split); builder.ConveyorLineCreate(new ConveyorLine(builder, part2)); } Init(); }
private void Increment(int offset, int index, ConveyorLineSegment segment) { var prevSegments = segments; segments = new ConveyorLineSegment[prevSegments.Length + 1]; Array.Copy(prevSegments, 0, segments, offset, prevSegments.Length); segments[index] = segment; Init(); }
public ConveyorLine Merge(ConveyorLineSegment segment, ConveyorLineSegment post) { var addLine = post.line; var prevSegments = segments; segments = new ConveyorLineSegment[prevSegments.Length + 1 + addLine.segments.Length]; Array.Copy(prevSegments, 0, segments, 0, prevSegments.Length); Array.Copy(addLine.segments, 0, segments, prevSegments.Length + 1, addLine.segments.Length); segments[prevSegments.Length] = segment; Init(); return(addLine); }
public void AddSegment(ConveyorLineSegment segment) { ConveyorLineSegment pre = null, post = null; if (segment.input != Direction.Invalid) { var input = new MachinePos(segment.position, segment.input); input.pos.y += segment.deltaH; inputs[input] = segment; outputs.TryGetValue(input.GetConnected(), out pre); } if (segment.output != Direction.Invalid) { var output = new MachinePos(segment.position, segment.output); outputs[output] = segment; inputs.TryGetValue(output.GetConnected(), out post); } if (pre == null) { if (post == null) { ConveyorLineCreate(new ConveyorLine(this, segment)); } else { post.line.Prepend(segment); } } else { if (post == null || post.line == pre.line) { pre.line.Append(segment); } else { ConveyorLineRemove(pre.line.Merge(segment, post)); } } }
public void RemoveSegment(ConveyorLineSegment segment) { segment.line.RemoveSegment(segment); }
public void Append(ConveyorLineSegment segment) { Increment(0, segments.Length, segment); }
public void Prepend(ConveyorLineSegment segment) { Increment(1, 0, segment); }