Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing Save & Load of Timers #1325

Open
AlmasB opened this issue Dec 28, 2023 Discussed in #1320 · 0 comments
Open

Allowing Save & Load of Timers #1325

AlmasB opened this issue Dec 28, 2023 Discussed in #1320 · 0 comments

Comments

@AlmasB
Copy link
Owner

AlmasB commented Dec 28, 2023

Discussed in #1320

Originally posted by DeathPhoenix22 November 7, 2023
Hi,

I was partially looking at how I'll be able to save & load games. I've found how with 1 limitation that I could easily overcum, but feel like any project will require it if they use LocalTimer.

Long story short, you can't save a timer. There is no access to it's current "Now" value, which in fact isn't truly interesting. But, to save and load, you need to store the remaining time and instantiate a Timer with that time already added up.

Let's check with a use case:

  1. The Player starts the construction of a building which takes 120 seconds to build.
  2. The Application creates a LocalTimer for 120 seconds
  3. The Player Save game after 110 seconds since the construction was started
  4. The Application can't access the current 110 seconds elapsed time and therefor cannot save the "time" value of a LocalTimer (private)
  5. The Player load the save
  6. The Application load the building under construction state
  7. The Application creates a new localTimer and cannot preset the elapsed time (could not access it at save time & can't assign it either)

The solution:

  1. Add a Getter the "time" value of a LocalTimer (Optional)
  2. Add a Getter the "elapsedTime" value of a LocalTimer (Mandatory) -> return now - time
  3. Add a Constructor parameter allowing instantiation of LocalTimer at a predefined "elapsedTime" (Mandatory) -> will do time = now - elapsedTime
  4. Add a timeProperty so LocalTimer can also be displayed easily in the UI (That would be really useful ! )

@AlmasB Do you want me to integrate this to the Engine or you prefer that I implement it only in my own game?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant