@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
46 lines (36 loc) • 1.26 kB
JavaScript
import Vector4 from "../../../src/core/geom/Vector4.js";
import { Action } from "../../../src/core/process/undo/Action.js";
import { obtainTerrain } from "../../../src/engine/ecs/terrain/util/obtainTerrain.js";
class PaintTerrainOverlayAction extends Action {
/**
*
* @param {number} entity
* @param {number} x
* @param {number} y
* @param {Vector4} color
* @constructor
*/
constructor(entity, x, y, color) {
super();
this.entity = entity;
this.x = x;
this.y = y;
this.color = color;
this.overlay = null;
this.oldColor = new Vector4();
}
async apply(editor) {
const terrain = obtainTerrain(editor.engine.entityManager.dataset);
const overlay = this.overlay = terrain.overlay;
//remember old color
overlay.readPoint(this.x, this.y, this.oldColor);
overlay.clearPoint(this.x, this.y);
overlay.paintPoint(this.x, this.y, this.color);
}
async revert(editor) {
const overlay = this.overlay;
overlay.clearPoint(this.x, this.y);
overlay.paintPoint(this.x, this.y, this.oldColor);
}
}
export default PaintTerrainOverlayAction;