31 lines
687 B
JavaScript
31 lines
687 B
JavaScript
import { GameScreen } from "./screenGame.js";
|
|
|
|
/**
|
|
* Chart Manager
|
|
* Loads charts from server
|
|
*/
|
|
class ChartManager {
|
|
constructor() {
|
|
this.cache = new Map();
|
|
this.covers = new Map();
|
|
}
|
|
|
|
async get(id) {
|
|
if(!this.cache.has(id)) {
|
|
await fetch("./charts/" + id + "/chart.json")
|
|
.then(res => res.json())
|
|
.then(json => this.cache.set(id, json))
|
|
|
|
this.covers.set(id, loadImage("./charts/" + id + "/cover.jpg"));
|
|
}
|
|
return this.cache.get(id)
|
|
}
|
|
|
|
async loadChart(selectedChart) {
|
|
console.log("loading", selectedChart)
|
|
let ch = await this.get(selectedChart)
|
|
return new GameScreen(ch);
|
|
}
|
|
}
|
|
|
|
export default new ChartManager(); |