@logic-pad/core
Version:
107 lines (106 loc) • 3.35 kB
JavaScript
import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import CustomSymbol from './customSymbol.js';
class CustomTextSymbol extends CustomSymbol {
/**
* **A custom text symbol**
*
* @param description - The description of the symbol. Leave this empty to hide the description.
* @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
* @param x - The x-coordinate of the symbol.
* @param y - The y-coordinate of the symbol.
* @param text - The text to display.
* @param rotation - The rotation of the text in degrees.
*/
constructor(description, grid, x, y, text, rotation = 0) {
super(description, grid, x, y);
Object.defineProperty(this, "text", {
enumerable: true,
configurable: true,
writable: true,
value: text
});
Object.defineProperty(this, "rotation", {
enumerable: true,
configurable: true,
writable: true,
value: rotation
});
this.text = text;
this.rotation = rotation;
}
get id() {
return `custom_text`;
}
get configs() {
return CustomTextSymbol.CONFIGS;
}
copyWith({ description, grid, x, y, text, rotation, }) {
return new CustomTextSymbol(description ?? this.description, grid ?? this.grid, x ?? this.x, y ?? this.y, text ?? this.text, rotation ?? this.rotation);
}
withText(text) {
return this.copyWith({ text });
}
withRotation(rotation) {
return this.copyWith({ rotation });
}
}
Object.defineProperty(CustomTextSymbol, "EXAMPLE_GRID", {
enumerable: true,
configurable: true,
writable: true,
value: Object.freeze(GridData.create(5, 4))
});
Object.defineProperty(CustomTextSymbol, "CONFIGS", {
enumerable: true,
configurable: true,
writable: true,
value: Object.freeze([
{
type: ConfigType.Number,
default: 0,
field: 'x',
description: 'X',
configurable: false,
},
{
type: ConfigType.Number,
default: 0,
field: 'y',
description: 'Y',
configurable: false,
},
{
type: ConfigType.String,
default: 'A *custom* text symbol',
placeholder: 'Enter description. Emphasize with *asterisks*.',
field: 'description',
description: 'Description',
configurable: true,
},
{
type: ConfigType.Grid,
default: CustomTextSymbol.EXAMPLE_GRID,
field: 'grid',
description: 'Thumbnail Grid',
configurable: true,
},
{
type: ConfigType.String,
default: 'X',
placeholder: 'Short text to be displayed on the symbol',
field: 'text',
description: 'Text',
configurable: true,
},
{
type: ConfigType.Number,
default: 0,
field: 'rotation',
description: 'Rotation',
configurable: true,
},
])
});
export default CustomTextSymbol;
export const instance = new CustomTextSymbol('A *custom* text symbol', GridData.create(5, 4), 0, 0, 'X');