made ui more modular
This commit is contained in:
@@ -1,22 +1,41 @@
|
||||
|
||||
declare var PUBLIC_URL: string;
|
||||
declare const PLANT_COUNT = 8;
|
||||
|
||||
|
||||
import { Controller } from ".";
|
||||
|
||||
export class PlantViews {
|
||||
getConfig(): PlantConfig[] {
|
||||
const rv: PlantConfig[] = [];
|
||||
for (let i = 0; i < PLANT_COUNT; i++) {
|
||||
rv[i] = this.plants[i].getConfig();
|
||||
}
|
||||
return rv
|
||||
}
|
||||
update(moisture_a: [number], moisture_b: [number]) {
|
||||
for (let plantId = 0; plantId < PLANT_COUNT; plantId++) {
|
||||
const a = moisture_a[plantId]
|
||||
const b = moisture_b[plantId]
|
||||
this.plants[plantId].update(a,b)
|
||||
}
|
||||
}
|
||||
|
||||
setConfig(plants: PlantConfig[]) {
|
||||
for (let plantId = 0; plantId < PLANT_COUNT; plantId++) {
|
||||
const plantConfig = plants[plantId];
|
||||
const plantView = this.plants[plantId];
|
||||
plantView.setConfig(plantConfig)
|
||||
}
|
||||
}
|
||||
private readonly plants: PlantView[] = []
|
||||
private readonly plantsDiv: HTMLDivElement
|
||||
|
||||
constructor(syncConfig:Controller) {
|
||||
this.plantsDiv = document.getElementById("plants") as HTMLDivElement;
|
||||
for (let plantId = 0; plantId < 8; plantId++) {
|
||||
for (let plantId = 0; plantId < PLANT_COUNT; plantId++) {
|
||||
this.plants[plantId] = new PlantView(plantId, this.plantsDiv, syncConfig);
|
||||
}
|
||||
}
|
||||
|
||||
getPlant(plantId: number) {
|
||||
return this.plants[plantId]
|
||||
}
|
||||
}
|
||||
|
||||
export class PlantView {
|
||||
@@ -113,6 +132,11 @@ export class PlantView {
|
||||
}
|
||||
console.log(this)
|
||||
}
|
||||
|
||||
update(a: number, b: number) {
|
||||
this.moistureA.innerText = String(a)
|
||||
this.moistureB.innerText = String(b)
|
||||
}
|
||||
|
||||
setConfig(plantConfig: PlantConfig) {
|
||||
console.log("apply config to ui plant " + this.plantId + " config: " + JSON.stringify(plantConfig))
|
||||
|
||||
Reference in New Issue
Block a user