"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const BlockLocation_1 = require("./../minecraft/BlockLocation");
const ActionSet_1 = require("../actions/ActionSet");
const ste_events_1 = require("ste-events");
const ActionSetScriptGenerator_1 = require("../script/ActionSetScriptGenerator");
const IActionSetData_1 = require("../actions/IActionSetData");
class WorldTestArea {
    _test;
    data;
    scripts;
    _location;
    _onPropertyChanged = new ste_events_1.EventDispatcher();
    getProperty(id) {
        switch (id) {
            case "location":
                return this.location.toArray();
        }
    }
    setProperty(id, value) {
        switch (id) {
            case "location":
                this.location = BlockLocation_1.default.from(value);
        }
    }
    getBaseValue() {
        return this.data;
    }
    setBaseValue(value) {
        this.data = value;
    }
    get onPropertyChanged() {
        return this._onPropertyChanged.asEvent();
    }
    get location() {
        if (!this._location) {
            let x = 0;
            let y = 0;
            let z = 0;
            if (this.data.location && this.data.location.length && this.data.location.length === 3) {
                x = this.data.location[0];
                y = this.data.location[1];
                z = this.data.location[2];
            }
            this._location = new BlockLocation_1.default(x, y, z);
        }
        return this._location;
    }
    set location(location) {
        if ((!this._location && location) ||
            (this._location &&
                (this._location.x !== location.x || this._location.y !== location.y || this._location.z !== location.z))) {
            this._location = location;
            for (let i = 0; i < this.scripts.length; i++) {
                this.scripts[i].locationRoot = this._location.toLocation();
            }
            this._onPropertyChanged.dispatch(this, "location");
        }
    }
    get title() {
        const loc = this.location;
        return "test" + loc.title;
    }
    constructor(test, data) {
        this.scripts = [];
        this.data = data;
        this._test = test;
    }
    generateGameTestJavaScript(groupName) {
        const scripts = [];
        for (let i = 0; i < this.scripts.length; i++) {
            const script = this.scripts[i];
            let scriptName = groupName;
            if (this.scripts.length > 1) {
                scriptName += (i + 1).toString();
            }
            scripts.push(ActionSetScriptGenerator_1.default.generateGameTestJavaScript(script, scriptName, (i + 1).toString(), this._test.name));
        }
        return scripts.join("\r\n");
    }
    createScript(type) {
        const as = new ActionSet_1.default({
            name: "Area Script",
            targetType: IActionSetData_1.ActionSetTarget.worldTest,
            actions: [],
        });
        if (as) {
            if (this._location) {
                as.locationRoot = this._location.toLocation();
            }
            this.scripts.push(as);
            if (!this.data.scripts) {
                this.data.scripts = [];
            }
            this.data.scripts.push(as.actionSetData);
        }
    }
}
exports.default = WorldTestArea;

//# sourceMappingURL=../maps/worldtest/WorldTestArea.js.map
