-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flagstaff_of_festivities: | ||
code: flagstaff | ||
add: [ flagstaff_of_festivities ] |
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
25 changes: 25 additions & 0 deletions
25
engine/src/main/kotlin/world/gregs/voidps/engine/data/config/DiangoCodeDefinition.kt
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,25 @@ | ||
package world.gregs.voidps.engine.data.config | ||
|
||
import world.gregs.voidps.engine.entity.item.Item | ||
|
||
/** | ||
* Codes to redeem holiday items from django | ||
* @param code the items code | ||
* @param add the items added with this code | ||
*/ | ||
data class DiangoCodeDefinition( | ||
val code: String = "", | ||
val add: List<Item> = emptyList(), | ||
) { | ||
|
||
companion object { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
operator fun invoke(map: Map<String, Any>) = DiangoCodeDefinition( | ||
code = map["code"] as? String ?: EMPTY.code, | ||
add = map["add"] as? List<Item> ?: EMPTY.add, | ||
) | ||
|
||
val EMPTY = DiangoCodeDefinition() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
engine/src/main/kotlin/world/gregs/voidps/engine/data/definition/DiangoCodeDefinitions.kt
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,56 @@ | ||
package world.gregs.voidps.engine.data.definition | ||
|
||
import com.github.michaelbull.logging.InlineLogger | ||
import world.gregs.voidps.engine.data.config.DiangoCodeDefinition | ||
import world.gregs.voidps.engine.entity.item.Item | ||
import world.gregs.voidps.engine.get | ||
import world.gregs.voidps.engine.getProperty | ||
import world.gregs.voidps.engine.timedLoad | ||
import world.gregs.yaml.Yaml | ||
import world.gregs.yaml.read.YamlReaderConfiguration | ||
|
||
class DiangoCodeDefinitions { | ||
|
||
private lateinit var definitions: Map<String, DiangoCodeDefinition> | ||
|
||
fun get(code: String) = definitions[code] ?: DiangoCodeDefinition.EMPTY | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun load(yaml: Yaml = get(), path: String = getProperty("diangoCodeDefinitionsPath"), itemDefinitions: ItemDefinitions? = null): DiangoCodeDefinitions { | ||
timedLoad("diango code definition") { | ||
val config = object : YamlReaderConfiguration(2, 2) { | ||
override fun add(list: MutableList<Any>, value: Any, parentMap: String?) { | ||
super.add(list, if (value is Map<*, *>) { | ||
val id = value["item"] as String | ||
if (itemDefinitions != null && !itemDefinitions.contains(id)) { | ||
logger.warn { "Invalid diango item id: $id" } | ||
} | ||
Item(id, value["amount"] as? Int ?: 1) | ||
} else { | ||
Item(value as String, amount = 1) | ||
}, parentMap) | ||
} | ||
override fun set(map: MutableMap<String, Any>, key: String, value: Any, indent: Int, parentMap: String?) { | ||
if (key == "<<") { | ||
map.putAll(value as Map<String, Any>) | ||
return | ||
} | ||
if (indent == 0) { | ||
super.set(map, key, DiangoCodeDefinition(value as Map<String, Any>), indent, parentMap) | ||
} else { | ||
super.set(map, key, value, indent, parentMap) | ||
} | ||
} | ||
} | ||
val definitions = yaml.load<Any>(path, config) as Map<String, DiangoCodeDefinition> | ||
this.definitions = definitions | ||
definitions.size | ||
} | ||
return this | ||
} | ||
|
||
companion object { | ||
private val logger = InlineLogger() | ||
} | ||
|
||
} |
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