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

Support keeping some scene properties while hot reloading #953

Merged
merged 3 commits into from
Aug 26, 2022

Conversation

soywiz-invideo
Copy link
Contributor

@soywiz-invideo soywiz-invideo commented Aug 26, 2022

class MyScene : Scene() {
    @KeepOnReload var textSize = 100.0 // If this value is modified at runtime, the new value will be persisted if we hotreload the scene. Effectively making modifying this value when compiling a no-op until the app is closed and reopened. You can also remove the annotation to modify again the value by code.

    @KeepOnReload var positionX by Delegates.observable(50.0) { _, _, _ -> reload() } // It even works with delegates! So we can register it later.

   // Also when a scene is reloaded the SContainer view will be highlighted, so the debug components will appear
   fun SContainer.sceneMain() {
      // Now we can add a debug component and use the views debugger to manually adjust properties that will be persisted later
      extraBuildDebugComponent = { views, view, container ->
        container.uiCollapsibleSection("Debug") {
            uiEditableValue(::textSize)
            uiEditableValue(::positionX, min = 0.0, max = 100.0, clamp = true)
        }
     }
   }
}

@soywiz soywiz merged commit 4fefa10 into main Aug 26, 2022
@soywiz soywiz deleted the feature/keep.some.properties.while.reloading branch October 4, 2023 19:16
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

Successfully merging this pull request may close these issues.

2 participants