Reformat code
This commit is contained in:
parent
6e27539eca
commit
420cd788c4
94 changed files with 10592 additions and 2608 deletions
54
src/app/model/tower.ts
Normal file
54
src/app/model/tower.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { ITower } from '../interfaces/persistance/tower';
|
||||
import { Color } from './color';
|
||||
import { Block } from './block';
|
||||
import { Base } from './base';
|
||||
import { IBlock } from '../interfaces/persistance/block';
|
||||
import { hashCode } from '../utils/hash';
|
||||
|
||||
export class Tower extends Base implements ITower {
|
||||
constructor(props: ITower) {
|
||||
super(props);
|
||||
|
||||
// @ts-ignore to prevent update message
|
||||
this.__baseColor = new Color(this.baseColor);
|
||||
|
||||
this.blocks = this.blocks.map(b => this.createBlock(b));
|
||||
this.blocks.sort((a, b) => a.created.getTime() - b.created.getTime());
|
||||
}
|
||||
|
||||
tags: string[];
|
||||
|
||||
// Only here to prevent ts warnings.
|
||||
name: string;
|
||||
blocks: Block[];
|
||||
baseColor: Color;
|
||||
|
||||
addBlock(props: { tag: string; description: string; isDone: boolean }) {
|
||||
this.blocks.push(
|
||||
this.createBlock({
|
||||
created: new Date(),
|
||||
...props
|
||||
})
|
||||
);
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
private createBlock(props: IBlock): Block {
|
||||
const block = new Block(props);
|
||||
block.subscribe(() => this.update());
|
||||
return block;
|
||||
}
|
||||
|
||||
protected update() {
|
||||
this.tags = [];
|
||||
for (const block of this.blocks) {
|
||||
if (!this.tags.includes(block.tag)) {
|
||||
this.tags.push(block.tag);
|
||||
}
|
||||
block.color = this.baseColor.lighten(hashCode(block.tag) * 50);
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue