mirror of
https://github.com/teoxoy/factorio-blueprint-editor.git
synced 2025-03-27 21:39:03 +02:00
fix offset rail pos
This commit is contained in:
parent
daa2742c9f
commit
7554cc76c5
@ -71,7 +71,10 @@ const switchSizeBasedOnDirection = (
|
||||
},
|
||||
direction: number
|
||||
): IPoint => {
|
||||
if (size.width !== size.height && (direction === 2 || direction === 6)) {
|
||||
if (
|
||||
size.width !== size.height &&
|
||||
(direction === 2 || direction === 3 || direction === 6 || direction === 7)
|
||||
) {
|
||||
return { x: size.height, y: size.width }
|
||||
}
|
||||
return { x: size.width, y: size.height }
|
||||
|
@ -94,18 +94,16 @@ export class PaintBlueprintContainer extends PaintContainer {
|
||||
public moveAtCursor(): void {
|
||||
if (!this.visible) return
|
||||
|
||||
const firstRailHere = this.bp.getFirstRailRelatedEntity()
|
||||
const firstRailInBP = this.bpc.bp.getFirstRailRelatedEntity()
|
||||
const firstRailPosHere = this.bp.getFirstRailRelatedEntityPos()
|
||||
const firstRailPosInBP = this.bpc.bp.getFirstRailRelatedEntityPos()
|
||||
|
||||
if (firstRailHere && firstRailInBP) {
|
||||
const frX = this.bpc.gridData.x32 + firstRailHere.position.x
|
||||
const frY = this.bpc.gridData.y32 + firstRailHere.position.y
|
||||
if (firstRailPosHere && firstRailPosInBP) {
|
||||
const frX = this.bpc.gridData.x32 + firstRailPosHere.x
|
||||
const frY = this.bpc.gridData.y32 + firstRailPosHere.y
|
||||
|
||||
// grid offsets
|
||||
const oX =
|
||||
-Math.abs((Math.abs(frX) % 2) - (Math.abs(firstRailInBP.position.x - 1) % 2)) + 1
|
||||
const oY =
|
||||
-Math.abs((Math.abs(frY) % 2) - (Math.abs(firstRailInBP.position.y - 1) % 2)) + 1
|
||||
const oX = -Math.abs((Math.abs(frX) % 2) - (Math.abs(firstRailPosInBP.x - 1) % 2)) + 1
|
||||
const oY = -Math.abs((Math.abs(frY) % 2) - (Math.abs(firstRailPosInBP.y - 1) % 2)) + 1
|
||||
|
||||
this.x = (this.bpc.gridData.x32 + oX) * 32
|
||||
this.y = (this.bpc.gridData.y32 + oY) * 32
|
||||
|
@ -144,17 +144,17 @@ export class PaintEntityContainer extends PaintContainer {
|
||||
if (!this.visible) return
|
||||
|
||||
const railRelatedNames = ['straight_rail', 'curved_rail', 'train_stop']
|
||||
const firstRail = this.bpc.bp.getFirstRailRelatedEntity()
|
||||
const firstRailPos = this.bpc.bp.getFirstRailRelatedEntityPos()
|
||||
|
||||
if (railRelatedNames.includes(this.name) && firstRail) {
|
||||
if (railRelatedNames.includes(this.name) && firstRailPos) {
|
||||
// grid offsets
|
||||
const oX =
|
||||
-Math.abs(
|
||||
(Math.abs(this.bpc.gridData.x32) % 2) - (Math.abs(firstRail.position.x - 1) % 2)
|
||||
(Math.abs(this.bpc.gridData.x32) % 2) - (Math.abs(firstRailPos.x - 1) % 2)
|
||||
) + 1
|
||||
const oY =
|
||||
-Math.abs(
|
||||
(Math.abs(this.bpc.gridData.y32) % 2) - (Math.abs(firstRail.position.y - 1) % 2)
|
||||
(Math.abs(this.bpc.gridData.y32) % 2) - (Math.abs(firstRailPos.y - 1) % 2)
|
||||
) + 1
|
||||
|
||||
this.x = (this.bpc.gridData.x32 + oX) * 32
|
||||
|
@ -344,12 +344,13 @@ export class Blueprint extends EventEmitter {
|
||||
return nr
|
||||
}
|
||||
|
||||
public getFirstRailRelatedEntity(): Entity {
|
||||
return this.entities.find(
|
||||
e =>
|
||||
e.name === 'straight_rail' /* || e.name === 'curved_rail' */ ||
|
||||
e.name === 'train_stop'
|
||||
)
|
||||
public getFirstRailRelatedEntityPos(): IPoint {
|
||||
for (const [, e] of this.entities) {
|
||||
if (e.name === 'straight_rail') return e.position
|
||||
if (e.name === 'train_stop') return e.position
|
||||
if (e.name === 'curved_rail') return { x: e.position.x - 1, y: e.position.y - 1 }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public isEmpty(): boolean {
|
||||
@ -372,8 +373,8 @@ export class Blueprint extends EventEmitter {
|
||||
const maxY = data.reduce((max, d) => Math.max(max, d.y + d.h / 2), -Infinity)
|
||||
|
||||
return {
|
||||
x: Math.floor((minX + maxX) / 2) + 0.5,
|
||||
y: Math.floor((minY + maxY) / 2) + 0.5,
|
||||
x: Math.round((minX + maxX) / 2),
|
||||
y: Math.round((minY + maxY) / 2),
|
||||
}
|
||||
}
|
||||
|
||||
@ -614,11 +615,17 @@ export class Blueprint extends EventEmitter {
|
||||
this.entities.valuesArray().map(e => e.serialize())
|
||||
)
|
||||
const center = this.getCenter()
|
||||
const fR = this.getFirstRailRelatedEntity()
|
||||
if (fR) {
|
||||
center.x += (fR.position.x - center.x) % 2
|
||||
center.y += (fR.position.y - center.y) % 2
|
||||
const firstRailPos = this.getFirstRailRelatedEntityPos()
|
||||
|
||||
if (firstRailPos) {
|
||||
if ((firstRailPos.x - center.x) % 2 === 0) {
|
||||
center.x += 1
|
||||
}
|
||||
if ((firstRailPos.y - center.y) % 2 === 0) {
|
||||
center.y += 1
|
||||
}
|
||||
}
|
||||
|
||||
for (const e of entityInfo) {
|
||||
e.position.x -= center.x
|
||||
e.position.y -= center.y
|
||||
|
@ -435,6 +435,7 @@ do
|
||||
end
|
||||
|
||||
entities['offshore-pump'].size = { width = 1, height = 1 }
|
||||
entities['curved-rail'].size = { width = 4, height = 8 }
|
||||
|
||||
entities['centrifuge'].possible_directions = nil
|
||||
entities['assembling-machine-1'].possible_directions = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user