Skip to content

Commit f92aa4f

Browse files
authored
Merge pull request #11 from integr-dev/develop
HOTFIX: Removed broken legacy syntax
2 parents 8356184 + e3e2f39 commit f92aa4f

5 files changed

Lines changed: 34 additions & 49 deletions

File tree

README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,6 @@ fun greet() {
164164
}
165165
```
166166

167-
168-
#### Script Syntax: Classic and Modern
169-
170-
Backbone supports two ways to write scripts:
171-
172-
- **Modern DSL (Recommended):** The new `lifecycle { ... }` syntax is concise, declarative, and covers most use cases for event handling, lifecycle hooks, and inter-script communication. All examples in this README use the new DSL.
173-
- **Classic API (Still Supported):** The old style, where you inherit from `ManagedLifecycle` and override `onLoad`/`onUnload`, is still fully supported. This approach is more flexible and powerful for advanced users, as it allows you to write imperative code and manage the lifecycle yourself. You can mix and match both styles as needed.
174-
175-
Example of the classic style:
176-
177-
```kotlin
178-
class MyScript : ManagedLifecycle() {
179-
override fun onLoad() {
180-
// Custom initialization logic
181-
}
182-
override fun onUnload() {
183-
// Cleanup logic
184-
}
185-
}
186-
```
187-
188-
For most scripts, the new DSL is recommended for its simplicity, but the classic approach remains available for complex or non-declarative scenarios.
189-
190167
### Storage and Configuration
191168

192169
Backbone provides a simple and powerful way to manage your plugin's data and configuration through `ResourcePool`s. This system allows you to easily handle databases and configuration files in a structured manner.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "net.integr"
10-
version = "1.6.0"
10+
version = "1.6.1"
1111

1212
repositories {
1313
mavenCentral()

src/main/kotlin/net/integr/backbone/systems/hotloader/GlobalScriptFunctions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414
package net.integr.backbone.systems.hotloader
1515

1616
import net.integr.backbone.Backbone
17+
import net.integr.backbone.systems.event.BackboneEventHandler
1718
import net.integr.backbone.systems.hotloader.isc.InterScriptDuckTypedEvent
1819
import net.integr.backbone.systems.hotloader.isc.IscMap
1920
import net.integr.backbone.systems.hotloader.isc.IscMapBuilder
21+
import net.integr.backbone.systems.hotloader.lifecycle.LifecycleSustainedState
2022
import net.integr.backbone.systems.hotloader.lifecycle.ManagedLifecycle
23+
import net.integr.backbone.systems.hotloader.lifecycle.sustained
24+
import net.integr.backbone.systems.text.component
25+
import java.awt.Color
26+
import kotlin.inc
2127
import kotlin.reflect.full.starProjectedType
28+
import kotlin.toString
2229

2330
/**
2431
* DSL entrypoint for defining a script lifecycle.

src/main/kotlin/net/integr/backbone/systems/hotloader/lifecycle/LifecycleSustainedState.kt

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ import kotlin.reflect.KProperty
2828
* @property value The current value of the state.
2929
* @since 1.0.0
3030
*/
31-
class LifecycleSustainedState<T>(private var value: T) : ReadWriteProperty<ManagedLifecycle, T> {
31+
class LifecycleSustainedState<T>(private var value: T) : ReadWriteProperty<Nothing?, T> {
3232
/**
33-
* The unique identifier for this sustained state.
34-
* This is typically the name of the property it's delegated to.
33+
* The unique identifier for this sustained state. This is assigned counting up from 0 for each `ManagedLifecycle` instance, based on the order of declaration.
3534
*
3635
* @since 1.0.0
3736
*/
38-
var id: String? = null
39-
private set
37+
var id: Int? = null
38+
internal set
4039

4140
/**
4241
* The default value of the state.
@@ -53,7 +52,7 @@ class LifecycleSustainedState<T>(private var value: T) : ReadWriteProperty<Manag
5352
* @return The current value of the state.
5453
* @since 1.0.0
5554
*/
56-
override fun getValue(thisRef: ManagedLifecycle, property: KProperty<*>): T {
55+
override fun getValue(thisRef: Nothing?, property: KProperty<*>): T {
5756
return value
5857
}
5958

@@ -65,28 +64,10 @@ class LifecycleSustainedState<T>(private var value: T) : ReadWriteProperty<Manag
6564
* @param value The new value to set.
6665
* @since 1.0.0
6766
*/
68-
override fun setValue(thisRef: ManagedLifecycle, property: KProperty<*>, value: T) {
67+
override fun setValue(thisRef: Nothing?, property: KProperty<*>, value: T) {
6968
this.value = value
7069
}
7170

72-
/**
73-
* Creates a [LifecycleSustainedState] instance and registers it with the [ManagedLifecycle] instance.
74-
*
75-
* This operator is called automatically when a `LifecycleSustainedState` is declared as a property
76-
* within a `ManagedLifecycle` class. It assigns an ID to the state based on the property name
77-
* and adds the state to the `ManagedLifecycle`'s tracking mechanism.
78-
*
79-
* @param thisRef The [ManagedLifecycle] instance that owns this property.
80-
* @param property The [KProperty] representing this state property.
81-
* @return This [ReadWriteProperty] instance.
82-
* @since 1.0.0
83-
*/
84-
operator fun provideDelegate(thisRef: ManagedLifecycle, property: KProperty<*>): ReadWriteProperty<ManagedLifecycle, T> {
85-
id = property.name
86-
thisRef.trackState(this)
87-
return this
88-
}
89-
9071
/**
9172
* Sets the state of this property to the given value without type checking.
9273
* This method is intended for internal use by the hotloader to restore state after a reload.

src/main/kotlin/net/integr/backbone/systems/hotloader/lifecycle/ManagedLifecycle.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.jetbrains.annotations.ApiStatus
2929
*/
3030
abstract class ManagedLifecycle : Listener {
3131
private var sustainedStates: Set<LifecycleSustainedState<*>> = mutableSetOf()
32+
private var sustainedNextId = 0
33+
3234

3335
/**
3436
* Called when the component is loaded.
@@ -69,6 +71,24 @@ abstract class ManagedLifecycle : Listener {
6971
onUnload()
7072
}
7173

74+
/**
75+
* Creates a new [LifecycleSustainedState] with the given initial value and tracks it for state persistence.
76+
*
77+
* This method should be used within `ManagedLifecycle` classes to create sustained state properties.
78+
* The returned `LifecycleSustainedState` can be delegated to a property to enable state persistence across reloads.
79+
*
80+
* @param T The type of the value being sustained.
81+
* @param value The initial value of the sustained state.
82+
* @return A new `LifecycleSustainedState` instance initialized with the given value.
83+
* @since 1.6.0
84+
*/
85+
fun <T> sustained(value: T): LifecycleSustainedState<T> {
86+
val s = LifecycleSustainedState(value)
87+
s.id = sustainedNextId++
88+
trackState(s)
89+
return s
90+
}
91+
7292
/**
7393
* Add a [LifecycleSustainedState] to be tracked by this [ManagedLifecycle] instance.
7494
*

0 commit comments

Comments
 (0)