-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from alyssaruth/x01-any-finish
X01 - Finish on non-double
- Loading branch information
Showing
56 changed files
with
808 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,55 @@ | ||
package dartzee.bean | ||
|
||
import dartzee.game.FinishType | ||
import dartzee.game.X01Config | ||
import java.awt.BorderLayout | ||
import java.awt.event.ActionListener | ||
import javax.swing.Box | ||
import javax.swing.JCheckBox | ||
import javax.swing.JPanel | ||
|
||
class GameParamFilterPanelX01 : GameParamFilterPanel() { | ||
private val panel = JPanel() | ||
val spinner = SpinnerX01() | ||
private val spinner = SpinnerX01() | ||
private val cbFinishOnDouble = JCheckBox("Finish on double") | ||
private val separator = Box.createHorizontalStrut(20) | ||
|
||
init { | ||
add(panel, BorderLayout.CENTER) | ||
panel.add(cbFinishOnDouble) | ||
panel.add(separator) | ||
panel.add(spinner) | ||
cbFinishOnDouble.isSelected = true | ||
} | ||
|
||
override fun getGameParams() = "${spinner.value}" | ||
override fun getGameParams() = constructGameParams().toJson() | ||
|
||
override fun setGameParams(gameParams: String) { | ||
spinner.value = gameParams.toInt() | ||
val config = X01Config.fromJson(gameParams) | ||
spinner.value = config.target | ||
cbFinishOnDouble.isSelected = config.finishType == FinishType.Doubles | ||
} | ||
|
||
override fun getFilterDesc() = "games of ${getGameParams()}" | ||
private fun constructGameParams() = | ||
X01Config( | ||
spinner.value as Int, | ||
if (cbFinishOnDouble.isSelected) FinishType.Doubles else FinishType.Any | ||
) | ||
|
||
override fun getFilterDesc() = "games of ${constructGameParams().description()}" | ||
|
||
override fun enableChildren(enabled: Boolean) { | ||
spinner.isEnabled = enabled | ||
cbFinishOnDouble.isEnabled = enabled | ||
} | ||
|
||
override fun addActionListener(listener: ActionListener) { | ||
spinner.addActionListener(listener) | ||
cbFinishOnDouble.addActionListener(listener) | ||
} | ||
|
||
override fun removeActionListener(listener: ActionListener) { | ||
spinner.removeActionListener() | ||
cbFinishOnDouble.addActionListener(listener) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dartzee.game | ||
|
||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import dartzee.core.util.jsonMapper | ||
|
||
enum class FinishType { | ||
Any, | ||
Doubles | ||
} | ||
|
||
data class X01Config(val target: Int, val finishType: FinishType) { | ||
fun toJson(): String = jsonMapper().writeValueAsString(this) | ||
|
||
fun description() = "$target${finishTypeDesc()}" | ||
|
||
private fun finishTypeDesc() = if (finishType == FinishType.Any) " (relaxed finish)" else "" | ||
|
||
companion object { | ||
fun fromJson(json: String) = jsonMapper().readValue<X01Config>(json) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.