@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
141 lines (140 loc) • 3.91 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageItem = void 0;
const ColorUtilities_1 = __importDefault(require("../core/ColorUtilities"));
const IImageEdits_1 = require("./IImageEdits");
class ImageItem {
data;
imageElement;
isImageElementLoaded;
constructor(_data) {
this.data = _data;
}
get isFilled() {
if (!this.data || !this.data.isFilled) {
return false;
}
return this.data.isFilled;
}
set isFilled(filled) {
this.data.isFilled = filled;
}
get coords() {
return this.data.coords;
}
get fixedWidth() {
if (this.data) {
return this.data.fixedWidth;
}
return undefined;
}
set fixedWidth(fixedWidth) {
this.data.fixedWidth = fixedWidth;
}
get fixedHeight() {
if (this.data) {
return this.data.fixedHeight;
}
return undefined;
}
set fixedHeight(fixedHeight) {
this.data.fixedHeight = fixedHeight;
}
get strokeColor() {
if (!this.data || !this.data.strokeColor) {
return {
red: 0,
green: 0,
blue: 0,
};
}
return this.data.strokeColor;
}
get strokeColorCss() {
return ColorUtilities_1.default.toCss(this.strokeColor);
}
get imageData() {
return this.data.imageData;
}
set imageData(imageData) {
this.data.imageData = imageData;
}
get x() {
return this.data.origin.x;
}
get y() {
return this.data.origin.y;
}
get coord0x() {
if (!this.data || !this.data.coords || this.data.coords.length <= 0) {
return this.x;
}
return this.data.coords[0].x;
}
set coord0x(newX) {
if (!this.data.coords) {
this.data.coords = [];
}
if (this.data.coords.length < 1) {
this.data.coords.push({ x: newX, y: this.y });
}
else {
this.data.coords[0].x = newX;
}
}
get coord0y() {
if (!this.data || !this.data.coords || this.data.coords.length <= 0) {
return this.y;
}
return this.data.coords[0].y;
}
set coord0y(newY) {
if (!this.data.coords) {
this.data.coords = [];
}
if (this.data.coords.length < 1) {
this.data.coords.push({ x: this.x, y: newY });
}
else {
this.data.coords[0].y = newY;
}
}
get type() {
return this.data.type;
}
get allPixels() {
let pixels = [];
if (this.data.type === IImageEdits_1.ImageItemType.pixelSet && this.data.coords.length === 1) {
pixels.push({ x: this.x, y: this.y });
}
else if (this.data.type === IImageEdits_1.ImageItemType.line && this.data.coords.length === 1) {
let x0 = this.x;
let y0 = this.y;
let x1 = this.data.coords[0].x;
let y1 = this.data.coords[0].y;
let dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
let dy = -Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
let err = dx + dy, e2;
while (true) {
pixels.push({ x: x0, y: y0 });
if (x0 === x1 && y0 === y1) {
break;
}
e2 = 2 * err;
if (e2 >= dy) {
err += dy;
x0 += sx;
}
if (e2 <= dx) {
err += dx;
y0 += sy;
}
}
}
return pixels;
}
}
exports.ImageItem = ImageItem;