mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 03:59:26 +02:00
fixed bug, clean up, added player name json
This commit is contained in:
@@ -33,6 +33,7 @@ jar {
|
||||
dependencies {
|
||||
compileOnly "com.github.Anuken.Arc:arc-core:$pMindustryVersion"
|
||||
compileOnly "com.github.Anuken.Mindustry:core:$pMindustryVersion"
|
||||
implementation 'org.hjson:hjson:3.0.0'
|
||||
}
|
||||
|
||||
task dexify(type: Jar) {
|
||||
|
||||
17
src/UnitInfo/SVars.java
Normal file
17
src/UnitInfo/SVars.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package UnitInfo;
|
||||
|
||||
import UnitInfo.core.HudUi;
|
||||
import UnitInfo.core.PlayerParser;
|
||||
import UnitInfo.core.Setting;
|
||||
import arc.Core;
|
||||
import arc.files.Fi;
|
||||
import arc.struct.Seq;
|
||||
|
||||
public class SVars {
|
||||
public static Fi modRoot = Core.settings.getDataDirectory().child("mods/UnitInfo");
|
||||
public static Seq<PlayerParser.PlayerInfo> playerInfos = new Seq<>();
|
||||
|
||||
public static Setting settingAdder = new Setting();
|
||||
public static HudUi hud = new HudUi();
|
||||
public static PlayerParser playerinfo = new PlayerParser();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package UnitInfo.core;
|
||||
|
||||
import UnitInfo.SVars;
|
||||
import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.math.Mathf;
|
||||
@@ -24,24 +25,24 @@ import static mindustry.Vars.content;
|
||||
import static mindustry.Vars.state;
|
||||
|
||||
public class BarInfo {
|
||||
Seq<String> strings = new Seq<>(new String[]{"","","","","",""});
|
||||
Seq<Float> numbers = new Seq<>(new Float[]{0f,0f,0f,0f,0f,0f});
|
||||
Seq<Color> colors = new Seq<>(new Color[]{Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear});
|
||||
static Seq<String> strings = new Seq<>(new String[]{"","","","","",""});
|
||||
static Seq<Float> numbers = new Seq<>(new Float[]{0f,0f,0f,0f,0f,0f});
|
||||
static Seq<Color> colors = new Seq<>(new Color[]{Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear});
|
||||
|
||||
public <T extends Teamc> Seq<String> returnStrings(T target){
|
||||
public static <T extends Teamc> Seq<String> returnStrings(T target){
|
||||
getInfo(target);
|
||||
return strings;
|
||||
}
|
||||
public <T extends Teamc> Seq<Color> returnColors(T target){
|
||||
public static <T extends Teamc> Seq<Color> returnColors(T target){
|
||||
getInfo(target);
|
||||
return colors;
|
||||
}
|
||||
public <T extends Teamc> Seq<Float> returnNumbers(T target){
|
||||
public static <T extends Teamc> Seq<Float> returnNumbers(T target){
|
||||
getInfo(target);
|
||||
return numbers;
|
||||
}
|
||||
|
||||
public <T extends Teamc> void getInfo(T target){
|
||||
public static <T extends Teamc> void getInfo(T target){
|
||||
for(int i = 0; i < 6; i++) { //init
|
||||
strings.set(i, "[lightgray]<Empty>[]");
|
||||
colors.set(i, Color.clear);
|
||||
@@ -133,10 +134,10 @@ public class BarInfo {
|
||||
if(target instanceof Turret.TurretBuild){
|
||||
Turret turret = (Turret)((Turret.TurretBuild)target).block;
|
||||
if(turret.chargeTime > 0f) {
|
||||
float value = Mathf.clamp(Main.hud.charge / turret.chargeTime) * 100f;
|
||||
float value = Mathf.clamp(SVars.hud.charge / turret.chargeTime) * 100f;
|
||||
strings.set(3, Core.bundle.format("shar-stat.charge", Strings.fixed(value, (Math.abs((int)value - value) <= 0.001f ? 0 : Math.abs((int)(value * 10) - value * 10) <= 0.001f ? 1 : 2))));
|
||||
colors.set(3, Pal.surge.cpy().lerp(Pal.accent, Main.hud.charge / turret.chargeTime));
|
||||
numbers.set(3, Main.hud.charge / turret.chargeTime);
|
||||
colors.set(3, Pal.surge.cpy().lerp(Pal.accent, SVars.hud.charge / turret.chargeTime));
|
||||
numbers.set(3, SVars.hud.charge / turret.chargeTime);
|
||||
}
|
||||
}
|
||||
else if(target instanceof Unit && ((Unit) target).type != null) {
|
||||
|
||||
@@ -46,7 +46,6 @@ public class HudUi {
|
||||
float tileScrollPos;
|
||||
float itemScrollPos;
|
||||
|
||||
Element image;
|
||||
Color lastItemColor = Pal.items;
|
||||
Color lastAmmoColor = Pal.ammo;
|
||||
Teamc lockedTarget;
|
||||
@@ -191,7 +190,6 @@ public class HudUi {
|
||||
update(() -> {
|
||||
if(!(getTarget() instanceof ItemTurret.ItemTurretBuild) && !(getTarget() instanceof LiquidTurret.LiquidTurretBuild) && !(getTarget() instanceof PowerTurret.PowerTurretBuild)){
|
||||
clearChildren();
|
||||
image = null;
|
||||
return;
|
||||
}
|
||||
if(getTarget() instanceof Turret.TurretBuild){
|
||||
@@ -216,15 +214,14 @@ public class HudUi {
|
||||
imaget = new Image(entity.liquids.current().uiIcon).setScaling(Scaling.fit);
|
||||
}
|
||||
else if(getTarget() instanceof PowerTurret.PowerTurretBuild){
|
||||
imaget = new ReqImage(Icon.power.getRegion(), () -> ((PowerTurret.PowerTurretBuild) getTarget()).power.status * ((PowerTurret.PowerTurretBuild) getTarget()).power.graph.getLastScaledPowerIn() > 0f){{
|
||||
add(new Image(Icon.power.getRegion()));
|
||||
add(new Element(){
|
||||
imaget = new Image(Icon.power.getRegion()){
|
||||
@Override
|
||||
public void draw(){
|
||||
Building entity = getTarget();
|
||||
float max = entity.block.consumes.getPower().usage;
|
||||
float v = entity.power.status * entity.power.graph.getLastScaledPowerIn();
|
||||
|
||||
super.draw();
|
||||
Lines.stroke(Scl.scl(2f), Pal.removeBack);
|
||||
Draw.alpha(1 - v/max);
|
||||
Lines.line(x, y - 2f + height, x + width, y - 2f);
|
||||
@@ -233,14 +230,11 @@ public class HudUi {
|
||||
Lines.line(x, y + height, x + width, y);
|
||||
Draw.reset();
|
||||
}
|
||||
});
|
||||
}};
|
||||
};
|
||||
}
|
||||
|
||||
if(image != null && (imaget.getClass() != image.getClass() || imaget.getClass() == Image.class))
|
||||
clearChildren();
|
||||
add(imaget).size(iconSmall).padBottom(2 * 8f).padRight(3 * 8f);
|
||||
image = imaget;
|
||||
}
|
||||
});
|
||||
pack();
|
||||
|
||||
@@ -3,6 +3,7 @@ package UnitInfo.core;
|
||||
import UnitInfo.ui.FreeBar;
|
||||
import arc.Core;
|
||||
import arc.Events;
|
||||
import arc.files.Fi;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.g2d.Draw;
|
||||
import arc.graphics.g2d.Fill;
|
||||
@@ -30,12 +31,11 @@ import mindustry.world.Block;
|
||||
import mindustry.world.blocks.defense.turrets.BaseTurret;
|
||||
import mindustry.world.blocks.defense.turrets.Turret;
|
||||
|
||||
import static UnitInfo.SVars.*;
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Main extends Mod {
|
||||
public static Setting settingAdder = new Setting();
|
||||
public static HudUi hud = new HudUi();
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
@@ -48,6 +48,8 @@ public class Main extends Mod {
|
||||
hud.addTileTable();
|
||||
hud.addTable();
|
||||
hud.setEvent();
|
||||
playerinfo.createFile();
|
||||
playerinfo.setEvent();
|
||||
});
|
||||
|
||||
Events.on(WorldLoadEvent.class, e -> {
|
||||
@@ -62,8 +64,6 @@ public class Main extends Mod {
|
||||
hud.addWaveTable();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Events.run(Trigger.draw, () -> {
|
||||
if(settings.getBool("blockstatus")) Groups.build.each(build -> {
|
||||
if(Vars.player != null && Vars.player.team() == build.team) return;
|
||||
|
||||
66
src/UnitInfo/core/PlayerParser.java
Normal file
66
src/UnitInfo/core/PlayerParser.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package UnitInfo.core;
|
||||
|
||||
import UnitInfo.SVars;
|
||||
import arc.Events;
|
||||
import arc.struct.Seq;
|
||||
import mindustry.Vars;
|
||||
import mindustry.game.EventType;
|
||||
import mindustry.gen.Groups;
|
||||
import mindustry.gen.Player;
|
||||
import org.hjson.JsonArray;
|
||||
import org.hjson.JsonObject;
|
||||
import org.hjson.Stringify;
|
||||
|
||||
import static UnitInfo.SVars.modRoot;
|
||||
|
||||
public class PlayerParser{
|
||||
|
||||
public void setEvent() {
|
||||
Events.on(EventType.PlayerJoin.class, e -> {
|
||||
writeJson(e.player);
|
||||
});
|
||||
Events.on(EventType.ServerLoadEvent.class, e->{
|
||||
Groups.player.each(this::writeJson);
|
||||
});
|
||||
Events.on(EventType.WorldLoadEvent.class, e->{
|
||||
if(Vars.net.active()) Groups.player.each(this::writeJson);
|
||||
});
|
||||
Events.run(EventType.Trigger.update, ()->{
|
||||
if(Vars.net.active())
|
||||
Groups.player.each(this::writeJson);
|
||||
});
|
||||
}
|
||||
|
||||
public void createFile() {
|
||||
if(!modRoot.child("players.hjson").exists()) save();
|
||||
}
|
||||
|
||||
public void writeJson(Player player1){
|
||||
PlayerInfo info = SVars.playerInfos.find(pi -> pi.player == player1);
|
||||
if(info != null){
|
||||
if(!info.names.contains(player1.name)) info.names.add(player1.name);
|
||||
}
|
||||
else{
|
||||
SVars.playerInfos.add(new PlayerInfo(){{
|
||||
player = player1;
|
||||
names.add(player1.name);
|
||||
}});
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
JsonObject data = new JsonObject();
|
||||
SVars.playerInfos.each(pi->{
|
||||
JsonArray arr = new JsonArray();
|
||||
pi.names.each(arr::add);
|
||||
data.add("names", arr);
|
||||
});
|
||||
|
||||
modRoot.child("players.hjson").writeString(data.toString(Stringify.HJSON));
|
||||
}
|
||||
public static class PlayerInfo{
|
||||
Player player;
|
||||
Seq<String> names = new Seq<>();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import arc.struct.Seq;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.core.Version;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.Styles;
|
||||
import mindustry.ui.dialogs.*;
|
||||
|
||||
Reference in New Issue
Block a user