Skip to content

Commit

Permalink
rolled back anticreep drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
WMF-Industries committed Dec 6, 2024
1 parent 4673dd1 commit d34cdde
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion assets/mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "floodcompat"
author: "io community"
main: "floodcompat.FloodCompat"
description: "Reduces desyncs & applies flood changes on join."
version: "1.2.2"
version: "1.2.3"
minGameVersion: 146
java: true
hidden: true
58 changes: 38 additions & 20 deletions src/floodcompat/FloodCompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class FloodCompat : Mod() {
/** Vanilla values of changed vars for restoration later */
private val defaults = mutableListOf<Any>()
/** All the tiles that currently have effects drawn on top */
private val allTiles = ObjectMap<Tile, List<Long>>()
private val allTiles = ObjectSet<Tile>()
private val allTasks = Seq<Timer.Task>()

/** Used to prevent flood from applying twice */
private var applied = false
Expand All @@ -50,42 +51,59 @@ class FloodCompat : Mod() {

if (pos <= 0 || rad <= 0 || time <= 0 || team <= 0) return@addPacketHandler
val tile = world.tile(pos) ?: return@addPacketHandler
val color = Team.get(team).color

val start = Time.millis()
val tiles = Seq<Tile>()
Geometry.circle(tile.x.toInt(), tile.y.toInt(), rad) { cx: Int, cy: Int ->
val t = world.tile(cx, cy)
if (t != null && !allTiles.containsKey(t)) {
allTiles.put(t, listOf(start, time.toLong(), team.toLong(), start + (time * 1000L))) // start time, overall length, team, end time
if (t != null && !allTiles.contains(t)) {
tiles.add(t)
}
}
allTiles.addAll(tiles)

val startTime = Time.millis()

allTasks.addAll(
Timer.schedule({
val sizeMultiplier = 1 - (Time.millis() - startTime) / 1000f / time
tiles.each { t: Tile ->
Timer.schedule({
Fx.lightBlock.at(
t.getX(),
t.getY(),
Mathf.random(0.01f, 1.5f * sizeMultiplier),
color
)
}, Mathf.random(1f))
}
}, 0f, 1f, time),

Timer.schedule({
allTiles.removeAll(tiles)
tiles.clear()
}, time.toFloat())
)
}

Timer.schedule({
val it = allTiles.iterator()
while(it.hasNext()){
val entry = it.next()
if(Time.millis() >= entry.value[3]){
val it = allTasks.iterator()
while (it.hasNext()) {
val task = it.next()
if (task == null || !task.isScheduled)
it.remove()
}else{
val sizeMultiplier = 1 - (Time.millis() - entry.value[0]) / 1000f / entry.value[1]
Timer.schedule({
Fx.lightBlock.at(
entry.key.getX(),
entry.key.getY(),
Mathf.random(0.01f, 1.5f * sizeMultiplier),
Team.get(entry.value[2].toInt()).color
)
}, Mathf.random(1f))
}
}
}, 0f, 1f)
}, 0f, 5f)
}

/** This is a function so that foo's can call it when downloading the mod */
private fun onWorldLoad() {
Log.debug("Send flood")
Call.serverPacketReliable("flood", "1.2")

allTiles.clear()
allTasks.each{ it.cancel() }
allTasks.clear()
}

/** Applies flood changes */
Expand Down

0 comments on commit d34cdde

Please sign in to comment.