mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-05 18:30:22 -08:00
Button for viewing content fields on wiki + More tests and fixes
This commit is contained in:
parent
c06c76d296
commit
3d4b432540
7 changed files with 96 additions and 2 deletions
|
|
@ -101,6 +101,7 @@ coreattack = < Core is under attack! >
|
||||||
nearpoint = [[ [scarlet]LEAVE DROP POINT IMMEDIATELY[] ]\nannihilation imminent
|
nearpoint = [[ [scarlet]LEAVE DROP POINT IMMEDIATELY[] ]\nannihilation imminent
|
||||||
database = Core Database
|
database = Core Database
|
||||||
database.button = Database
|
database.button = Database
|
||||||
|
viewfields = View Content Fields
|
||||||
savegame = Save Game
|
savegame = Save Game
|
||||||
loadgame = Load Game
|
loadgame = Load Game
|
||||||
joingame = Join Game
|
joingame = Join Game
|
||||||
|
|
|
||||||
|
|
@ -448,7 +448,7 @@ public class ContentParser{
|
||||||
T two = (T)Vars.content.getByName(ctype, jsonData.asString());
|
T two = (T)Vars.content.getByName(ctype, jsonData.asString());
|
||||||
|
|
||||||
if(two != null) return two;
|
if(two != null) return two;
|
||||||
throw new IllegalArgumentException("\"" + jsonData.name + "\": No " + ctype + " found with name '" + jsonData.asString() + "'.\nMake sure '" + jsonData.asString() + "' is spelled correctly, and that it really exists!\nThis may also occur because its file failed to parse.");
|
throw new IllegalArgumentException((jsonData.name == null ? "" : "\"" + jsonData.name + "\": ") + "No " + ctype + " found with name '" + jsonData.asString() + "'.\nMake sure '" + jsonData.asString() + "' is spelled correctly, and that it really exists!\nThis may also occur because its file failed to parse.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ public class ContentPatcher{
|
||||||
|
|
||||||
try{
|
try{
|
||||||
JsonValue value = parser.getJson().fromJson(null, Jval.read(patch).toString(Jformat.plain));
|
JsonValue value = parser.getJson().fromJson(null, Jval.read(patch).toString(Jformat.plain));
|
||||||
|
set.json = value;
|
||||||
currentlyApplying = set;
|
currentlyApplying = set;
|
||||||
|
|
||||||
set.name = value.getString("name", "");
|
set.name = value.getString("name", "");
|
||||||
|
|
@ -381,9 +382,13 @@ public class ContentPatcher{
|
||||||
}else{
|
}else{
|
||||||
//assign each field manually
|
//assign each field manually
|
||||||
var childFields = parser.getJson().getFields(prevValue.getClass().isAnonymousClass() ? prevValue.getClass().getSuperclass() : prevValue.getClass());
|
var childFields = parser.getJson().getFields(prevValue.getClass().isAnonymousClass() ? prevValue.getClass().getSuperclass() : prevValue.getClass());
|
||||||
|
|
||||||
for(var child : jsv){
|
for(var child : jsv){
|
||||||
if(child.name != null){
|
if(child.name != null){
|
||||||
assign(prevValue, child.name, child, !childFields.containsKey(child.name) ? null : new FieldData(childFields.get(child.name)), object, field);
|
assign(prevValue, child.name, child,
|
||||||
|
metadata != null && metadata.type == ObjectMap.class ? metadata :
|
||||||
|
!childFields.containsKey(child.name) ? null :
|
||||||
|
new FieldData(childFields.get(child.name)), object, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -541,6 +546,15 @@ public class ContentPatcher{
|
||||||
public FieldData(FieldMetadata data){
|
public FieldData(FieldMetadata data){
|
||||||
this(data.field.getType(), data.elementType, data.keyType);
|
this(data.field.getType(), data.elementType, data.keyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "FieldData{" +
|
||||||
|
"type=" + type +
|
||||||
|
", elementType=" + elementType +
|
||||||
|
", keyType=" + keyType +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PatchRecord{
|
private static class PatchRecord{
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import mindustry.ctype.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.input.*;
|
import mindustry.input.*;
|
||||||
|
import mindustry.ui.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
|
|
@ -93,6 +94,15 @@ public class ContentInfoDialog extends BaseDialog{
|
||||||
table.row();
|
table.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(settings.getBool("console")){
|
||||||
|
table.button("@viewfields", Icon.link, Styles.grayt, () -> {
|
||||||
|
Class<?> contentClass = content.getClass();
|
||||||
|
if(contentClass.isAnonymousClass()) contentClass = contentClass.getSuperclass();
|
||||||
|
|
||||||
|
Core.app.openURI("https://mindustrygame.github.io/wiki/Modding%20Classes/" + contentClass.getSimpleName());
|
||||||
|
}).margin(8f).pad(4f).size(300f, 50f).row();
|
||||||
|
}
|
||||||
|
|
||||||
content.displayExtra(table);
|
content.displayExtra(table);
|
||||||
|
|
||||||
ScrollPane pane = new ScrollPane(table);
|
ScrollPane pane = new ScrollPane(table);
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ public class Block extends UnlockableContent implements Senseable{
|
||||||
/** if true, {@link #buildEditorConfig(Table)} will be called for configuring this block in the editor. */
|
/** if true, {@link #buildEditorConfig(Table)} will be called for configuring this block in the editor. */
|
||||||
public boolean editorConfigurable;
|
public boolean editorConfigurable;
|
||||||
/** the last configuration value applied to this block. */
|
/** the last configuration value applied to this block. */
|
||||||
|
@NoPatch
|
||||||
public @Nullable Object lastConfig;
|
public @Nullable Object lastConfig;
|
||||||
/** whether to save the last config and apply it to newly placed blocks */
|
/** whether to save the last config and apply it to newly placed blocks */
|
||||||
public boolean saveConfig = false;
|
public boolean saveConfig = false;
|
||||||
|
|
|
||||||
|
|
@ -467,6 +467,13 @@ public class ServerControl implements ApplicationListener{
|
||||||
info("Map directory: &fi@", customMapDirectory.file().getAbsoluteFile().toString());
|
info("Map directory: &fi@", customMapDirectory.file().getAbsoluteFile().toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.register("reloadpatches", "Reload all patch files from disk.", arg -> {
|
||||||
|
loadPatchFiles();
|
||||||
|
if(contentPatches.isEmpty()){
|
||||||
|
err("No valid content patch files found.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
handler.register("reloadmaps", "Reload all maps from disk.", arg -> {
|
handler.register("reloadmaps", "Reload all maps from disk.", arg -> {
|
||||||
int beforeMaps = maps.all().size;
|
int beforeMaps = maps.all().size;
|
||||||
maps.reload();
|
maps.reload();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import mindustry.entities.abilities.*;
|
||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
import mindustry.world.blocks.defense.turrets.*;
|
||||||
import mindustry.world.blocks.units.*;
|
import mindustry.world.blocks.units.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
@ -296,6 +297,66 @@ public class PatcherTests{
|
||||||
assertFalse(UnitTypes.dagger.immunities.contains(StatusEffects.fast));
|
assertFalse(UnitTypes.dagger.immunities.contains(StatusEffects.fast));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAmmoReassign() throws Exception{
|
||||||
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
block.fuse.ammoTypes: {
|
||||||
|
titanium: "-"
|
||||||
|
surge-alloy: {
|
||||||
|
type: LaserBulletType
|
||||||
|
ammoMultiplier: 1
|
||||||
|
reloadMultiplier: 0.5
|
||||||
|
damage: 100
|
||||||
|
colors: ["000000", "ff0000", "ffffff"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""));
|
||||||
|
|
||||||
|
assertEquals(new Seq<>(), Vars.state.patcher.patches.first().warnings);
|
||||||
|
assertTrue(((ItemTurret)Blocks.fuse).ammoTypes.containsKey(Items.surgeAlloy));
|
||||||
|
assertFalse(((ItemTurret)Blocks.fuse).ammoTypes.containsKey(Items.titanium));
|
||||||
|
assertEquals(100, ((ItemTurret)Blocks.fuse).ammoTypes.get(Items.surgeAlloy).damage);
|
||||||
|
|
||||||
|
Vars.logic.reset();
|
||||||
|
|
||||||
|
assertFalse(((ItemTurret)Blocks.fuse).ammoTypes.containsKey(Items.surgeAlloy));
|
||||||
|
assertTrue(((ItemTurret)Blocks.fuse).ammoTypes.containsKey(Items.titanium));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIndexAccess() throws Exception{
|
||||||
|
float oldDamage = UnitTypes.dagger.weapons.first().bullet.damage;
|
||||||
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
unit.dagger.weapons.0.bullet.damage: 100
|
||||||
|
"""));
|
||||||
|
|
||||||
|
assertEquals(new Seq<>(), Vars.state.patcher.patches.first().warnings);
|
||||||
|
assertEquals(100, UnitTypes.dagger.weapons.first().bullet.damage);
|
||||||
|
|
||||||
|
Vars.logic.reset();
|
||||||
|
|
||||||
|
assertEquals(oldDamage, UnitTypes.dagger.weapons.first().bullet.damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddWeapon() throws Exception{
|
||||||
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
unit.flare.weapons.+: {
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
reload: 10
|
||||||
|
bullet: {
|
||||||
|
type: LaserBulletType
|
||||||
|
damage: 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""));
|
||||||
|
|
||||||
|
assertEquals(new Seq<>(), Vars.state.patcher.patches.first().warnings);
|
||||||
|
assertEquals(3, UnitTypes.flare.weapons.size);
|
||||||
|
assertEquals(100, UnitTypes.flare.weapons.peek().bullet.damage);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBigPatch() throws Exception{
|
void testBigPatch() throws Exception{
|
||||||
Vars.state.patcher.apply(Seq.with("""
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue