Skip to content

Commit 7fafbb2

Browse files
committedJun 12, 2022
mobile support :o
1 parent 18ea989 commit 7fafbb2

13 files changed

+129
-46
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/build/
22
/.idea/
3-
/.gradle/
3+
/.gradle/
4+
/local.properties

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Dusted Lands
33
A small mod which adds powders to the game, along with a ton of turrets, units, and other content.
44
# Compiling
5-
1. Download Java 16.
6-
2. Run `gradlew jar` (or `./gradlew jar` on Linux/Mac).
7-
3. The mod jar will be in `/build/libs/`. Currently doesn't support android.
5+
1. Clone this repository.
6+
2. Install any necessary files, such as Java 16 and the Android SDK.
7+
3. Run `gradlew deploy`. This should create a jar in the `build/libs` directory.

‎build.gradle

+47-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ repositories {
1616
ext {
1717
mindustryVersion = 'v135'
1818
jabelVersion = '0.6.0'
19+
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
1920
}
2021

2122
allprojects {
@@ -30,13 +31,58 @@ dependencies {
3031
annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
3132
}
3233

34+
35+
3336
jar {
34-
archiveFileName = "${project.archivesBaseName}.jar"
37+
archiveFileName = "${project.archivesBaseName}Desktop.jar"
3538
from {
3639
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
3740
}
3841

3942
from(rootDir) {
4043
include "mod.hjson"
4144
}
45+
}
46+
47+
task jarAndroid {
48+
dependsOn "jar"
49+
50+
doLast {
51+
if (!sdkRoot || !new File(sdkRoot).exists()) throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.")
52+
53+
def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find { f -> new File(f, "android.jar").exists() }
54+
55+
if (!platformRoot) throw new GradleException("No android.jar found. Ensure that you have an Android platform installed.")
56+
57+
//collect dependencies needed for desugaring
58+
def dependencies = (configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")]).collect { "--classpath $it.path" }.join(" ")
59+
60+
//dex and desugar files - this requires d8 in your PATH
61+
def paras = "$dependencies --min-api 14 --output ${project.archivesBaseName}Android.jar ${project.archivesBaseName}Desktop.jar".toString()
62+
try {
63+
"d8 $paras".execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err)
64+
} catch (Exception ignored) {
65+
logger.lifecycle("d8 cannot be found in your PATH, so trying to use an absolute path.")
66+
def cmdOutput = new ByteArrayOutputStream()
67+
"where d8".execute().waitForProcessOutput(cmdOutput, System.err)
68+
def d8FullPath = cmdOutput.toString().replace("\r", "").replace("\n", "")
69+
logger.lifecycle("d8 was found at $d8FullPath")
70+
"$d8FullPath $paras".execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err)
71+
}
72+
}
73+
}
74+
75+
task deploy(type: Jar) {
76+
dependsOn jarAndroid
77+
dependsOn jar
78+
archiveFileName = "${project.archivesBaseName}.jar"
79+
80+
from { [zipTree("$buildDir/libs/${project.archivesBaseName}Desktop.jar"), zipTree("$buildDir/libs/${project.archivesBaseName}Android.jar")] }
81+
82+
doLast {
83+
delete {
84+
delete "$buildDir/libs/${project.archivesBaseName}Desktop.jar"
85+
delete "$buildDir/libs/${project.archivesBaseName}Android.jar"
86+
}
87+
}
4288
}

‎mod.hjson

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: "dusted-lands"
22
main: "dusted.DustedLands"
3-
version: 0.2
3+
version: 0.21
44
minGameVersion: 129
55
java: true
66

77
displayName: "Dusted Lands"
88
author: "KayAyeAre"
9-
description: "A small mod which adds powders to the game, along with a ton of turrets, units, and other content."
9+
description: "A small mod which adds powders to the game, along with some of turrets, units, and other content."
1010
repo: "KayyAyeAre/Dusted-Lands"

‎src/dusted/DustedLands.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package dusted;
22

33
import arc.*;
4-
import arc.struct.*;
54
import dusted.content.*;
65
import dusted.input.*;
76
import dusted.world.*;
87
import mindustry.*;
98
import mindustry.mod.*;
10-
import mindustry.world.*;
119

1210
public class DustedLands extends Mod {
13-
public static DustedInput input;
11+
public DustedInputHandler inputHandler;
1412

1513
public DustedLands() {
1614
Vars.enableConsole = true;
17-
Core.app.addListener(input = new DustedInput());
15+
Core.app.addListener(inputHandler = new DustedInputHandler());
1816
VolcanoSpawner.load();
1917
}
2018

‎src/dusted/ai/types/BounceAI.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class BounceAI extends FlyingAI {
88
@Override
9-
public void updateWeapons() {
10-
super.updateWeapons();
9+
public void updateTargeting() {
10+
super.updateTargeting();
1111
if (target != null) unit.abilities.each(a -> a instanceof BounceAbility, a -> ((BounceAbility) a).bounce(unit, target));
1212
}
1313
}

‎src/dusted/ai/types/OrbsAI.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dusted.ai.types;
22

33
import dusted.entities.abilities.*;
4+
import mindustry.*;
45
import mindustry.ai.types.*;
56
import mindustry.gen.*;
67

@@ -9,11 +10,11 @@ public class OrbsAI extends GroundAI {
910
public void updateUnit() {
1011
super.updateUnit();
1112

12-
if (unit.abilities.contains(a -> a instanceof RevolvingOrbAbility)) {
13-
RevolvingOrbAbility ability = (RevolvingOrbAbility) unit.abilities.find(a -> a instanceof RevolvingOrbAbility);
14-
if (Groups.bullet.intersect(unit.x - (ability.radius * 2), unit.y - (ability.radius * 2), ability.radius * 4, ability.radius * 4).contains(b -> b.team.isEnemy(unit.team))) {
15-
ability.summon();
13+
unit.abilities.each(a -> a instanceof RevolvingOrbAbility, a -> {
14+
RevolvingOrbAbility orbs = (RevolvingOrbAbility) a;
15+
if (Groups.bullet.intersect(unit.x - (orbs.radius * 2), unit.y - (orbs.radius * 2), orbs.radius * 4, orbs.radius * 4).contains(b -> b.team.isEnemy(Vars.player.unit().team))) {
16+
orbs.summon();
1617
}
17-
}
18+
});
1819
}
1920
}

‎src/dusted/content/DustedBlocks.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,10 @@ DustedPowders.quartzDust, new RocketBulletType(3.8f, 50f) {{
589589

590590
consumes.power(5f);
591591
consumes.items(ItemStack.with(Items.silicon, 120, Items.titanium, 100, DustedItems.plastel, 60));
592-
upgrades.addAll(new UnitType[]{DustedUnitTypes.recur, DustedUnitTypes.saltate});
592+
upgrades.addAll(
593+
new UnitType[]{DustedUnitTypes.recur, DustedUnitTypes.saltate},
594+
new UnitType[]{DustedUnitTypes.rancor, DustedUnitTypes.animus}
595+
);
593596
}};
594597
//endregion
595598
//region cores

‎src/dusted/input/CustomInput.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dusted.input;
2+
3+
public interface CustomInput {
4+
void update();
5+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dusted.input;
2+
3+
import arc.*;
4+
import arc.input.*;
5+
import dusted.entities.abilities.*;
6+
import mindustry.*;
7+
8+
public class DustedDesktopInput implements CustomInput {
9+
@Override
10+
public void update() {
11+
if (Vars.state.isPlaying()) {
12+
if (Core.input.keyTap(KeyCode.b) && !Core.scene.hasKeyboard()) Vars.player.unit().abilities.each(a -> a instanceof BounceAbility, a -> ((BounceAbility) a).bounce(Vars.player.unit()));
13+
if (Core.input.keyTap(KeyCode.q) && !Core.scene.hasKeyboard()) Vars.player.unit().abilities.each(a -> a instanceof QuakeAbility, a -> ((QuakeAbility) a).quake());
14+
if (Core.input.keyTap(KeyCode.r) && !Core.scene.hasKeyboard()) Vars.player.unit().abilities.each(a -> a instanceof RevolvingOrbAbility, a -> ((RevolvingOrbAbility) a).summon());
15+
}
16+
}
17+
}

‎src/dusted/input/DustedInput.java

-27
This file was deleted.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dusted.input;
2+
3+
import arc.*;
4+
import mindustry.*;
5+
6+
public class DustedInputHandler implements ApplicationListener {
7+
public CustomInput input;
8+
9+
{
10+
input = Vars.mobile ? new DustedMobileInput() : new DustedDesktopInput();
11+
}
12+
@Override
13+
public void update() {
14+
input.update();
15+
}
16+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dusted.input;
2+
3+
import arc.*;
4+
import dusted.entities.abilities.*;
5+
import mindustry.*;
6+
import mindustry.gen.*;
7+
8+
public class DustedMobileInput implements CustomInput {
9+
@Override
10+
public void update() {
11+
if (Vars.player.shooting) {
12+
Vars.player.unit().abilities.each(a -> a instanceof BounceAbility, a -> ((BounceAbility) a).bounce(Vars.player.unit()));
13+
Vars.player.unit().abilities.each(a -> a instanceof QuakeAbility, a -> ((QuakeAbility) a).quake());
14+
}
15+
16+
Vars.player.unit().abilities.each(a -> a instanceof RevolvingOrbAbility, a -> {
17+
RevolvingOrbAbility orbs = (RevolvingOrbAbility) a;
18+
if (Groups.bullet.intersect(Vars.player.unit().x - (orbs.radius * 2), Vars.player.unit().y - (orbs.radius * 2), orbs.radius * 4, orbs.radius * 4).contains(b -> b.team.isEnemy(Vars.player.unit().team))) {
19+
orbs.summon();
20+
}
21+
});
22+
}
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.