Skip to content

Commit

Permalink
Keep RaGaugeModel as a subclass of RaIntModel
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed May 4, 2024
1 parent 149d180 commit 91928f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ abstract class RHMIModel protected constructor(val id: Int) {
open var value: Int = 0
}

open class RaGaugeModel(id: Int, raIntModel: RaIntModel? = null): RHMIModel(id) {
open class RaGaugeModel(id: Int): RaIntModel(id) {
var modelType: String = ""
var min: Int = 0
var max: Int = 100
var increment: Int = 1

// has a value from RaIntModel
// so subclasses can pass in their own raIntModel to enable live functionality
private val raIntModel = raIntModel ?: RaIntModel(id)
var value: Int
get() = raIntModel.value
set(value) { raIntModel.value = value }
// inherits value from RaIntModel
}

open class FormatDataModel(id: Int, val submodels: List<RHMIModel>): RHMIModel(id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class RHMIModelLive {
get() = app.getModel(id) as? Int ?: 0
set(value) = app.setModel(id, value)
}
open class RaGaugeModel(app: RHMIApplication, id: Int): RHMIModel.RaGaugeModel(id, RaIntModel(app, id))
open class RaGaugeModel(val app: RHMIApplication, id: Int): RHMIModel.RaGaugeModel(id) {
override var value: Int
get() = app.getModel(id) as? Int ?: 0
set(value) = app.setModel(id, value)

}

open class FormatDataModel(app: RHMIApplication, id: Int, submodels: List<RHMIModel>): RHMIModel.FormatDataModel(id, submodels) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class TestXMLParsing {
@Test fun raGaugeModel() {
val model = RHMIModel.loadFromXML(app, models.getChildNamed("raGaugeModel") as Node)
assertNotNull(model)
assertTrue(model is RHMIModel.RaIntModel) // subclass with the same value behavior
assertTrue(model is RHMIModel.RaGaugeModel)
assertEquals(null, app.modelData[model?.id])
assertEquals(8, model?.id)
Expand Down

0 comments on commit 91928f7

Please sign in to comment.