"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tile_1 = require("../models/tile");
exports.SPRITE_GRAMMAR = `
    Sprite
        = SpritePixels
        | SpriteNoPixels

    SpriteNoPixels =
        spriteName legendShortcutChar? lineTerminator
        colorNameOrHex+ lineTerminator+

    SpritePixels =
        spriteName legendShortcutChar? lineTerminator
        colorNameOrHex+ lineTerminator+
        PixelRows
        lineTerminator*

    spriteName = ruleVariableName
    pixelRow = pixelDigit+ lineTerminator
    pixelDigit = digit | "."
    legendShortcutChar = (~lineTerminator any)

    // Support at least 5x5 sprites (so we can disambiguate from single-color definitions)
    PixelRows = pixelRow pixelRow pixelRow pixelRow pixelRow+
`;
exports.LEGEND_GRAMMAR = `
    LegendTile
        = LegendTileSimple
        | LegendTileAnd
        | LegendTileOr

    LegendTileSimple = LegendVarNameDefn "=" LookupLegendVarName lineTerminator+
    LegendTileAnd = LegendVarNameDefn "=" NonemptyListOf<LookupLegendVarName, t_AND> lineTerminator+
    LegendTileOr = LegendVarNameDefn "=" NonemptyListOf<LookupLegendVarName, t_OR> lineTerminator+

    LegendVarNameDefn = ruleVariableName | legendVariableChar
    LookupLegendVarName = LegendVarNameDefn
`;
function getTileSemantics(lookup) {
    return {
        Sprite(_1) {
            const gameObject = _1.parse();
            lookup.addToAllObjects(gameObject);
            if (gameObject._optionalLegendChar) {
                // addObjectToAllLegendTiles(gameObject)
                lookup.addObjectToAllLevelChars(gameObject._optionalLegendChar, gameObject);
            }
            else if (gameObject.getName().length === 1) {
                lookup.addObjectToAllLevelChars(gameObject.getName(), gameObject);
            }
            return gameObject;
        },
        SpritePixels(name, optionalLegendChar, _3, colors, _5, pixels, _7) {
            return new tile_1.GameSpritePixels(this.source, name.parse(), optionalLegendChar.parse()[0], colors.parse(), pixels.parse());
        },
        SpriteNoPixels(name, optionalLegendChar, _3, colors, _5) {
            return new tile_1.GameSpriteSingleColor(this.source, name.parse(), optionalLegendChar.parse()[0], colors.parse());
        },
        PixelRows(row1, row2, row3, row4, rows) {
            return [
                row1.parse(),
                row2.parse(),
                row3.parse(),
                row4.parse()
            ].concat(rows.parse());
        },
        LookupLegendVarName(tileName) {
            // Replace all the Sprite Names with the actual objects
            return lookup.lookupObjectOrLegendTile(this.source, tileName.parse());
        },
        LegendTile(tile) {
            const legendTile = tile.parse();
            lookup.addToAllLegendTiles(legendTile);
            if (legendTile.spriteNameOrLevelChar.length === 1) {
                lookup.addLegendToAllLevelChars(legendTile);
            }
            return legendTile;
        },
        LegendTileSimple(spriteNameOrLevelChar, _equals, tile, _whitespace) {
            // TODO: Do the lookup and adding to sets here rather than rewiring in LegendTile
            return new tile_1.GameLegendTileSimple(this.source, spriteNameOrLevelChar.parse(), tile.parse());
        },
        LegendTileAnd(spriteNameOrLevelChar, _equals, tiles, _whitespace) {
            return new tile_1.GameLegendTileAnd(this.source, spriteNameOrLevelChar.parse(), tiles.parse());
        },
        LegendTileOr(spriteNameOrLevelChar, _equals, tiles, _whitespace) {
            return new tile_1.GameLegendTileOr(this.source, spriteNameOrLevelChar.parse(), tiles.parse());
        }
    };
}
exports.getTileSemantics = getTileSemantics;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGlsZUdyYW1tYXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcGFyc2VyL3RpbGVHcmFtbWFyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEseUNBUXVCO0FBSVYsUUFBQSxjQUFjLEdBQUc7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Q0FzQjdCLENBQUE7QUFFWSxRQUFBLGNBQWMsR0FBRzs7Ozs7Ozs7Ozs7O0NBWTdCLENBQUE7QUFFRCxTQUFnQixnQkFBZ0IsQ0FBQyxNQUFvQjtJQUNqRCxPQUFPO1FBQ0gsTUFBTSxDQUFpQixFQUEwQjtZQUM3QyxNQUFNLFVBQVUsR0FBRyxFQUFFLENBQUMsS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