1
0
mirror of https://github.com/teoxoy/factorio-blueprint-editor.git synced 2025-03-27 21:39:03 +02:00

Support rotate of whole Blueprint

This commit is contained in:
Ken Vogel 2022-02-21 09:14:17 -06:00 committed by Teodor Tanasoaia
parent de9e3a0411
commit 200093f68f
6 changed files with 54 additions and 22 deletions

View File

@ -162,24 +162,26 @@ export class Editor {
registerAction('focus', 'f').bind({ press: () => G.BPC.centerViewport() })
registerAction('rotate', 'r').bind({
press: () => {
if (G.BPC.mode === EditorMode.EDIT) {
G.BPC.hoverContainer.entity.rotate(false, true)
} else if (G.BPC.mode === EditorMode.PAINT) {
G.BPC.paintContainer.rotate()
function doRotate(ccw: boolean): void {
if (G.BPC.mode === EditorMode.EDIT) {
G.BPC.hoverContainer.entity.rotate(false, true)
} else if (G.BPC.mode === EditorMode.PAINT) {
const copies = G.BPC.paintContainer.rotatedEntities(ccw)
if (copies === undefined) {
G.BPC.paintContainer.rotate(ccw)
} else {
G.BPC.paintContainer.destroy()
G.BPC.spawnPaintContainer(copies, 0)
}
},
}
}
registerAction('rotate', 'r').bind({
press: () => doRotate(false)
})
registerAction('reverseRotate', 'shift+r').bind({
press: () => {
if (G.BPC.mode === EditorMode.EDIT) {
G.BPC.hoverContainer.entity.rotate(true, true)
} else if (G.BPC.mode === EditorMode.PAINT) {
G.BPC.paintContainer.rotate(true)
}
},
press: () => doRotate(true)
})
registerAction('pipette', 'q').bind({

View File

@ -85,12 +85,19 @@ export class PaintBlueprintContainer extends PaintContainer {
}
public rotate(): void {
if (!this.visible) return
// TODO: implement
return undefined
}
public rotatedEntities(ccw?: boolean): Entity[] {
if (!this.visible) return undefined
const result = []
for (const [e] of this.entities) {
result.push(e.getRotatedCopy(ccw))
}
return result
}
public moveAtCursor(): void {
if (!this.visible) return

View File

@ -1,5 +1,6 @@
import * as PIXI from 'pixi.js'
import G from '../common/globals'
import { Entity } from '../core/Entity'
import F from '../UI/controls/functions'
import { BlueprintContainer } from './BlueprintContainer'
@ -90,9 +91,12 @@ export abstract class PaintContainer extends PIXI.Container {
// override
public abstract getItemName(): string
// override
// override
public abstract rotate(ccw?: boolean): void
// override
public abstract rotatedEntities(ccw?: boolean): Entity[]
// override
protected abstract redraw(): void

View File

@ -130,6 +130,10 @@ export class PaintEntityContainer extends PaintContainer {
this.moveAtCursor()
}
public rotatedEntities(): Entity[] {
return undefined
}
protected redraw(): void {
this.removeChildren()
const sprites = EntitySprite.getParts({

View File

@ -3,6 +3,7 @@ import { Tile } from '../core/Tile'
import { TileContainer } from './TileContainer'
import { PaintContainer } from './PaintContainer'
import { BlueprintContainer } from './BlueprintContainer'
import { Entity } from '../core/Entity'
export class PaintTileContainer extends PaintContainer {
private static size = 2
@ -67,6 +68,10 @@ export class PaintTileContainer extends PaintContainer {
}
}
public rotatedEntities(): Entity[] {
return undefined
}
protected redraw(): void {
this.removeChildren()
const sprites = TileContainer.generateSprites(

View File

@ -526,17 +526,27 @@ export class Entity extends EventEmitter {
)
}
public rotate(ccw = false, rotateOpposingUB = false): void {
if (!this.canBeRotated) return
public getRotatedCopy(ccw = false): Entity {
const position = ccw
? {x: this.m_rawEntity.position.y, y: -this.m_rawEntity.position.x}
: {x: -this.m_rawEntity.position.y, y: this.m_rawEntity.position.x}
const direction = this.rotateDir(ccw)
return new Entity({...this.m_rawEntity, position, direction}, this.m_BP);
}
private rotateDir(ccw: boolean): number {
if (!this.canBeRotated) return this.direction
const pr = this.entityData.possible_rotations
const newDir =
pr[
return pr[
(pr.indexOf(this.direction) +
(this.size.x !== this.size.y || this.type === 'underground_belt' ? 2 : 1) *
(ccw ? 3 : 1)) %
pr.length
]
}
public rotate(ccw = false, rotateOpposingUB = false): void {
const newDir = this.rotateDir(ccw)
if (newDir === this.direction) return