Skip to content

Commit

Permalink
fix: data updates while not in scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmagic2020 committed May 27, 2024
1 parent 873907a commit a7c7b74
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning].

- Fix [[#16](https://github.com/mrmagic2020/openrct2-dynamicdashboard/issues/16)]: Month/Year park rating average bug.

- Fix data updating while not playing in a scenario.

## [1.0.0-pre.6] - 2024-05-25

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Data {
SFData.init()
RideData.init()
FinanceData.init()
interval.initCounter()
interval.resumeAll()
// interval.initCounter()
}

export function reset(): void {
Expand Down
11 changes: 11 additions & 0 deletions src/data/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { WritableStore, compute, store, twoway } from "openrct2-flexui"
import { Options } from "./options"
import IntervalManager from "../utils/interval"
import DataEntry from "./classes/dataEntry"
import HookManager from "../utils/hooks"
import Logger from "../utils/logger"

/**
* Represents a dataset with keys of type `U` and values of type `DataEntry<T>`.
Expand Down Expand Up @@ -866,6 +868,15 @@ const interval = IntervalManager.init({
update_frequency: baseData.global.update_frequency,
countdown_progress: baseData.local.options.countdown_progress.store
})
HookManager.hook("map.changed", () => {
if (context.mode !== "normal") {
Logger.debug("Map changed: Pausing all intervals.")
interval.pauseAll()
} else {
Logger.debug("Map changed: Resuming all intervals.")
interval.resumeAll()
}
})

export {
type DataEntry,
Expand Down
1 change: 1 addition & 0 deletions src/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function initMainMenu(): void {
}

function openMainMenu(): void {
if (context.mode !== "normal") return
menu()
}

Expand Down
14 changes: 7 additions & 7 deletions src/utils/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class IntervalManager {
}

/**
* Registers a function to be executed at a specified interval.
* Registers a function to be executed at a specified interval. Does not start the interval.
*
* @param func The function to be executed.
* @param interval The interval at which the function should be executed, in milliseconds. Defaults to the value of `baseData.global.update_frequency.get() * 1000`.
Expand All @@ -83,18 +83,18 @@ export class IntervalManager {
func: Function,
interval: number = this.updateFrequency.get() * 1000,
pause_on_manual: boolean = true
): number {
const ID = context.setInterval(func, interval)
this.intervalIDs.push(ID)
): void {
// const ID = context.setInterval(func, interval)
// this.intervalIDs.push(ID)
let info: FunctionInfo = {
ID: ID,
ID: -1,
func: func,
interval: interval,
paused: false,
paused: true,
pause_on_manual: pause_on_manual
}
this.registered.push(info)
return ID
// return ID
}

pauseManual(): void {
Expand Down

0 comments on commit a7c7b74

Please sign in to comment.