Improve color rendering performance
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 279 KiB After Width: | Height: | Size: 279 KiB |
Before Width: | Height: | Size: 705 KiB After Width: | Height: | Size: 697 KiB |
@ -197,7 +197,7 @@
|
||||
<key>scaleMode</key>
|
||||
<enum type="ScaleMode">Smooth</enum>
|
||||
<key>extrude</key>
|
||||
<uint>4</uint>
|
||||
<uint>3</uint>
|
||||
<key>trimThreshold</key>
|
||||
<uint>2</uint>
|
||||
<key>trimMargin</key>
|
||||
@ -507,6 +507,28 @@
|
||||
<key>scale9FromFile</key>
|
||||
<false/>
|
||||
</struct>
|
||||
<key type="filename">sprites/colors/blue.png</key>
|
||||
<key type="filename">sprites/colors/cyan.png</key>
|
||||
<key type="filename">sprites/colors/green.png</key>
|
||||
<key type="filename">sprites/colors/purple.png</key>
|
||||
<key type="filename">sprites/colors/red.png</key>
|
||||
<key type="filename">sprites/colors/uncolored.png</key>
|
||||
<key type="filename">sprites/colors/white.png</key>
|
||||
<key type="filename">sprites/colors/yellow.png</key>
|
||||
<struct type="IndividualSpriteSettings">
|
||||
<key>pivotPoint</key>
|
||||
<point_f>0.5,0.5</point_f>
|
||||
<key>spriteScale</key>
|
||||
<double>1</double>
|
||||
<key>scale9Enabled</key>
|
||||
<false/>
|
||||
<key>scale9Borders</key>
|
||||
<rect>18,18,36,36</rect>
|
||||
<key>scale9Paddings</key>
|
||||
<rect>18,18,36,36</rect>
|
||||
<key>scale9FromFile</key>
|
||||
<false/>
|
||||
</struct>
|
||||
<key type="filename">sprites/debug/acceptor_slot.png</key>
|
||||
<key type="filename">sprites/debug/ejector_slot.png</key>
|
||||
<key type="filename">sprites/misc/hub_direction_indicator.png</key>
|
||||
|
BIN
res_raw/sprites/colors/blue.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
res_raw/sprites/colors/cyan.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
res_raw/sprites/colors/green.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
res_raw/sprites/colors/purple.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
res_raw/sprites/colors/red.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
res_raw/sprites/colors/uncolored.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
res_raw/sprites/colors/white.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
res_raw/sprites/colors/yellow.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
@ -1,122 +1,73 @@
|
||||
import { globalConfig } from "../../core/config";
|
||||
import { smoothenDpi } from "../../core/dpi_manager";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { enumColors, enumColorsToHexCode } from "../colors";
|
||||
import { THEME } from "../theme";
|
||||
import { drawSpriteClipped } from "../../core/draw_utils";
|
||||
|
||||
export class ColorItem extends BaseItem {
|
||||
static getId() {
|
||||
return "color";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return types.enum(enumColors);
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
deserialize(data) {
|
||||
this.color = data;
|
||||
}
|
||||
|
||||
/** @returns {"color"} **/
|
||||
getItemType() {
|
||||
return "color";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BaseItem} other
|
||||
*/
|
||||
equalsImpl(other) {
|
||||
return this.color === /** @type {ColorItem} */ (other).color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {enumColors} color
|
||||
*/
|
||||
constructor(color) {
|
||||
super();
|
||||
this.color = color;
|
||||
this.bufferGenerator = null;
|
||||
}
|
||||
|
||||
getBackgroundColorAsResource() {
|
||||
return THEME.map.resources[this.color];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} diameter
|
||||
* @param {DrawParameters} parameters
|
||||
*/
|
||||
drawItemCenteredImpl(x, y, parameters, diameter = globalConfig.defaultItemDiameter) {
|
||||
if (!this.bufferGenerator) {
|
||||
this.bufferGenerator = this.internalGenerateColorBuffer.bind(this);
|
||||
}
|
||||
|
||||
const realDiameter = diameter * 0.6;
|
||||
const dpi = smoothenDpi(globalConfig.shapesSharpness * parameters.zoomLevel);
|
||||
const key = realDiameter + "/" + dpi + "/" + this.color;
|
||||
const canvas = parameters.root.buffers.getForKey({
|
||||
key: "coloritem",
|
||||
subKey: key,
|
||||
w: realDiameter,
|
||||
h: realDiameter,
|
||||
dpi,
|
||||
redrawMethod: this.bufferGenerator,
|
||||
});
|
||||
|
||||
drawSpriteClipped({
|
||||
parameters,
|
||||
sprite: canvas,
|
||||
x: x - realDiameter / 2,
|
||||
y: y - realDiameter / 2,
|
||||
w: realDiameter,
|
||||
h: realDiameter,
|
||||
originalW: realDiameter * dpi,
|
||||
originalH: realDiameter * dpi,
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {HTMLCanvasElement} canvas
|
||||
* @param {CanvasRenderingContext2D} context
|
||||
* @param {number} w
|
||||
* @param {number} h
|
||||
* @param {number} dpi
|
||||
*/
|
||||
internalGenerateColorBuffer(canvas, context, w, h, dpi) {
|
||||
context.translate((w * dpi) / 2, (h * dpi) / 2);
|
||||
context.scale((dpi * w) / 12, (dpi * h) / 12);
|
||||
|
||||
context.fillStyle = enumColorsToHexCode[this.color];
|
||||
context.strokeStyle = THEME.items.outline;
|
||||
context.lineWidth = 2 * THEME.items.outlineWidth;
|
||||
context.beginCircle(2, -1, 3);
|
||||
context.stroke();
|
||||
context.fill();
|
||||
context.beginCircle(-2, -1, 3);
|
||||
context.stroke();
|
||||
context.fill();
|
||||
context.beginCircle(0, 2, 3);
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
context.fill();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton instances
|
||||
* @type {Object<enumColors, ColorItem>}
|
||||
*/
|
||||
export const COLOR_ITEM_SINGLETONS = {};
|
||||
|
||||
for (const color in enumColors) {
|
||||
COLOR_ITEM_SINGLETONS[color] = new ColorItem(color);
|
||||
}
|
||||
import { globalConfig } from "../../core/config";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { enumColors } from "../colors";
|
||||
import { THEME } from "../theme";
|
||||
|
||||
export class ColorItem extends BaseItem {
|
||||
static getId() {
|
||||
return "color";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return types.enum(enumColors);
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
deserialize(data) {
|
||||
this.color = data;
|
||||
}
|
||||
|
||||
/** @returns {"color"} **/
|
||||
getItemType() {
|
||||
return "color";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BaseItem} other
|
||||
*/
|
||||
equalsImpl(other) {
|
||||
return this.color === /** @type {ColorItem} */ (other).color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {enumColors} color
|
||||
*/
|
||||
constructor(color) {
|
||||
super();
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
getBackgroundColorAsResource() {
|
||||
return THEME.map.resources[this.color];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} diameter
|
||||
* @param {DrawParameters} parameters
|
||||
*/
|
||||
drawItemCenteredClipped(x, y, parameters, diameter = globalConfig.defaultItemDiameter) {
|
||||
const realDiameter = diameter * 0.6;
|
||||
if (!this.cachedSprite) {
|
||||
this.cachedSprite = Loader.getSprite("sprites/colors/" + this.color + ".png");
|
||||
}
|
||||
this.cachedSprite.drawCachedCentered(parameters, x, y, realDiameter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton instances
|
||||
* @type {Object<enumColors, ColorItem>}
|
||||
*/
|
||||
export const COLOR_ITEM_SINGLETONS = {};
|
||||
|
||||
for (const color in enumColors) {
|
||||
COLOR_ITEM_SINGLETONS[color] = new ColorItem(color);
|
||||
}
|
||||
|