import {SimpleLevel} from "./SimpleLevel";
import {RowLevel8} from "./RowLevel8";
import {RowLevel10} from "./RowLevel10";
import {SixWordsRowLevel8} from "./SixWordsRowLevel8";
import {SixWordsRowLevel12} from "./SixWordsRowLevel12";
import {FourWordsLevel8} from "./FourWordsLevel8";
import {FourWordsLevel12} from "./FourWordsLevel12";

export class LevelHelper {
    static setLevelType(typeId, level) {
        LevelHelper.types[typeId] = level;
    }

    static getLevelClass(type) {
        return LevelHelper.types[type];
    }

    static inflateLevel(jsonLevel, templateContainer) {
        let level = new (LevelHelper.types[jsonLevel["rendererType"]])(templateContainer);
        level.setWords(jsonLevel["words"]);
        level.setId(jsonLevel["id"]);

        for (let i = 0, n = jsonLevel["rotations"].length; i < n; i++) {
            if (jsonLevel["rotations"][i] <= 4) {
                jsonLevel["rotations"][i] = 90 * jsonLevel["rotations"][i];
            }
        }

        level.setStartRotations(jsonLevel["rotations"]);
        return level;
    }
}

LevelHelper.types = {
    20: SimpleLevel,
    40: RowLevel8,
    60: RowLevel10,
    100: SixWordsRowLevel8,
    120: FourWordsLevel8,
    140: SixWordsRowLevel12,
    160: FourWordsLevel12,
};