-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72c74f3
commit e4e9816
Showing
27 changed files
with
197 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { HistoryObservable, IEqualityComparer, Result } from "../foundation"; | ||
import { HistoryObservable } from "../foundation"; | ||
import { I18nKeys } from "../i18n"; | ||
import { IShape } from "../shape"; | ||
import { Matrix4 } from "../math"; | ||
import { Serializer } from "../serialize"; | ||
|
||
export abstract class Entity extends HistoryObservable { | ||
protected shouldRegenerate: boolean = true; | ||
abstract display: I18nKeys; | ||
|
||
protected _shape: Result<IShape> = Result.err("Not initialised"); | ||
get shape(): Result<IShape> { | ||
if (this.shouldRegenerate) { | ||
this._shape = this.generateShape(); | ||
this.shouldRegenerate = false; | ||
} | ||
return this._shape; | ||
protected _matrix: Matrix4 = Matrix4.identity(); | ||
@Serializer.serialze() | ||
get matrix(): Matrix4 { | ||
return this._matrix; | ||
} | ||
|
||
protected setPropertyAndUpdate<K extends keyof this>( | ||
property: K, | ||
newValue: this[K], | ||
onPropertyChanged?: (property: K, oldValue: this[K]) => void, | ||
equals?: IEqualityComparer<this[K]>, | ||
) { | ||
if (this.setProperty(property, newValue, onPropertyChanged, equals)) { | ||
this.shouldRegenerate = true; | ||
this.emitShapeChanged(); | ||
} | ||
} | ||
|
||
protected emitShapeChanged() { | ||
this.emitPropertyChanged("shape", this._shape); | ||
set matrix(value: Matrix4) { | ||
this.setProperty( | ||
"matrix", | ||
value, | ||
(_p, oldMatrix) => { | ||
this.onMatrixChanged(value, oldMatrix); | ||
}, | ||
{ | ||
equals: (left, right) => left.equals(right), | ||
}, | ||
); | ||
} | ||
|
||
protected abstract generateShape(): Result<IShape>; | ||
protected onMatrixChanged(newMatrix: Matrix4, oldMatrix: Matrix4): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.