Skip to content

Commit

Permalink
render scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Jan 31, 2019
1 parent ec06bb4 commit c168b12
Show file tree
Hide file tree
Showing 26 changed files with 895 additions and 90 deletions.
2 changes: 1 addition & 1 deletion render/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ application {

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(group = "io.github.spair", name = "byond-dmm-util", version = "1.0.1")
implementation(group = "io.github.spair", name = "byond-dmm-util", version = "1.1")
implementation(group = "com.eclipsesource.minimal-json", name = "minimal-json", version = "0.9.5")
}

Expand Down
42 changes: 36 additions & 6 deletions render/src/main/kotlin/io/github/spair/tauwebmap/configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.github.spair.tauwebmap

import com.eclipsesource.json.Json
import com.eclipsesource.json.JsonObject
import java.io.File
import java.lang.Exception

private const val CONFIG_FILE = "config.json"

Expand All @@ -12,13 +14,15 @@ private const val LESS_ENTRY = "<"
private const val LESS_EQUAL_ENTRY = "<="

val RENDER_CONFIG = mutableMapOf<String, MutableList<String>>()
val SCRIPT_CONFIG = mutableMapOf<String, MutableList<File>>()

fun readConfigForRevisions(revisionList: List<String>) {
val configJson = Json.parse(readResource(CONFIG_FILE)).asObject()

configJson.entryForEach(MORE_EQUAL_ENTRY) { config ->
for (revision in revisionList) {
addToRenderConfig(revision, config)
addToScriptConfig(revision, config)
if (config.getRevision() == revision) {
break
}
Expand All @@ -30,12 +34,14 @@ fun readConfigForRevisions(revisionList: List<String>) {
break
}
addToRenderConfig(revision, config)
addToScriptConfig(revision, config)
}
}
configJson.entryForEach(EQUAL_ENTRY) { config ->
for (revision in revisionList) {
if (config.getRevision() == revision) {
addToRenderConfig(revision, config)
addToScriptConfig(revision, config)
}
}
}
Expand All @@ -45,11 +51,13 @@ fun readConfigForRevisions(revisionList: List<String>) {
break
}
addToRenderConfig(revision, config)
addToScriptConfig(revision, config)
}
}
configJson.entryForEach(LESS_EQUAL_ENTRY) { config ->
for (revision in revisionList.reversed()) {
addToRenderConfig(revision, config)
addToScriptConfig(revision, config)
if (config.getRevision() == revision) {
break
}
Expand All @@ -58,11 +66,31 @@ fun readConfigForRevisions(revisionList: List<String>) {
}

private fun addToRenderConfig(revision: String, config: JsonObject) {
if (config.renderExcluded(revision))
if (config.excluded(revision))
return
RENDER_CONFIG.getOrPut(revision) { mutableListOf() }.let { list ->
config.getRender().forEach { renderFileName ->
list.add(renderFileName.asString())
config.getRender()?.forEach { renderFileName ->
try {
list.add(renderFileName.asString())
} catch (e: Exception) {
println("exception with $renderFileName")
throw e
}
}
}
}

private fun addToScriptConfig(revision: String, config: JsonObject) {
if (config.excluded(revision))
return
SCRIPT_CONFIG.getOrPut(revision) { mutableListOf() }.let { list ->
config.getScript()?.forEach { scriptFileName ->
try {
list.add(resourceFile(scriptFileName.asString()))
} catch (e: Exception) {
println("exception with $scriptFileName")
throw e
}
}
}
}
Expand All @@ -71,11 +99,12 @@ private fun JsonObject.entryForEach(entryName: String, action: (JsonObject) -> (
get(entryName)?.asArray()?.forEach { action(it.asObject()) }
}

private fun JsonObject.getRender() = get("render").asArray()
private fun JsonObject.getRender() = get("render")?.asArray()
private fun JsonObject.getScript() = get("script")?.asArray()
private fun JsonObject.getRevision() = get("revision").asString()

private fun JsonObject.renderExcluded(revision: String): Boolean {
val exclude = get("render_exclude")?.asArray()
private fun JsonObject.excluded(revision: String): Boolean {
val exclude = get("exclude")?.asArray()
if (exclude != null) {
for (excl in exclude) {
if (revision == excl.asString()) {
Expand All @@ -88,3 +117,4 @@ private fun JsonObject.renderExcluded(revision: String): Boolean {

internal class Resource
fun readResource(path: String) = Resource::class.java.classLoader.getResource(path).readText()
fun resourceFile(path: String) = File(Resource::class.java.classLoader.getResource(path).file)
2 changes: 1 addition & 1 deletion render/src/main/kotlin/io/github/spair/tauwebmap/render.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private fun generateMapImage(typesToUse: Array<String>): BufferedImage {
val dmm = Dmm(dmmData, dme)

return if (typesToUse.isEmpty()) {
DmmDrawer.drawMap(dmm, FilterMode.IGNORE, *IGNORE_TYPES)
DmmDrawer.drawMap(dmm, SCRIPT_CONFIG[CURRENT_REVISION], FilterMode.IGNORE, *IGNORE_TYPES)
} else {
DmmDrawer.drawMap(dmm, FilterMode.INCLUDE, *typesToUse)
}
Expand Down
63 changes: 0 additions & 63 deletions render/src/main/resources/common_render.json

This file was deleted.

42 changes: 40 additions & 2 deletions render/src/main/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,51 @@
{
"revision": "887f80dff",
"render": [
"common_render.json"
"renders/common_render.json"
],
"script": [
"scripts/posters_amount.glob.groovy",
"scripts/color_window.glob.groovy",
"scripts/random_tools_icons.glob.groovy",
"scripts/adjust_window_color.var.groovy",
"scripts/airlock_overlay.img.groovy",
"scripts/color_window.var.groovy",
"scripts/handle_random_tool_color.var.groovy",
"scripts/handle_random_tool_supply.var.groovy",
"scripts/hide_content_in_closet.var.groovy",
"scripts/init_posters.var.groovy",
"scripts/smooth_carpet.var.groovy",
"scripts/smooth_wall.var.groovy",
"scripts/smooth_window.var.groovy"
]
},
{
"revision": "1f995d5f7",
"render": [
"specific_render/from_1f995d5f7.json"
"renders/equal_more_1f995d5f7.json"
]
},
{
"revision": "82304ea90",
"script": [
"scripts/equal_more_82304ea90/handle_random_flora.var.groovy"
]
},
{
"revision": "0bc341bb0",
"script": [
"scripts/equal_more_0bc341bb0/adjust_cleanable_blood_color.var.groovy",
"scripts/equal_more_0bc341bb0/smooth_table.var.groovy",
"scripts/equal_more_0bc341bb0/smooth_carpet.var.groovy"
]
}
],
"==": [
{
"revision": "887f80dff",
"script": [
"scripts/equal_887f80dff/smooth_table.var.groovy",
"scripts/equal_887f80dff/smooth_carpet.var.groovy"
]
}
]
Expand Down
61 changes: 61 additions & 0 deletions render/src/main/resources/renders/common_render.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"definitions": [
{
"type": "/turf/simulated/floor/plating",
"vars": {
"layer": 1.98
}
},
{
"type": "/obj/machinery/navbeacon",
"vars": {
"layer": 1.988
}
},
{
"type": "/obj/structure/disposalpipe",
"vars": {
"layer": 1.99
}
},
{
"type": "/obj/machinery/atmospherics/pipe/simple/hidden",
"vars": {
"layer": 1.999,
"alpha": 255
}
},
{
"type": "/obj/machinery/atmospherics/pipe/manifold/hidden",
"vars": {
"layer": 1.999,
"alpha": 255
}
},
{
"type": "/obj/machinery/atmospherics/pipe/manifold4w/hidden",
"vars": {
"layer": 1.999,
"alpha": 255
}
},
{
"type": "/obj/structure/cable",
"vars": {
"layer": 1.9999
}
},
{
"type": "/obj/machinery/atmospherics/components/unary/vent_scrubber/on",
"vars": {
"icon_state": "{text}on"
}
},
{
"type": "/obj/machinery/atmospherics/components/unary/vent_pump/on",
"vars": {
"icon_state": "{text}out"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,36 @@
"definitions": [
{
"type": "/turf/simulated/floor",
"parent": "/turf/simulated",
"subtypes": [],
"vars": {
"plane": -1
}
},{
},
{
"type": "/obj/machinery/ai_slipper",
"parent": "/obj/machinery",
"subtypes": [],
"vars": {
"plane": -1
}
},{
},
{
"type": "/obj/machinery/hologram/holopad",
"parent": "/obj/machinery/hologram",
"subtypes": [],
"vars": {
"plane": -1
}
},{
},
{
"type": "/obj/machinery/igniter",
"parent": "/obj/machinery",
"subtypes": [],
"vars": {
"plane": -1
}
},{
},
{
"type": "/obj/structure/lattice",
"parent": "/obj/structure",
"subtypes": [],
"vars": {
"plane": -1
}
},{
},
{
"type": "/obj/structure/alien/weeds",
"parent": "/obj/structure/alien",
"subtypes": [],
"vars": {
"plane": -1
}
Expand Down
16 changes: 16 additions & 0 deletions render/src/main/resources/scripts/adjust_window_color.var.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if (!src.isType('/obj/structure/window') && !src.isType('/obj/machinery/door/window'))
return

def currentArea = dmm.getTile(src.x, src.y).getArea()
def colored = false

areaColorsLists.each { areaColorList ->
if (colored) return
areaColorList.each { areaList, color ->
if (colored) return
if (currentArea.type in areaList) {
src.color = color
colored = true
}
}
}
19 changes: 19 additions & 0 deletions render/src/main/resources/scripts/airlock_overlay.img.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if (!src.isType('/obj/machinery/door/airlock'))
return sprite

def filling_overlay

if (src.inner_material) {
filling_overlay = getCachedDmi(src.overlays_file).getSprite("${src.inner_material}_closed")
} else {
filling_overlay = getCachedDmi(src.icon).getSprite('fill_closed')
}

if (filling_overlay) {
sprite.graphics.with {
drawImage(filling_overlay, 0, 0, null)
dispose()
}
}

return sprite
Loading

0 comments on commit c168b12

Please sign in to comment.