Edit mode track updates
This commit is contained in:
parent
10d462edaf
commit
2176f67413
@ -58,7 +58,7 @@ export function getContext() {
|
||||
return ctx;
|
||||
}
|
||||
export function getContextItem<K extends keyof ContextMap>(
|
||||
prop: string,
|
||||
prop: K,
|
||||
): ContextMap[K];
|
||||
export function getContextItem<T>(prop: string): T;
|
||||
export function getContextItem<T>(prop: string): T {
|
||||
|
@ -51,7 +51,7 @@ export class EditTrackState extends State<States> {
|
||||
p.set(mousePos);
|
||||
p.add(relativePoint);
|
||||
});
|
||||
segment.recalculateTiePoints();
|
||||
segment.update();
|
||||
|
||||
const ends = track.findEnds();
|
||||
setContextItem("showEnds", true);
|
||||
@ -130,7 +130,7 @@ export class EditTrackState extends State<States> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.ghostSegment.recalculateTiePoints();
|
||||
this.ghostSegment.update();
|
||||
|
||||
// } else if (closestEnd) {
|
||||
// this.closestEnd = closestEnd;
|
||||
@ -245,6 +245,7 @@ export class EditTrackState extends State<States> {
|
||||
|
||||
if (translation.x !== 0 || translation.y !== 0) {
|
||||
track.translate(translation);
|
||||
track.recalculateAll();
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -35,7 +35,7 @@ export class TrackSystem {
|
||||
|
||||
recalculateAll() {
|
||||
for (const segment of this._segments.values()) {
|
||||
segment.recalculateRailPoints();
|
||||
segment.update();
|
||||
segment.length = segment.calculateApproxLength();
|
||||
}
|
||||
}
|
||||
@ -290,9 +290,7 @@ export class TrackSegment extends PathSegment {
|
||||
super(p);
|
||||
this.doodler = getContextItem<Doodler>("doodler");
|
||||
this.id = id ?? crypto.randomUUID();
|
||||
this.recalculateRailPoints();
|
||||
this.recalculateTiePoints();
|
||||
this.updateAABB();
|
||||
this.update();
|
||||
}
|
||||
|
||||
updateAABB() {
|
||||
@ -301,7 +299,7 @@ export class TrackSegment extends PathSegment {
|
||||
let minY = Infinity;
|
||||
let maxY = -Infinity;
|
||||
|
||||
this.points.forEach((p) => {
|
||||
[...this.normalPoints, ...this.antiNormalPoints].forEach((p) => {
|
||||
minX = Math.min(minX, p.x);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
@ -349,6 +347,12 @@ export class TrackSegment extends PathSegment {
|
||||
this.evenPoints = this.calculateEvenlySpacedPoints(this.length / spacing);
|
||||
}
|
||||
|
||||
update() {
|
||||
this.recalculateRailPoints();
|
||||
this.recalculateTiePoints();
|
||||
this.updateAABB();
|
||||
}
|
||||
|
||||
setTrack(t: TrackSystem) {
|
||||
this.track = t;
|
||||
}
|
||||
@ -431,7 +435,8 @@ export class TrackSegment extends PathSegment {
|
||||
// color: "red",
|
||||
// weight: 3,
|
||||
// });
|
||||
|
||||
const debug = getContextItem("debug");
|
||||
if (debug.track) {
|
||||
this.doodler.drawRect(this.aabb.pos, this.aabb.width, this.aabb.height, {
|
||||
color: "lime",
|
||||
});
|
||||
@ -439,6 +444,7 @@ export class TrackSegment extends PathSegment {
|
||||
color: "cyan",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
serialize(): SerializedTrackSegment {
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user