mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 21:35:14 -04:00
Unified many implementations of common interfaces into abstract classes (#5312)
* Unified many implementations of common interfaces into abstract classes * RulesetObject interface
This commit is contained in:
parent
ed47f16c6e
commit
8d631254aa
@ -9,18 +9,12 @@ import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class Belief : INamed, ICivilopediaText, IHasUniques {
|
||||
override var name: String = ""
|
||||
class Belief : RulesetObject() {
|
||||
var type: BeliefType = BeliefType.None
|
||||
override var uniques = ArrayList<String>()
|
||||
|
||||
override fun getUniqueTarget() =
|
||||
if (type == BeliefType.Founder || type == BeliefType.Enhancer) UniqueTarget.FounderBelief
|
||||
else UniqueTarget.FollowerBelief
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
override fun makeLink() = "Belief/$name"
|
||||
override fun getCivilopediaTextHeader() = FormattedLine(name, icon = makeLink(), header = 2, color = if (type == BeliefType.None) "#e34a2b" else "")
|
||||
|
@ -10,13 +10,11 @@ import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.fillPlaceholders
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import kotlin.collections.ArrayList
|
||||
@ -24,7 +22,7 @@ import kotlin.collections.HashMap
|
||||
import kotlin.math.pow
|
||||
|
||||
|
||||
class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
|
||||
var requiredTech: String? = null
|
||||
|
||||
@ -66,18 +64,9 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
var replaces: String? = null
|
||||
var uniqueTo: String? = null
|
||||
var quote: String = ""
|
||||
override var uniques = ArrayList<String>()
|
||||
override fun getUniqueTarget() = UniqueTarget.Building
|
||||
override val uniqueObjects: List<Unique> by lazy {
|
||||
uniques.map {
|
||||
Unique(it, if (isAnyWonder()) UniqueTarget.Wonder else UniqueTarget.Building, name)
|
||||
}
|
||||
}
|
||||
override fun getUniqueTarget() = if (isAnyWonder()) UniqueTarget.Wonder else UniqueTarget.Building
|
||||
private var replacementTextForUniques = ""
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
|
||||
/** Used for AlertType.WonderBuilt, and as sub-text in Nation and Tech descriptions */
|
||||
fun getShortDescription(ruleset: Ruleset): String { // should fit in one line
|
||||
val infoList = mutableListOf<String>()
|
||||
|
@ -22,3 +22,5 @@ interface IHasUniques {
|
||||
fun hasUnique(uniqueTemplate: String) = uniqueObjects.any { it.placeholderText == uniqueTemplate }
|
||||
fun hasUnique(uniqueType: UniqueType) = uniqueObjects.any { it.isOfType(uniqueType) }
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,9 +22,7 @@ enum class VictoryType {
|
||||
Scientific,
|
||||
}
|
||||
|
||||
class Nation : INamed, ICivilopediaText, IHasUniques {
|
||||
override lateinit var name: String
|
||||
|
||||
class Nation : RulesetObject() {
|
||||
var leaderName = ""
|
||||
fun getLeaderDisplayName() = if (isCityState()) name
|
||||
else "[$leaderName] of [$name]"
|
||||
@ -43,10 +41,7 @@ class Nation : INamed, ICivilopediaText, IHasUniques {
|
||||
|
||||
lateinit var outerColor: List<Int>
|
||||
var uniqueName = ""
|
||||
override var uniques = ArrayList<String>()
|
||||
override fun getUniqueTarget() = UniqueTarget.Nation
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
var uniqueText = ""
|
||||
var innerColor: List<Int>? = null
|
||||
var startBias = ArrayList<String>()
|
||||
@ -57,8 +52,6 @@ class Nation : INamed, ICivilopediaText, IHasUniques {
|
||||
/* Properties present in json but not yet implemented:
|
||||
var adjective = ArrayList<String>()
|
||||
*/
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
@Transient
|
||||
private lateinit var outerColorObject: Color
|
||||
|
@ -1,26 +1,17 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
|
||||
open class Policy : INamed, IHasUniques, ICivilopediaText {
|
||||
open class Policy : RulesetObject() {
|
||||
lateinit var branch: PolicyBranch // not in json - added in gameBasics
|
||||
|
||||
override lateinit var name: String
|
||||
override var uniques: ArrayList<String> = ArrayList()
|
||||
override fun getUniqueTarget() = UniqueTarget.Policy
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
var row: Int = 0
|
||||
var column: Int = 0
|
||||
var requires: ArrayList<String>? = null
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
/** Indicates whether a [Policy] is a [PolicyBranch] starting policy, a normal one, or the branch completion */
|
||||
enum class PolicyBranchType {BranchStart, Member, BranchComplete}
|
||||
/** Indicates whether this [Policy] is a [PolicyBranch] starting policy, a normal one, or the branch completion */
|
||||
@ -37,8 +28,6 @@ open class Policy : INamed, IHasUniques, ICivilopediaText {
|
||||
fun isBranchCompleteByName(name: String) = name.endsWith(branchCompleteSuffix)
|
||||
}
|
||||
|
||||
override fun toString() = name
|
||||
|
||||
/** Used in PolicyPickerScreen to display Policy properties */
|
||||
fun getDescription(): String {
|
||||
val policyText = ArrayList<String>()
|
||||
|
@ -1,24 +1,15 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
|
||||
class RuinReward : INamed, ICivilopediaText, IHasUniques {
|
||||
override lateinit var name: String // Displayed in Civilopedia!
|
||||
class RuinReward : RulesetObject() {
|
||||
val notification: String = ""
|
||||
override var uniques = ArrayList<String>()
|
||||
|
||||
override fun getUniqueTarget() = UniqueTarget.Ruins
|
||||
@delegate:Transient // Defense in depth against mad modders
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it, UniqueTarget.Ruins, name) } }
|
||||
|
||||
val excludedDifficulties: List<String> = listOf()
|
||||
val weight: Int = 1
|
||||
val color: String = "" // For Civilopedia
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
override fun makeLink() = "" //No own category on Civilopedia screen
|
||||
}
|
||||
|
30
core/src/com/unciv/models/ruleset/RulesetObject.kt
Normal file
30
core/src/com/unciv/models/ruleset/RulesetObject.kt
Normal file
@ -0,0 +1,30 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
|
||||
interface IRulesetObject:INamed, IHasUniques, ICivilopediaText
|
||||
|
||||
abstract class RulesetObject: IRulesetObject {
|
||||
override lateinit var name: String
|
||||
override var uniques = ArrayList<String>() // Can not be a hashset as that would remove doubles
|
||||
@delegate:Transient
|
||||
override val uniqueObjects: List<Unique> by lazy {
|
||||
uniques.map { Unique(it, getUniqueTarget(), name) }
|
||||
}
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
override fun toString() = name
|
||||
}
|
||||
|
||||
// Same, but inherits from NamedStats - I couldn't find a way to unify the declarations but this is fine
|
||||
abstract class RulesetStatsObject: NamedStats(), IRulesetObject {
|
||||
override var uniques = ArrayList<String>() // Can not be a hashset as that would remove doubles
|
||||
@delegate:Transient
|
||||
override val uniqueObjects: List<Unique> by lazy {
|
||||
uniques.map { Unique(it, getUniqueTarget(), name) }
|
||||
}
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
}
|
@ -4,39 +4,25 @@ import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import java.util.*
|
||||
|
||||
class Technology: INamed, ICivilopediaText, IHasUniques {
|
||||
|
||||
override lateinit var name: String
|
||||
class Technology: RulesetObject() {
|
||||
|
||||
var cost: Int = 0
|
||||
var prerequisites = HashSet<String>()
|
||||
override var uniques = ArrayList<String>()
|
||||
override fun getUniqueTarget() = UniqueTarget.Tech
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
var column: TechColumn? = null // The column that this tech is in the tech tree
|
||||
var row: Int = 0
|
||||
var quote = ""
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
|
||||
// Debug helper
|
||||
override fun toString() = name
|
||||
|
||||
fun era(): String = column!!.era
|
||||
|
||||
fun isContinuallyResearchable() = uniques.contains("Can be continually researched")
|
||||
|
@ -3,16 +3,13 @@ package com.unciv.models.ruleset.tile
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.unciv.Constants
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.RulesetStatsObject
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.ui.utils.colorFromRGB
|
||||
|
||||
class Terrain : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
class Terrain : RulesetStatsObject() {
|
||||
|
||||
lateinit var type: TerrainType
|
||||
|
||||
@ -27,11 +24,7 @@ class Terrain : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
/** Used by Natural Wonders: it is the baseTerrain on top of which the Natural Wonder is placed */
|
||||
val turnsInto: String? = null
|
||||
|
||||
/** Uniques (Properties such as Temp/humidity, Fresh water, elevation, rough, defense, Natural Wonder specials) */
|
||||
override var uniques = ArrayList<String>()
|
||||
override fun getUniqueTarget() = UniqueTarget.Terrain
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
/** Natural Wonder weight: probability to be picked */
|
||||
var weight = 10
|
||||
@ -46,8 +39,6 @@ class Terrain : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
@Transient
|
||||
var damagePerTurn = 0
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
fun isRough(): Boolean = uniques.contains("Rough terrain")
|
||||
|
||||
/** Tests base terrains, features and natural wonders whether they should be treated as Land/Water.
|
||||
|
@ -3,34 +3,27 @@ package com.unciv.models.ruleset.tile
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetStatsObject
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class TileImprovement : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
class TileImprovement : RulesetStatsObject() {
|
||||
|
||||
var terrainsCanBeBuiltOn: Collection<String> = ArrayList()
|
||||
var techRequired: String? = null
|
||||
var uniqueTo:String? = null
|
||||
override var uniques = ArrayList<String>()
|
||||
override fun getUniqueTarget() = UniqueTarget.Improvement
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
val shortcutKey: Char? = null
|
||||
val turnsToBuild: Int = 0 // This is the base cost.
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
|
||||
fun getTurnsToBuild(civInfo: CivilizationInfo): Int {
|
||||
var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||
|
@ -1,16 +1,13 @@
|
||||
package com.unciv.models.ruleset.tile
|
||||
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.RulesetStatsObject
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
|
||||
class TileResource : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
class TileResource : RulesetStatsObject() {
|
||||
|
||||
var resourceType: ResourceType = ResourceType.Bonus
|
||||
var terrainsCanBeFoundOn: List<String> = listOf()
|
||||
@ -19,12 +16,7 @@ class TileResource : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
var revealedBy: String? = null
|
||||
@Deprecated("As of 3.16.16 - replaced by uniques")
|
||||
var unique: String? = null
|
||||
override var uniques: ArrayList<String> = arrayListOf()
|
||||
override fun getUniqueTarget() = UniqueTarget.Resource
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
|
||||
override fun makeLink() = "Resource/$name"
|
||||
|
@ -5,6 +5,7 @@ import com.unciv.logic.city.*
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
@ -24,9 +25,8 @@ import kotlin.math.pow
|
||||
|
||||
/** This is the basic info of the units, as specified in Units.json,
|
||||
in contrast to MapUnit, which is a specific unit of a certain type that appears on the map */
|
||||
class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||
|
||||
override lateinit var name: String
|
||||
var cost: Int = 0
|
||||
override var hurryCostModifier: Int = 0
|
||||
var movement: Int = 0
|
||||
@ -40,10 +40,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
var requiredTech: String? = null
|
||||
private var requiredResource: String? = null
|
||||
|
||||
override var uniques = ArrayList<String>() // Can not be a hashset as that would remove doubles
|
||||
override fun getUniqueTarget() = UniqueTarget.Unit
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
private var replacementTextForUniques = ""
|
||||
var promotions = HashSet<String>()
|
||||
@ -64,7 +61,6 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
|
||||
lateinit var ruleset: Ruleset
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
fun getShortDescription(): String {
|
||||
val infoList = mutableListOf<String>()
|
||||
@ -494,8 +490,6 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
return civInfo.getEquivalentUnit(upgradesTo!!)
|
||||
}
|
||||
|
||||
override fun toString(): String = name
|
||||
|
||||
fun getReplacedUnit(ruleset: Ruleset): BaseUnit {
|
||||
return if (replaces == null) this
|
||||
else ruleset.units[replaces!!]!!
|
||||
|
@ -1,34 +1,26 @@
|
||||
package com.unciv.models.ruleset.unit
|
||||
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
|
||||
|
||||
class Promotion : INamed, ICivilopediaText, IHasUniques {
|
||||
override lateinit var name: String
|
||||
class Promotion : RulesetObject() {
|
||||
var prerequisites = listOf<String>()
|
||||
// effect deprecated since 3.16.12, use uniques instead
|
||||
|
||||
@Deprecated("As of 3.16.12", ReplaceWith("uniques"))
|
||||
var effect = ""
|
||||
//
|
||||
|
||||
var unitTypes = listOf<String>() // The json parser wouldn't agree to deserialize this as a list of UnitTypes. =(
|
||||
|
||||
override var uniques = ArrayList<String>()
|
||||
fun uniquesWithEffect() = sequence {
|
||||
if (effect.isNotEmpty()) yield(effect)
|
||||
yieldAll(uniques)
|
||||
}
|
||||
|
||||
override fun getUniqueTarget() = UniqueTarget.Promotion
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it,
|
||||
getUniqueTarget(), name) } }
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
|
||||
/** Used to describe a Promotion on the PromotionPickerScreen */
|
||||
|
Loading…
x
Reference in New Issue
Block a user