144 lines
6.1 KiB
TypeScript
144 lines
6.1 KiB
TypeScript
import { PlaceStyle, PlaceBlock, PlaceBoard, BoardPosition } from "../confClass";
|
|
/** 靠板类 */
|
|
export class PlacePosition {
|
|
static turnPlacePosition(pb: PlaceBoard, newlocator: BoardPosition, config) {
|
|
const { placeOriginByBoardLocation } = config
|
|
if (placeOriginByBoardLocation == false) return;
|
|
if (pb.isAdnormal()) return; //余料板是余料板,不参与翻转
|
|
let width = pb.width;
|
|
let length = pb.length;
|
|
//右下角靠板
|
|
if (newlocator == BoardPosition.RIGHT_BOTTOM) {
|
|
for (let block of pb.blockList) {
|
|
let x = width - block.placeX - block.placeWidth;
|
|
let y = block.placeY;
|
|
let placeStyle = this.getPlaceStyleLeftRight(block);
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
//右上角靠板
|
|
if (newlocator == BoardPosition.RIGHT_TOP) {
|
|
// console.log('BoardPosition=BoardPosition.RIGHT_TOP');
|
|
for (let block of pb.blockList) {
|
|
|
|
let x = width - block.placeX - block.placeWidth;
|
|
let y = length - block.placeLength - block.placeY;
|
|
let placeStyle = this.getPlaceStyleAcrossCorner(block);
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
//左上角靠板
|
|
if (newlocator == BoardPosition.LEFT_TOP) {
|
|
for (let block of pb.blockList) {
|
|
let x = block.placeX;
|
|
let y = length - block.placeLength - block.placeY;
|
|
let placeStyle = this.getPlaceStyleTopBottom(block);
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
}
|
|
|
|
/** 重置排版位置 */
|
|
static resetPlacePosition(pb: PlaceBoard, config) {
|
|
const { placeOriginByBoardLocation = false, boardLocation } = config
|
|
const newlocator: BoardPosition = boardLocation
|
|
if (placeOriginByBoardLocation == false) return;
|
|
|
|
if (newlocator == BoardPosition.LEFT_BOTTOM) return;
|
|
|
|
let width = pb.width;
|
|
let length = pb.length;
|
|
//右下角靠板
|
|
if (newlocator == BoardPosition.RIGHT_BOTTOM) {
|
|
for (let block of pb.blockList) {
|
|
|
|
let x = width - block.placeX - block.placeWidth;
|
|
let y = block.placeY;
|
|
let placeStyle = this.getPlaceStyleLeftRight(block);
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
|
|
//右上角靠板
|
|
if (newlocator == BoardPosition.RIGHT_TOP) {
|
|
for (let block of pb.blockList) {
|
|
let x = width - block.placeX - block.placeWidth;
|
|
let y = length - block.placeLength - block.placeY;
|
|
let placeStyle = this.getPlaceStyleAcrossCorner(block);
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
//左上角, 靠板
|
|
if (newlocator == BoardPosition.LEFT_TOP) {
|
|
for (let block of pb.blockList) {
|
|
let x = block.placeX;
|
|
let y = length - block.placeLength - block.placeY;
|
|
let placeStyle = this.getPlaceStyleTopBottom(block);
|
|
|
|
block.placeX = x;
|
|
block.placeY = y;
|
|
block.placeStyle = placeStyle;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** 获得新的放置方式(左右翻) */
|
|
static getPlaceStyleLeftRight(block: PlaceBlock): PlaceStyle {
|
|
if (block.placeStyle == PlaceStyle.FRONT) return PlaceStyle.BACK;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_RIGHT) return PlaceStyle.BACK_TURN_LEFT;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_BACK) return PlaceStyle.BACK_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_LEFT) return PlaceStyle.BACK_TURN_RIGHT;
|
|
|
|
if (block.placeStyle == PlaceStyle.BACK) return PlaceStyle.FRONT;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_LEFT) return PlaceStyle.FRONT_TURN_RIGHT;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_BACK) return PlaceStyle.FRONT_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_RIGHT) return PlaceStyle.FRONT_TURN_LEFT;
|
|
|
|
return PlaceStyle.FRONT;
|
|
|
|
|
|
}
|
|
|
|
/** 获得新的放置方式(上下翻) */
|
|
static getPlaceStyleTopBottom(block: PlaceBlock): PlaceStyle {
|
|
if (block.placeStyle == PlaceStyle.FRONT) return PlaceStyle.BACK_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_RIGHT) return PlaceStyle.BACK_TURN_RIGHT;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_BACK) return PlaceStyle.BACK;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_LEFT) return PlaceStyle.BACK_TURN_LEFT;
|
|
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_BACK) return PlaceStyle.FRONT;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_RIGHT) return PlaceStyle.FRONT_TURN_RIGHT;
|
|
if (block.placeStyle == PlaceStyle.BACK) return PlaceStyle.FRONT_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_LEFT) return PlaceStyle.FRONT_TURN_LEFT;
|
|
|
|
return PlaceStyle.FRONT;
|
|
}
|
|
|
|
/** 获得新的放置方式(对角翻) */
|
|
static getPlaceStyleAcrossCorner(block: PlaceBlock): PlaceStyle {
|
|
if (block.placeStyle == PlaceStyle.FRONT) return PlaceStyle.FRONT_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_RIGHT) return PlaceStyle.FRONT_TURN_LEFT;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_BACK) return PlaceStyle.FRONT;
|
|
if (block.placeStyle == PlaceStyle.FRONT_TURN_LEFT) return PlaceStyle.FRONT_TURN_RIGHT;
|
|
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_BACK) return PlaceStyle.BACK;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_RIGHT) return PlaceStyle.BACK_TURN_LEFT;
|
|
if (block.placeStyle == PlaceStyle.BACK) return PlaceStyle.BACK_TURN_BACK;
|
|
if (block.placeStyle == PlaceStyle.BACK_TURN_LEFT) return PlaceStyle.BACK_TURN_RIGHT;
|
|
|
|
return PlaceStyle.FRONT;
|
|
}
|
|
|
|
}
|