Fixed #748 / Better mod loading

This commit is contained in:
Anuken
2019-09-29 21:41:32 -04:00
parent 0049a0004e
commit 002a052371
14 changed files with 85 additions and 61 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -627,7 +627,7 @@ keybind.chat.name = Chat
keybind.player_list.name = Player list keybind.player_list.name = Player list
keybind.console.name = Console keybind.console.name = Console
keybind.rotate.name = Rotate keybind.rotate.name = Rotate
keybind.rotateplaced.name = Rotate Placed (Hold) keybind.rotateplaced.name = Rotate Existing (Hold)
keybind.toggle_menus.name = Toggle menus keybind.toggle_menus.name = Toggle menus
keybind.chat_history_prev.name = Chat history prev keybind.chat_history_prev.name = Chat history prev
keybind.chat_history_next.name = Chat history next keybind.chat_history_next.name = Chat history next

View File

@ -15031,7 +15031,6 @@ scroll-knob-horizontal-black
rotate: false rotate: false
xy: 1937, 749 xy: 1937, 749
size: 40, 24 size: 40, 24
split: 11, 10, 10, 10
orig: 40, 24 orig: 40, 24
offset: 0, 0 offset: 0, 0
index: -1 index: -1
@ -15039,7 +15038,6 @@ scroll-knob-vertical-black
rotate: false rotate: false
xy: 1832, 429 xy: 1832, 429
size: 24, 40 size: 24, 40
split: 10, 10, 6, 10
orig: 24, 40 orig: 24, 40
offset: 0, 0 offset: 0, 0
index: -1 index: -1

View File

@ -17,7 +17,7 @@ public class UnitTypes implements ContentList{
@Override @Override
public void load(){ public void load(){
draug = new UnitType("draug", Draug.class, Draug::new){{ draug = new UnitType("draug", Draug::new){{
flying = true; flying = true;
drag = 0.01f; drag = 0.01f;
speed = 0.3f; speed = 0.3f;
@ -32,7 +32,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
spirit = new UnitType("spirit", Spirit.class, Spirit::new){{ spirit = new UnitType("spirit", Spirit::new){{
flying = true; flying = true;
drag = 0.01f; drag = 0.01f;
speed = 0.4f; speed = 0.4f;
@ -53,7 +53,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
phantom = new UnitType("phantom", Phantom.class, Phantom::new){{ phantom = new UnitType("phantom", Phantom::new){{
flying = true; flying = true;
drag = 0.01f; drag = 0.01f;
mass = 2f; mass = 2f;
@ -77,7 +77,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
dagger = new UnitType("dagger", Dagger.class, Dagger::new){{ dagger = new UnitType("dagger", Dagger::new){{
maxVelocity = 1.1f; maxVelocity = 1.1f;
speed = 0.2f; speed = 0.2f;
drag = 0.4f; drag = 0.4f;
@ -93,7 +93,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
crawler = new UnitType("crawler", Crawler.class, Crawler::new){{ crawler = new UnitType("crawler", Crawler::new){{
maxVelocity = 1.27f; maxVelocity = 1.27f;
speed = 0.285f; speed = 0.285f;
drag = 0.4f; drag = 0.4f;
@ -124,7 +124,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
titan = new UnitType("titan", Titan.class, Titan::new){{ titan = new UnitType("titan", Titan::new){{
maxVelocity = 0.8f; maxVelocity = 0.8f;
speed = 0.22f; speed = 0.22f;
drag = 0.4f; drag = 0.4f;
@ -146,7 +146,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
fortress = new UnitType("fortress", Fortress.class, Fortress::new){{ fortress = new UnitType("fortress", Fortress::new){{
maxVelocity = 0.78f; maxVelocity = 0.78f;
speed = 0.15f; speed = 0.15f;
drag = 0.4f; drag = 0.4f;
@ -168,7 +168,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
eruptor = new UnitType("eruptor", Eruptor.class, Eruptor::new){{ eruptor = new UnitType("eruptor", Eruptor::new){{
maxVelocity = 0.81f; maxVelocity = 0.81f;
speed = 0.16f; speed = 0.16f;
drag = 0.4f; drag = 0.4f;
@ -190,7 +190,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
chaosArray = new UnitType("chaos-array", Dagger.class, Dagger::new){{ chaosArray = new UnitType("chaos-array", Dagger::new){{
maxVelocity = 0.68f; maxVelocity = 0.68f;
speed = 0.12f; speed = 0.12f;
drag = 0.4f; drag = 0.4f;
@ -214,7 +214,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
eradicator = new UnitType("eradicator", Dagger.class, Dagger::new){{ eradicator = new UnitType("eradicator", Dagger::new){{
maxVelocity = 0.68f; maxVelocity = 0.68f;
speed = 0.12f; speed = 0.12f;
drag = 0.4f; drag = 0.4f;
@ -239,7 +239,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
wraith = new UnitType("wraith", Wraith.class, Wraith::new){{ wraith = new UnitType("wraith", Wraith::new){{
speed = 0.3f; speed = 0.3f;
maxVelocity = 1.9f; maxVelocity = 1.9f;
drag = 0.01f; drag = 0.01f;
@ -258,7 +258,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
ghoul = new UnitType("ghoul", Ghoul.class, Ghoul::new){{ ghoul = new UnitType("ghoul", Ghoul::new){{
health = 220; health = 220;
speed = 0.2f; speed = 0.2f;
maxVelocity = 1.4f; maxVelocity = 1.4f;
@ -282,7 +282,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
revenant = new UnitType("revenant", Revenant.class, Revenant::new){{ revenant = new UnitType("revenant", Revenant::new){{
health = 1000; health = 1000;
mass = 5f; mass = 5f;
hitsize = 20f; hitsize = 20f;
@ -313,7 +313,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
lich = new UnitType("lich", Revenant.class, Revenant::new){{ lich = new UnitType("lich", Revenant::new){{
health = 6000; health = 6000;
mass = 20f; mass = 20f;
hitsize = 40f; hitsize = 40f;
@ -346,7 +346,7 @@ public class UnitTypes implements ContentList{
}}; }};
}}; }};
reaper = new UnitType("reaper", Revenant.class, Revenant::new){{ reaper = new UnitType("reaper", Revenant::new){{
health = 11000; health = 11000;
mass = 30f; mass = 30f;
hitsize = 56f; hitsize = 56f;

View File

@ -215,14 +215,6 @@ public class MapEditorDialog extends Dialog implements Disposable{
return; return;
} }
Vector2 v = pane.stageToLocalCoordinates(Core.input.mouse());
if(v.x >= 0 && v.y >= 0 && v.x <= pane.getWidth() && v.y <= pane.getHeight()){
Core.scene.setScrollFocus(pane);
}else{
Core.scene.setScrollFocus(null);
}
if(Core.scene != null && Core.scene.getKeyboardFocus() == this){ if(Core.scene != null && Core.scene.getKeyboardFocus() == this){
doInput(); doInput();
} }

View File

@ -59,18 +59,25 @@ public class MapInfoDialog extends FloatingDialog{
t.row(); t.row();
t.add("$editor.rules").padRight(8).left(); t.add("$editor.rules").padRight(8).left();
t.addButton("$edit", () -> ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules())).left().width(200f); t.addButton("$edit", () -> {
ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules());
hide();
}).left().width(200f);
t.row(); t.row();
t.add("$editor.waves").padRight(8).left(); t.add("$editor.waves").padRight(8).left();
t.addButton("$edit", waveInfo::show).left().width(200f); t.addButton("$edit", () -> {
waveInfo.show();
hide();
}).left().width(200f);
t.row(); t.row();
t.add("$editor.generation").padRight(8).left(); t.add("$editor.generation").padRight(8).left();
t.addButton("$edit", t.addButton("$edit", () -> {
() -> generate.show(Vars.maps.readFilters(editor.getTags().get("genfilters", "")), generate.show(Vars.maps.readFilters(editor.getTags().get("genfilters", "")),
filters -> editor.getTags().put("genfilters", JsonIO.write(filters))) filters -> editor.getTags().put("genfilters", JsonIO.write(filters)));
).left().width(200f); hide();
}).left().width(200f);
name.change(); name.change();
description.change(); description.change();

View File

@ -43,11 +43,9 @@ public class ContentParser{
private ObjectMap<ContentType, TypeParser<?>> parsers = ObjectMap.of( private ObjectMap<ContentType, TypeParser<?>> parsers = ObjectMap.of(
ContentType.block, (TypeParser<Block>)(mod, name, value) -> { ContentType.block, (TypeParser<Block>)(mod, name, value) -> {
String clas = value.getString("type"); Class<Block> type = resolve(value.getString("type"), "io.anuke.mindustry.world", "io.anuke.mindustry.world.blocks", "io.anuke.mindustry.world.blocks.defense");
Class<Block> type = resolve("io.anuke.mindustry.world." + clas, "io.anuke.mindustry.world.blocks." + clas, "io.anuke.mindustry.world.blocks.defense" + clas);
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name); Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
value.remove("type"); readFields(block, value, true);
readFields(block, value);
//make block visible //make block visible
if(block.buildRequirements != null){ if(block.buildRequirements != null){
@ -57,29 +55,25 @@ public class ContentParser{
return block; return block;
}, },
ContentType.unit, (TypeParser<UnitType>)(mod, name, value) -> { ContentType.unit, (TypeParser<UnitType>)(mod, name, value) -> {
String clas = value.getString("type"); Class<BaseUnit> type = resolve(value.getString("type"), "io.anuke.mindustry.entities.type.base");
Class<BaseUnit> type = resolve("io.anuke.mindustry.entities.type.base." + clas); UnitType unit = new UnitType(mod + "-" + name, supply(type));
java.lang.reflect.Constructor<BaseUnit> cons = type.getDeclaredConstructor(); readFields(unit, value, true);
UnitType unit = new UnitType(mod + "-" + name, type, () -> {
try{
return cons.newInstance();
}catch(Exception e){
throw new RuntimeException(e);
}
});
value.remove("type");
readFields(unit, value);
return unit; return unit;
}, },
ContentType.item, parser(Item::new), ContentType.item, parser(ContentType.item, Item::new),
ContentType.liquid, parser(Liquid::new), ContentType.liquid, parser(ContentType.liquid, Liquid::new),
ContentType.mech, parser(Mech::new) ContentType.mech, parser(ContentType.mech, Mech::new)
); );
private <T extends Content> TypeParser<T> parser(Function<String, T> constructor){ private <T extends Content> TypeParser<T> parser(ContentType type, Function<String, T> constructor){
return (mod, name, value) -> { return (mod, name, value) -> {
T item = constructor.get(mod + "-" + name); T item;
if(Vars.content.getByName(type, name) != null){
item = (T)Vars.content.getByName(type, name);
}else{
item = constructor.get(mod + "-" + name);
}
readFields(item, value); readFields(item, value);
return item; return item;
}; };
@ -122,6 +116,21 @@ public class ContentParser{
return c; return c;
} }
private <T> Supplier<T> supply(Class<T> type){
try{
java.lang.reflect.Constructor<T> cons = type.getDeclaredConstructor();
return () -> {
try{
return cons.newInstance();
}catch(Exception e){
throw new RuntimeException(e);
}
};
}catch(Exception e){
throw new RuntimeException(e);
}
}
private Object field(Class<?> type, JsonValue value){ private Object field(Class<?> type, JsonValue value){
return field(type, value.asString()); return field(type, value.asString());
} }
@ -165,6 +174,11 @@ public class ContentParser{
}); });
} }
private void readFields(Object object, JsonValue jsonMap, boolean stripType){
if(stripType) jsonMap.remove("type");
readFields(object, jsonMap);
}
private void readFields(Object object, JsonValue jsonMap){ private void readFields(Object object, JsonValue jsonMap){
Class type = object.getClass(); Class type = object.getClass();
ObjectMap<String, FieldMetadata> fields = parser.getFields(type); ObjectMap<String, FieldMetadata> fields = parser.getFields(type);
@ -198,10 +212,10 @@ public class ContentParser{
} }
/** Tries to resolve a class from a list of potential class names. */ /** Tries to resolve a class from a list of potential class names. */
private <T> Class<T> resolve(String... potentials) throws Exception{ private <T> Class<T> resolve(String base, String... potentials) throws Exception{
for(String type : potentials){ for(String type : potentials){
try{ try{
return (Class<T>)Class.forName(type); return (Class<T>)Class.forName(type + '.' + base);
}catch(Exception ignored){ }catch(Exception ignored){
} }
} }

View File

@ -65,6 +65,7 @@ public class Packets{
public static class ConnectPacket implements Packet{ public static class ConnectPacket implements Packet{
public int version; public int version;
public String versionType; public String versionType;
public String mods;
public String name, uuid, usid; public String name, uuid, usid;
public boolean mobile; public boolean mobile;
public int color; public int color;
@ -73,6 +74,7 @@ public class Packets{
public void write(ByteBuffer buffer){ public void write(ByteBuffer buffer){
buffer.putInt(Version.build); buffer.putInt(Version.build);
TypeIO.writeString(buffer, versionType); TypeIO.writeString(buffer, versionType);
TypeIO.writeString(buffer, mods);
TypeIO.writeString(buffer, name); TypeIO.writeString(buffer, name);
TypeIO.writeString(buffer, usid); TypeIO.writeString(buffer, usid);
buffer.put(mobile ? (byte)1 : 0); buffer.put(mobile ? (byte)1 : 0);
@ -86,6 +88,7 @@ public class Packets{
versionType = TypeIO.readString(buffer); versionType = TypeIO.readString(buffer);
name = TypeIO.readString(buffer); name = TypeIO.readString(buffer);
usid = TypeIO.readString(buffer); usid = TypeIO.readString(buffer);
mods = TypeIO.readString(buffer);
mobile = buffer.get() == 1; mobile = buffer.get() == 1;
color = buffer.getInt(); color = buffer.getInt();
byte[] idbytes = new byte[8]; byte[] idbytes = new byte[8];

View File

@ -14,9 +14,8 @@ import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.ui.*; import io.anuke.mindustry.ui.*;
public class UnitType extends UnlockableContent{ public class UnitType extends UnlockableContent{
public final @NonNull public @NonNull TypeID typeID;
TypeID typeID; public @NonNull Supplier<? extends BaseUnit> constructor;
public final @NonNull Supplier<? extends BaseUnit> constructor;
public float health = 60; public float health = 60;
public float hitsize = 7f; public float hitsize = 7f;
@ -43,8 +42,17 @@ public class UnitType extends UnlockableContent{
public TextureRegion iconRegion, legRegion, baseRegion, region; public TextureRegion iconRegion, legRegion, baseRegion, region;
public <T extends BaseUnit> UnitType(String name, Class<T> type, Supplier<T> mainConstructor){ public <T extends BaseUnit> UnitType(String name, Supplier<T> mainConstructor){
this(name);
create(mainConstructor);
}
public <T extends BaseUnit> UnitType(String name){
super(name); super(name);
this.description = Core.bundle.getOrNull("unit." + name + ".description");
}
public <T extends BaseUnit> void create(Supplier<T> mainConstructor){
this.constructor = mainConstructor; this.constructor = mainConstructor;
this.description = Core.bundle.getOrNull("unit." + name + ".description"); this.description = Core.bundle.getOrNull("unit." + name + ".description");
this.typeID = new TypeID(name, mainConstructor); this.typeID = new TypeID(name, mainConstructor);

View File

@ -91,8 +91,8 @@ public class Minimap extends Table{
Element e = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true); Element e = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
if(e != null && e.isDescendantOf(this)){ if(e != null && e.isDescendantOf(this)){
Core.scene.setScrollFocus(this); requestScroll();
}else if(Core.scene.getScrollFocus() == this){ }else if(hasScroll()){
Core.scene.setScrollFocus(null); Core.scene.setScrollFocus(null);
} }
}); });

View File

@ -42,6 +42,8 @@ public class CustomRulesDialog extends FloatingDialog{
main.addButton("$settings.reset", () -> { main.addButton("$settings.reset", () -> {
rules = resetter.get(); rules = resetter.get();
setup(); setup();
requestKeyboard();
requestScroll();
}).size(300f, 50f); }).size(300f, 50f);
main.left().defaults().fillX().left().pad(5); main.left().defaults().fillX().left().pad(5);
main.row(); main.row();