Skip to content

Commit

Permalink
Remove buildSrc since it breaks compiling now for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Nov 6, 2024
1 parent 85597e0 commit dace346
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 149 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ packr-out/
config/
*.gif
/tests/out
/buildSrc/build

/core/assets/basepartnames
version.properties
Expand Down
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ buildscript{
}

plugins{
id "org.jetbrains.kotlin.jvm" version "2.0.10"
id "org.jetbrains.kotlin.jvm" version "2.0.10" apply false
id "org.jetbrains.kotlin.kapt" version "2.0.10" apply false
}

Expand Down Expand Up @@ -359,7 +359,7 @@ project(":core"){
if(localArc && debugged()) api arcModule("extensions:recorder")
if(localArc) api arcModule(":extensions:packer")

implementation "org.jetbrains.kotlin:kotlin-reflect:2.0.10"
// implementation "org.jetbrains.kotlin:kotlin-reflect:2.0.10"

compileOnly files("../bouncycastle/bcprov-jdk15on.jar")
compileOnly files("../bouncycastle/bcpkix-jdk15on.jar")
Expand Down Expand Up @@ -445,7 +445,12 @@ project(":tests"){
}

project(":tools"){
apply plugin: "java"
apply plugin: "kotlin"

kotlin.compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.add("-Xjdk-release=1.8")
}

dependencies{
implementation project(":core")
Expand Down
26 changes: 0 additions & 26 deletions buildSrc/build.gradle.kts

This file was deleted.

88 changes: 0 additions & 88 deletions buildSrc/src/main/kotlin/Paletter.kt

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/mindustry/client/utils/AutoTransfer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class AutoTransfer {

/** Transfers outputs from blocks into core/containers */
private fun drain(): Boolean { // FINISHME: Until this class is refactored to have a more generic input output system I'm just gonna copy a lot of code into this function
core = player.closestCore() ?: return@drain false
core = player.closestCore() ?: return false
val nearCore = player.within(core, itemTransferRange)
if (!nearCore) core = null

Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ org.gradle.jvmargs=-Xms256m -Xmx1024m --illegal-access=permit \

# Compilation avoidance (see https://kotlinlang.org/docs/kapt.html#compile-avoidance-for-kapt-since-1-3-20)
kapt.include.compile.classpath=false
# I don't need to use the kotlin stdlib, so remove it to prevent extra bloat & method count issues
kotlin.stdlib.default.dependency=false
#kapt.workers.isolation=process
#needed for android compilation
android.useAndroidX=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pluginManagement { // FINISHME: Move all the plugin versions and such here.
gradlePluginPortal()
google()
}
plugins {
id "org.jetbrains.kotlin.jvm" version "2.0.10"
}
}

if(JavaVersion.current().ordinal() < JavaVersion.VERSION_16.ordinal()){
Expand Down
31 changes: 6 additions & 25 deletions tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ buildscript {
}
}

plugins {
id "org.jetbrains.kotlin.jvm" version "2.0.10"
}

sourceSets.main.java.srcDirs = ["src/"]
sourceSets.main.kotlin.srcDirs = ["src/"]

import arc.files.Fi
import arc.files.ZipFi
Expand Down Expand Up @@ -139,27 +136,11 @@ task bleedImages(){
}
}

task mapImages(){
doLast{
// def executor = Executors.newFixedThreadPool(OS.cores)
def dir = new Fi(project.getProperty("startdir"))
def paletter = new Paletter()
dir.walk { fi ->
var name = fi.name()
if (paletter.blacklist.contains(name) || name.startsWith("zzzzz-") || paletter.regexlist.any(regex -> regex.matches(name))) return
if (!name.endsWith(".png")) {
throw new IOException(name)
}
// executor.execute {
var pix = new Pixmap(fi)
paletter.mapColors(pix, name)
fi.sibling("zzzzz-" + name).writePng(pix)
pix.dispose()
// }
}
println("Missing: $paletter.missingCount | Similar: $paletter.similar.size")
// Threads.await(executor)
}
task mapImages(dependsOn: classes, type: JavaExec){
mainClass = "mindustry.tools.Paletter"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../"
}

task pack(dependsOn: [classes, configurations.runtimeClasspath]){
Expand Down
115 changes: 115 additions & 0 deletions tools/src/mindustry/tools/Paletter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@file:JvmName("Paletter")
package mindustry.tools

import arc.files.*
import arc.graphics.*
import arc.struct.*
import kotlin.math.*

fun main(vararg args: String) {
val dir = Fi(if (args.isEmpty()) "core/assets-raw/sprites" else args[0])
// FINISHME: This isn't ported fully from groovy (see the commented block below)
}

// doLast{
//// def executor = Executors.newFixedThreadPool(OS.cores)
// def dir = new Fi(project.getProperty("startdir"))
// def paletter = new Paletter()
// dir.walk { fi ->
// var name = fi.name()
// if (paletter.blacklist.contains(name) || name.startsWith("zzzzz-") || paletter.regexlist.any(regex -> regex.matches(name))) return
// if (!name.endsWith(".png")) {
// throw new IOException(name)
// }
//// executor.execute {
// var pix = new Pixmap(fi)
// paletter.mapColors(pix, name)
// fi.sibling("zzzzz-" + name).writePng(pix)
// pix.dispose()
//// }
// }
// println("Missing: $paletter.missingCount | Similar: $paletter.similar.size")
//// Threads.await(executor)
// }

private val blacklist = setOf(
".DS_Store", "pack.json", "error.png", "logo.png", "alpha-bg.png", "alphaaaa.png", "clear.png",
"particle.png", "hcircle.png", "clear-effect.png", "flarogus.png"
)
private val regexlist = arrayOf(
".+-shadow[0-9]?\\.png", ".+-glow\\.png", ".+-vents\\.png", ".+-blur\\.png", ".+-heat(?:_full|-top)?\\.png", "fire[0-9]+\\.png",
"circle-(?:mid|end|small)\\.png", ".+-cell\\.png", "edge(?:-stencil)?\\.png",
).map { it.toRegex() }

private val mapping = map(
0x62AE7FFF, 0x50A9ADFF,
0x84F491FF, 0x6DF5D7FF,
0xB0BAC0FF, 0x757C80FF,
0x989AA4FF, 0x5C5E64FF,
0x6E7080FF, 0x373840FF,
0xD3816BFF, 0xD48555FF,
0xEA8778FF, 0xEB7360FF,
0xFEB380FF, 0xFFA366FF,
0x767a84FF, 0x4f5f85FF,
0x8e9097FF, 0x737c96FF,
0x3a3a50FF, 0x29294fFF,
0x84f491FF, 0x58f56aFF,
0xFF62AE7F, 0xFF3EAD68,
)

private val notFound = IntSet() // Colors not in mapping that we've already tried and are not similar and are therefore missing from the map
private var missingCount = 0
private val similar = map() // Basically just additional keys for [mapping] entries for colors that are similar enough to be considered one of the mapped colors

/** Horribly cursed way around having to spam [Long.toInt] calls everywhere */
private fun map(vararg values: Long) = IntIntMap.of(*values.map { it.toInt() }.toIntArray())

/** Not thread safe. */
private fun Pixmap.mapColors(fileName: String) {
val colorCache = Color()
val pc = Color() // pixelColor
for (i in 0 until height * width * 4 step 4) {
val pixel = pixels.getInt(i)
if (pixel == 0) continue

val mapped = mapping[pixel, -1]
if (mapped != -1) {
pixels.putInt(i, mapped)
continue
}

val similarMapped = similar[pixel, -1] // This is *very* hacky
if (similarMapped != -1) {
pixels.putInt(i, similarMapped)
continue
}

if (notFound.add(pixel) && !mapping.containsValue(pixel)) { // This is very slow
pc.set(pixel)
if (pc.a == 0F) continue
pc.premultiplyAlpha()
val values = mapping.values()
var diff = Float.MAX_VALUE
var min: Int = -1
while (values.hasNext()) { // minBy just doesn't work here and I can't be bothered to find out why.
val e = values.next()
val c = colorCache.set(e).premultiplyAlpha()
val v = sqrt((c.r - pc.r) * (c.r - pc.r) +
(c.g - pc.g) * (c.g - pc.g) +
(c.b - pc.b) * (c.b - pc.b))
if (diff > v) {
min = e
diff = v
}
}

if (diff < 0.01) {
similar.put(pixel, min)
pixels.putInt(i, min)
} else {
missingCount++
println("Missing 0x${Integer.toHexString(pixel).uppercase()} | Closest: 0x${Integer.toHexString(min).uppercase()} | File: $fileName | Diff: $diff")
}
}
}
}
4 changes: 2 additions & 2 deletions tools/src/mindustry/tools/ScriptMainGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ScriptMainGenerator{

public static void main(String[] args) throws Exception{
String base = "mindustry";
Seq<String> blacklist = Seq.with("tools");
Seq<String> blacklist = Seq.with("tools", "arc.flabel.effects");
Seq<String> nameBlacklist = Seq.with();
Seq<Class<?>> whitelist = Seq.with(Draw.class, Fill.class, Lines.class, Core.class, TextureAtlas.class, TextureRegion.class, Time.class, System.class, PrintStream.class,
AtlasRegion.class, String.class, Mathf.class, Angles.class, Color.class, Runnable.class, Object.class, Icon.class, Tex.class, Shader.class,
Expand All @@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception{
classes.sort(Structs.comparing(Class::getName));

classes.removeAll(type -> type.isSynthetic() || type.isAnonymousClass() || type.getCanonicalName() == null || Modifier.isPrivate(type.getModifiers())
|| blacklist.contains(s -> type.getName().startsWith(base + "." + s + ".")) || nameBlacklist.contains(type.getSimpleName()));
|| blacklist.contains(s -> type.getName().startsWith(base + "." + s + ".")) || nameBlacklist.contains(type.getSimpleName()) || blacklist.contains(type.getPackage().getName()));
classes.add(NetConnection.class, SaveIO.class, SystemCursor.class);

classes.distinct();
Expand Down

0 comments on commit dace346

Please sign in to comment.