Skip to content

Commit

Permalink
refactor: Update ActivityStoredAbstract and ActivityRoom constructors…
Browse files Browse the repository at this point in the history
… to use ActivityStoredAbstract instead of ActivityModel in onRun parameter
  • Loading branch information
BlackRam-oss committed May 16, 2024
1 parent 7fd1e70 commit 90bf610
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/classes/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export abstract class ActivityStoredAbstract {
abstract get id(): string

private defaultName?: string
/**
* The name
*/
get name(): string {
return this.getStorageProperty<string>("name") || this.defaultName || ""
}
Expand All @@ -84,6 +87,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultFromHour?: number
/**
* The hour when the activity starts. If the activity is not started yet, it will be hidden.
*/
get fromHour(): number {
return this.getStorageProperty<number>("fromHour") || this.defaultFromHour || TimeManager.minDayHours
}
Expand All @@ -92,6 +98,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultToHour?: number
/**
* The hour when the activity ends. If the activity is ended yet, it will be hidden.
*/
get toHour(): number {
return this.getStorageProperty<number>("toHour") || this.defaultToHour || (TimeManager.maxDayHours + 1)
}
Expand All @@ -100,6 +109,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultFromDay?: number
/**
* The day when the activity starts. If the activity is not started yet, it will be hidden.
*/
get fromDay(): number | undefined {
return this.getStorageProperty<number>("fromDay") || this.defaultFromDay
}
Expand All @@ -108,6 +120,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultToDay?: number
/**
* The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
*/
get toDay(): number | undefined {
return this.getStorageProperty<number>("toDay") || this.defaultToDay
}
Expand All @@ -116,6 +131,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultDisabled: boolean | string
/**
* Whether is disabled.
*/
get disabled(): boolean {
let value = this.getStorageProperty<boolean>("disabled") || this.defaultDisabled
if (typeof value === "string") {
Expand All @@ -128,6 +146,9 @@ export abstract class ActivityStoredAbstract {
}

private defaultHidden: boolean | string
/**
* Whether is hidden. If the activity is not started yet, it will be hidden.
*/
get hidden(): boolean {
if (this.fromDay && this.fromDay > TimeManager.currentDay) {
return true
Expand All @@ -149,22 +170,36 @@ export abstract class ActivityStoredAbstract {
}

private _icon?: GraphicItemType
/**
* The icon element.
*/
get icon(): GraphicItemType | undefined {
return this._icon
}

private _onRun: (activity: ActivityStoredAbstract) => void
/**
* The function that is called when the activity is runned.
*/
get onRun(): () => void {
return () => this._onRun(this)
}

/**
* Whether the activity is a deadline.
* @returns Whether the activity is a deadline.
*/
isExpired(): boolean {
if (this.toDay && this.toDay <= TimeManager.currentDay) {
return true
}
return false
}

/**
* Export the activity properties.
* @returns The activity properties.
*/
export(): ActivityProps {
return {
name: this.getStorageProperty<string>("name") || this.defaultName,
Expand Down Expand Up @@ -202,36 +237,57 @@ export default class ActivityModel {
}

private _id: string
/**
* The activity id, that is unique.
*/
get id(): string {
return this._id
}

private _name?: string
/**
* The name
*/
get name(): string | undefined {
return this._name
}

private _fromHour?: number
/**
* The hour when the activity starts. If the activity is not started yet, it will be hidden.
*/
get fromHour(): number | undefined {
return this._fromHour
}

private _toHour?: number
/**
* The hour when the activity ends. If the activity is ended yet, it will be hidden.
*/
get toHour(): number | undefined {
return this._toHour
}

private _fromDay?: number
/**
* The day when the activity starts. If the activity is not started yet, it will be hidden.
*/
get fromDay(): number | undefined {
return this._fromDay
}

private _toDay?: number
/**
* The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
*/
get toDay(): number | undefined {
return this._toDay
}

private _disabled?: boolean | string
/**
* Whether is disabled.
*/
get disabled(): boolean | undefined {
if (typeof this._disabled === "string") {
return getFlag(this._disabled)
Expand All @@ -240,6 +296,9 @@ export default class ActivityModel {
}

private _hidden: boolean | string
/**
* Whether is hidden. If the activity is not started yet, it will be hidden.
*/
get hidden(): boolean {
if (this.fromDay && this.fromDay > TimeManager.currentDay) {
return true
Expand All @@ -254,22 +313,36 @@ export default class ActivityModel {
}

private _icon?: GraphicItemType
/**
* The icon element.
*/
get icon(): GraphicItemType | undefined {
return this._icon
}

private _onRun: OnRunActivityEvent<ActivityModel>
/**
* The function that is called when the activity is runned.
*/
get onRun(): () => void {
return () => this._onRun(this)
}

/**
* Whether the activity is a deadline.
* @returns Whether the activity is a deadline.
*/
isDeadline(): boolean {
if (this.toDay && this.toDay <= TimeManager.currentDay) {
return true
}
return false
}

/**
* Export the activity properties.
* @returns The activity properties.
*/
export(): ActivityProps {
return {
name: this._name,
Expand Down
6 changes: 6 additions & 0 deletions src/classes/navigation/ActivityRoom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ActivityProps, ActivityStoredAbstract, OnRunActivityEvent } from "../Activity";
import RoomBaseModel from "./Room";

/**
* The activity generated by the room.
*/
export class ActivityRoom<TRoom extends RoomBaseModel = RoomBaseModel> extends ActivityStoredAbstract {
constructor(id: string, room: TRoom, onRun: OnRunActivityEvent<ActivityStoredAbstract>, props: ActivityProps) {
super(onRun, props)
Expand All @@ -21,6 +24,9 @@ export class ActivityRoom<TRoom extends RoomBaseModel = RoomBaseModel> extends A
get id(): string {
return this._id;
}
/**
* The room where the activity is.
*/
private _room: TRoom;
get room(): TRoom {
return this._room;
Expand Down

0 comments on commit 90bf610

Please sign in to comment.