@hiddentao/clockwork-engine
Version:
A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering
146 lines (145 loc) • 4.23 kB
JavaScript
/**
* Display Node
*
* OOP-style wrapper around NodeId providing fluent interface for rendering operations.
* All methods delegate to the underlying RenderingLayer.
*/
export class DisplayNode {
constructor(id, rendering) {
this.id = id;
this.rendering = rendering;
}
// Hierarchy (fluent interface)
addChild(child) {
this.rendering.addChild(this.id, child.id);
return this;
}
removeChild(child) {
this.rendering.removeChild(this.id, child.id);
return this;
}
destroy() {
this.rendering.destroyNode(this.id);
}
// Transform (fluent interface)
setPosition(x, y) {
this.rendering.setPosition(this.id, x, y);
return this;
}
setRotation(radians) {
this.rendering.setRotation(this.id, radians);
return this;
}
setScale(scaleX, scaleY) {
this.rendering.setScale(this.id, scaleX, scaleY ?? scaleX);
return this;
}
getRotation() {
return this.rendering.getRotation(this.id);
}
getScale() {
return this.rendering.getScale(this.id);
}
setAnchor(anchorX, anchorY) {
this.rendering.setAnchor(this.id, anchorX, anchorY);
return this;
}
setAlpha(alpha) {
this.rendering.setAlpha(this.id, alpha);
return this;
}
setVisible(visible) {
this.rendering.setVisible(this.id, visible);
return this;
}
setZIndex(z) {
this.rendering.setZIndex(this.id, z);
return this;
}
// Size (fluent interface)
setSize(width, height) {
this.rendering.setSize(this.id, width, height);
return this;
}
getSize() {
return this.rendering.getSize(this.id);
}
// Visual effects (fluent interface)
setTint(color) {
this.rendering.setTint(this.id, color);
return this;
}
setBlendMode(mode) {
this.rendering.setBlendMode(this.id, mode);
return this;
}
setTextureFiltering(filtering) {
this.rendering.setTextureFiltering(this.id, filtering);
return this;
}
// Bounds query
getBounds() {
return this.rendering.getBounds(this.id);
}
// Visual content (fluent interface)
setSprite(textureId) {
this.rendering.setSprite(this.id, textureId);
return this;
}
setAnimatedSprite(textureIds, ticksPerFrame) {
this.rendering.setAnimatedSprite(this.id, textureIds, ticksPerFrame);
return this;
}
playAnimation(loop = false) {
this.rendering.playAnimation(this.id, loop);
return this;
}
stopAnimation() {
this.rendering.stopAnimation(this.id);
return this;
}
setAnimationCompleteCallback(callback) {
this.rendering.setAnimationCompleteCallback(this.id, callback);
return this;
}
// Primitives (fluent interface)
drawRectangle(x, y, width, height, fill, stroke, strokeWidth) {
this.rendering.drawRectangle(this.id, x, y, width, height, fill, stroke, strokeWidth);
return this;
}
drawCircle(x, y, radius, fill, stroke, strokeWidth) {
this.rendering.drawCircle(this.id, x, y, radius, fill, stroke, strokeWidth);
return this;
}
drawPolygon(points, fill, stroke, strokeWidth) {
this.rendering.drawPolygon(this.id, points, fill, stroke, strokeWidth);
return this;
}
drawRoundRect(x, y, width, height, radius, fill, stroke, strokeWidth) {
this.rendering.drawRoundRect(this.id, x, y, width, height, radius, fill, stroke, strokeWidth);
return this;
}
// Line drawing (fluent interface)
drawLine(x1, y1, x2, y2, color, width) {
this.rendering.drawLine(this.id, x1, y1, x2, y2, color, width);
return this;
}
drawPolyline(points, color, width) {
this.rendering.drawPolyline(this.id, points, color, width);
return this;
}
clearGraphics() {
this.rendering.clearGraphics(this.id);
return this;
}
// Access
getId() {
return this.id;
}
getNodeId() {
return this.id;
}
getRendering() {
return this.rendering;
}
}