1
1
Fork 0
This repository has been archived on 2024-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
blueheartforever-web/src/types.ts
2023-11-02 05:05:16 +03:00

38 lines
1,004 B
TypeScript

export type MemoryBox = HTMLDivElement;
export interface MemoryInfo {
name: string
memory: string
}
export class MemoryPage {
readonly memories: MemoryInfo[];
readonly memoryBox: MemoryBox;
protected currentMemoryIndex: number;
constructor(memories: MemoryInfo[], memoryBox: MemoryBox) {
this.memories = memories;
this.memoryBox = memoryBox;
this.currentMemoryIndex = 0;
}
goToNextMemory() {
this.currentMemoryIndex = (this.currentMemoryIndex + 1) % this.memories.length;
this.renderMemorybox();
}
goToPreviousMemory() {
this.currentMemoryIndex = (this.currentMemoryIndex - 1) % this.memories.length;
this.renderMemorybox();
}
renderMemorybox() {
const memoryInfo = this.memories[this.currentMemoryIndex];
if (memoryInfo) {
this.memoryBox.innerHTML = `
<h2>${memoryInfo.name}</h2>
<p>${memoryInfo.memory}</p>
`;
}
}
}