Allow to specify field name prefix in SynchronizedRedstoneControl

This commit is contained in:
DBotThePony 2023-01-29 22:25:28 +07:00
parent b817e9f290
commit 44c0422387
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -65,9 +65,11 @@ class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) ->
class SynchronizedRedstoneControl(
synchronizer: FieldSynchronizer,
fieldNamePrefix: String?,
private val valueChanges: (new: Boolean, old: Boolean) -> Unit,
fieldNamePrefix: String? = null
) : AbstractRedstoneControl() {
constructor(synchronizer: FieldSynchronizer, valueChanges: (new: Boolean, old: Boolean) -> Unit) : this(synchronizer, null, valueChanges)
override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { value, access, setByRemote ->
if (setByRemote) {
access.write(value)
@ -80,7 +82,7 @@ class SynchronizedRedstoneControl(
valueChanges.invoke(state, old)
}
}
})
}, name = if (fieldNamePrefix != null) "${fieldNamePrefix}_redstoneSetting" else null)
override var redstoneSignal: Int by synchronizer.int(0, setter = { value, access, setByRemote ->
if (setByRemote) {
@ -94,5 +96,5 @@ class SynchronizedRedstoneControl(
valueChanges.invoke(state, old)
}
}
})
}, name = if (fieldNamePrefix != null) "${fieldNamePrefix}_redstoneSignal" else null)
}