import FileLoader from "./FileLoader.js"; import Terrain from "../tilorswift/js/Terrain.js"; export default class Level { constructor(terrain) { this.terrain = terrain; this.gravity = 2.0; } getTilesetId() { return this.terrain.tileset.setId; } getBackgroundColor() { return this.terrain.backgroundColor; } getBackgroundImage() { return this.terrain.backgroundImage; } getRows() { return this.terrain.tilesY; } getColumns() { return this.terrain.tilesX; } getStartX() { return this.terrain.entranceTileX; } getStartY() { return this.terrain.entranceTileY; } getTargetX() { return this.terrain.targetTileX; } getTargetY() { return this.terrain.targetTileY; } getTilesetMatrix() { return this.terrain.fields; } hasEntrancePoint() { return this.terrain.hasEntrancePoint(); } hasTargetPoint() { return this.terrain.hasTargetPoint(); } setGravity(gravity) { this.gravity = gravity; } static createFromFile(filename) { let loader = new FileLoader(filename); let levelData = JSON.parse(loader.getContent()); let terrain = Terrain.createFromJson(levelData); let level = new Level(terrain); level.setGravity(levelData.gravity); return level; } static createFromJson(json) { const data = JSON.parse(json); const terrain = Terrain.createFromJson(data); const level = new Level(terrain); level.setGravity(data.gravity); return level; } }