Skip to content

Commit 35e699d

Browse files
committed
Rewrite most of mlogv32-utils in Kotlin
1 parent a1367f6 commit 35e699d

File tree

15 files changed

+833
-304
lines changed

15 files changed

+833
-304
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,44 @@ logicids.json
1414
.ruff_cache/
1515
.theia/
1616

17+
.kotlin/
18+
19+
## Gradle
20+
.gradle
21+
**/build/
22+
!src/**/build/
23+
!gradle-wrapper.jar
24+
25+
## Eclipse
26+
bin/
27+
.metadata/
28+
.settings/
29+
.classpath
30+
.project
31+
.loadpath
32+
33+
## Java
34+
*.class
35+
*.jar
36+
*.war
37+
*.rar
38+
*.nar
39+
*.ear
40+
*.zip
41+
*.tar.gz
42+
hs_err_pid*
43+
replay_pid*
44+
45+
## Intellij
46+
.idea/
47+
*.ipr
48+
*.iws
49+
*.iml
50+
51+
## OS Specific
52+
.DS_Store
53+
Thumbs.db
54+
1755
# Byte-compiled / optimized / DLL files
1856
__pycache__/
1957
*.py[cod]

mod/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# mlogv32-utils
2+
3+
Companion mod for mlogv32.
4+
5+
Based on xpdustry/kotlin-runtime and xpdustry/template-plugin.

mod/assets/scripts/main.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// this is some of the worst code i've written in my life
2+
3+
Blocks.worldProcessor.maxInstructionsPerTick = 1000000;
4+
5+
/** @type ClassLoader */
6+
const loader = Vars.mods.getMod("mlogv32-utils").loader;
7+
const ProcessorAccess = loader.loadClass("gay.object.mlogv32.ProcessorAccess");
8+
const ProcessorAccess_Companion = ProcessorAccess.getField("Companion").get(null);
9+
10+
global.override.block(LogicBlock, {
11+
/**
12+
* @param {Table} table
13+
*/
14+
buildConfiguration(table) {
15+
/** @type Table */
16+
const buttons = table.table().get();
17+
this.super$buildConfiguration(buttons);
18+
19+
const processor = ProcessorAccess_Companion.of(this);
20+
if (processor != null) {
21+
buttons
22+
.button(Icon.download, Styles.cleari, () => {
23+
Vars.platform.showFileChooser(true, "bin", (file) => {
24+
try {
25+
const bytes = processor.flashRom(file);
26+
const message =
27+
"Flashed " + bytes + " bytes from " + file.name() + " to ROM.";
28+
Log.info(message);
29+
Vars.ui.hudfrag.showToast("Done! " + message);
30+
} catch (e) {
31+
Log.err(e);
32+
Vars.ui.hudfrag.showToast(Icon.warning, "Failed to flash ROM: " + e);
33+
}
34+
});
35+
})
36+
.tooltip("Flash mlogv32 ROM")
37+
.size(40);
38+
39+
buttons
40+
.button(Icon.upload, Styles.cleari, () => {
41+
Vars.platform.showFileChooser(false, "bin", (file) => {
42+
try {
43+
const bytes = processor.dumpRam(file);
44+
const message =
45+
"Dumped " + bytes + " bytes from RAM to " + file.name() + ".";
46+
Log.info(message);
47+
Vars.ui.hudfrag.showToast("Done! " + message);
48+
} catch (e) {
49+
Log.err(e);
50+
Vars.ui.hudfrag.showToast(Icon.warning, "Failed to dump RAM: " + e);
51+
}
52+
});
53+
})
54+
.tooltip("Dump mlogv32 RAM")
55+
.size(40);
56+
}
57+
},
58+
});
59+
60+
Log.info("Loaded mlogv32-utils scripts.");

mod/build.gradle.kts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import com.xpdustry.toxopid.extension.anukeXpdustry
2+
import com.xpdustry.toxopid.spec.ModMetadata
3+
import com.xpdustry.toxopid.spec.ModPlatform
4+
5+
plugins {
6+
alias(libs.plugins.kotlin)
7+
alias(libs.plugins.indra.common)
8+
alias(libs.plugins.shadow)
9+
alias(libs.plugins.toxopid)
10+
}
11+
12+
val metadata = ModMetadata.fromJson(file("mod.hjson"))
13+
group = "gay.object"
14+
version = metadata.version
15+
description = metadata.description
16+
17+
toxopid {
18+
compileVersion = "v${metadata.minGameVersion}"
19+
platforms = setOf(ModPlatform.DESKTOP, ModPlatform.ANDROID, ModPlatform.SERVER)
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
anukeXpdustry()
25+
}
26+
27+
dependencies {
28+
compileOnly(toxopid.dependencies.arcCore)
29+
compileOnly(toxopid.dependencies.mindustryCore)
30+
31+
implementation(kotlin("stdlib-jdk8"))
32+
}
33+
34+
indra {
35+
javaVersions {
36+
target(8)
37+
minimumToolchain(17)
38+
}
39+
}
40+
41+
// FIXME: we should be using kotlin-runtime instead, but it doesn't seem to work on build 149
42+
43+
//configurations.runtimeClasspath {
44+
// exclude("org.jetbrains.kotlin")
45+
// exclude("org.jetbrains.kotlinx")
46+
//}
47+
48+
tasks {
49+
val generateResources by registering {
50+
inputs.property("metadata", metadata)
51+
val output = temporaryDir.resolve("mod.json")
52+
outputs.file(output)
53+
doLast {
54+
output.writeText(ModMetadata.toJson(metadata, true))
55+
}
56+
}
57+
58+
shadowJar {
59+
archiveClassifier = "mod"
60+
from(generateResources)
61+
from("./assets") {
62+
include("**")
63+
}
64+
}
65+
66+
build {
67+
dependsOn(shadowJar)
68+
}
69+
}

mod/gradle/libs.versions.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[versions]
2+
kotlin = "2.1.20"
3+
indra = "3.1.3"
4+
shadow = "8.3.6"
5+
toxopid = "4.1.2"
6+
7+
[plugins]
8+
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
9+
indra-common = { id = "net.kyori.indra", version.ref = "indra" }
10+
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
11+
toxopid = { id = "com.xpdustry.toxopid", version.ref = "toxopid" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)