Cleanup / Added server support for scripting
This commit is contained in:
@@ -42,11 +42,6 @@ public abstract class UnlockableContent extends MappableContent{
|
|||||||
return cicons[icon.ordinal()];
|
return cicons[icon.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the localized name of this content. */
|
|
||||||
public abstract String localizedName();
|
|
||||||
|
|
||||||
//public abstract TextureRegion getContentIcon();
|
|
||||||
|
|
||||||
/** This should show all necessary info about this content in the specified table. */
|
/** This should show all necessary info about this content in the specified table. */
|
||||||
public abstract void displayInfo(Table table);
|
public abstract void displayInfo(Table table);
|
||||||
|
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ public class Mods implements Loadable{
|
|||||||
if(mod.root.child("scripts").exists()){
|
if(mod.root.child("scripts").exists()){
|
||||||
content.setCurrentMod(mod);
|
content.setCurrentMod(mod);
|
||||||
mod.scripts = mod.root.child("scripts").findAll(f -> f.extension().equals("js"));
|
mod.scripts = mod.root.child("scripts").findAll(f -> f.extension().equals("js"));
|
||||||
Log.info("[{0}] Found {1} scripts.", mod.meta.name, mod.scripts.size);
|
Log.debug("[{0}] Found {1} scripts.", mod.meta.name, mod.scripts.size);
|
||||||
|
|
||||||
for(FileHandle file : mod.scripts){
|
for(FileHandle file : mod.scripts){
|
||||||
try{
|
try{
|
||||||
@@ -415,7 +415,7 @@ public class Mods implements Loadable{
|
|||||||
content.setCurrentMod(null);
|
content.setCurrentMod(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info("Time to initialize modded scripts: {0}", Time.elapsed());
|
Log.debug("Time to initialize modded scripts: {0}", Time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates all the content found in mod files. */
|
/** Creates all the content found in mod files. */
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Scripts implements Disposable{
|
|||||||
wrapper = Core.files.internal("scripts/wrapper.js").readString();
|
wrapper = Core.files.internal("scripts/wrapper.js").readString();
|
||||||
|
|
||||||
run(Core.files.internal("scripts/global.js").readString(), "global.js");
|
run(Core.files.internal("scripts/global.js").readString(), "global.js");
|
||||||
Log.info("Time to load script engine: {0}", Time.elapsed());
|
Log.debug("Time to load script engine: {0}", Time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String runConsole(String text){
|
public String runConsole(String text){
|
||||||
@@ -52,7 +52,7 @@ public class Scripts implements Disposable{
|
|||||||
public void log(String source, String message){
|
public void log(String source, String message){
|
||||||
Log.info("[{0}]: {1}", source, message);
|
Log.info("[{0}]: {1}", source, message);
|
||||||
logBuffer.add("[accent][" + source + "]:[] " + message);
|
logBuffer.add("[accent][" + source + "]:[] " + message);
|
||||||
if(!headless & ui.scriptfrag != null){
|
if(!headless && ui.scriptfrag != null){
|
||||||
onLoad();
|
onLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package io.anuke.mindustry.type;
|
package io.anuke.mindustry.type;
|
||||||
|
|
||||||
import io.anuke.arc.*;
|
|
||||||
import io.anuke.arc.collection.*;
|
import io.anuke.arc.collection.*;
|
||||||
import io.anuke.arc.graphics.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.scene.ui.layout.*;
|
import io.anuke.arc.scene.ui.layout.*;
|
||||||
import io.anuke.mindustry.ctype.UnlockableContent;
|
import io.anuke.mindustry.ctype.*;
|
||||||
import io.anuke.mindustry.ui.*;
|
import io.anuke.mindustry.ui.*;
|
||||||
import io.anuke.mindustry.world.blocks.*;
|
import io.anuke.mindustry.world.blocks.*;
|
||||||
|
|
||||||
@@ -50,14 +49,9 @@ public class Item extends UnlockableContent{
|
|||||||
ContentDisplay.displayItem(table, this);
|
ContentDisplay.displayItem(table, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localizedName(){
|
|
||||||
return Core.bundle.get("item." + this.name + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return localizedName();
|
return localizedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package io.anuke.mindustry.type;
|
package io.anuke.mindustry.type;
|
||||||
|
|
||||||
import io.anuke.arc.*;
|
|
||||||
import io.anuke.arc.graphics.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.scene.ui.layout.*;
|
import io.anuke.arc.scene.ui.layout.*;
|
||||||
import io.anuke.arc.util.ArcAnnotate.*;
|
import io.anuke.arc.util.ArcAnnotate.*;
|
||||||
import io.anuke.mindustry.content.*;
|
import io.anuke.mindustry.content.*;
|
||||||
import io.anuke.mindustry.ctype.UnlockableContent;
|
import io.anuke.mindustry.ctype.*;
|
||||||
import io.anuke.mindustry.ui.*;
|
import io.anuke.mindustry.ui.*;
|
||||||
|
|
||||||
public class Liquid extends UnlockableContent{
|
public class Liquid extends UnlockableContent{
|
||||||
@@ -51,14 +50,9 @@ public class Liquid extends UnlockableContent{
|
|||||||
ContentDisplay.displayLiquid(table, this);
|
ContentDisplay.displayLiquid(table, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localizedName(){
|
|
||||||
return Core.bundle.get("liquid." + this.name + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return localizedName();
|
return localizedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ public class Mech extends UnlockableContent{
|
|||||||
this(name, false);
|
this(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String localizedName(){
|
|
||||||
return Core.bundle.get("mech." + name + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAlt(Player player){
|
public void updateAlt(Player player){
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +108,6 @@ public class Mech extends UnlockableContent{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return localizedName();
|
return localizedName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,11 +64,6 @@ public class UnitType extends UnlockableContent{
|
|||||||
ContentDisplay.displayUnit(table, this);
|
ContentDisplay.displayUnit(table, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localizedName(){
|
|
||||||
return Core.bundle.get("unit." + name + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
weapon.load();
|
weapon.load();
|
||||||
|
|||||||
@@ -205,11 +205,6 @@ public class Zone extends UnlockableContent{
|
|||||||
public void displayInfo(Table table){
|
public void displayInfo(Table table){
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localizedName(){
|
|
||||||
return Core.bundle.get("zone." + name + ".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContentType getContentType(){
|
public ContentType getContentType(){
|
||||||
return ContentType.zone;
|
return ContentType.zone;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class ContentDisplay{
|
|||||||
|
|
||||||
table.table(title -> {
|
table.table(title -> {
|
||||||
title.addImage(item.icon(Cicon.xlarge)).size(8 * 6);
|
title.addImage(item.icon(Cicon.xlarge)).size(8 * 6);
|
||||||
title.add("[accent]" + item.localizedName()).padLeft(5);
|
title.add("[accent]" + item.localizedName).padLeft(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
table.row();
|
table.row();
|
||||||
@@ -100,7 +100,7 @@ public class ContentDisplay{
|
|||||||
|
|
||||||
table.table(title -> {
|
table.table(title -> {
|
||||||
title.addImage(liquid.icon(Cicon.xlarge)).size(8 * 6);
|
title.addImage(liquid.icon(Cicon.xlarge)).size(8 * 6);
|
||||||
title.add("[accent]" + liquid.localizedName()).padLeft(5);
|
title.add("[accent]" + liquid.localizedName).padLeft(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
table.row();
|
table.row();
|
||||||
@@ -134,7 +134,7 @@ public class ContentDisplay{
|
|||||||
public static void displayMech(Table table, Mech mech){
|
public static void displayMech(Table table, Mech mech){
|
||||||
table.table(title -> {
|
table.table(title -> {
|
||||||
title.addImage(mech.icon(Cicon.xlarge)).size(8 * 6);
|
title.addImage(mech.icon(Cicon.xlarge)).size(8 * 6);
|
||||||
title.add("[accent]" + mech.localizedName()).padLeft(5);
|
title.add("[accent]" + mech.localizedName).padLeft(5);
|
||||||
});
|
});
|
||||||
table.left().defaults().left();
|
table.left().defaults().left();
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ public class ContentDisplay{
|
|||||||
public static void displayUnit(Table table, UnitType unit){
|
public static void displayUnit(Table table, UnitType unit){
|
||||||
table.table(title -> {
|
table.table(title -> {
|
||||||
title.addImage(unit.icon(Cicon.xlarge)).size(8 * 6);
|
title.addImage(unit.icon(Cicon.xlarge)).size(8 * 6);
|
||||||
title.add("[accent]" + unit.localizedName()).padLeft(5);
|
title.add("[accent]" + unit.localizedName).padLeft(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
table.row();
|
table.row();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class ItemDisplay extends Table{
|
|||||||
|
|
||||||
public ItemDisplay(Item item, int amount, boolean showName){
|
public ItemDisplay(Item item, int amount, boolean showName){
|
||||||
add(new ItemImage(new ItemStack(item, amount))).size(8 * 4).padRight(amount > 99 ? 12 : 0);
|
add(new ItemImage(new ItemStack(item, amount))).size(8 * 4).padRight(amount > 99 ? 12 : 0);
|
||||||
if(showName) add(item.localizedName()).padLeft(4 + amount > 99 ? 4 : 0);
|
if(showName) add(item.localizedName).padLeft(4 + amount > 99 ? 4 : 0);
|
||||||
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class ItemsDisplay extends Table{
|
|||||||
if(item.type == ItemType.material && data.isUnlocked(item)){
|
if(item.type == ItemType.material && data.isUnlocked(item)){
|
||||||
t.label(() -> format(item)).left();
|
t.label(() -> format(item)).left();
|
||||||
t.addImage(item.icon(Cicon.small)).size(8 * 3).padLeft(4).padRight(4);
|
t.addImage(item.icon(Cicon.small)).size(8 * 3).padLeft(4).padRight(4);
|
||||||
t.add(item.localizedName()).color(Color.lightGray).left();
|
t.add(item.localizedName).color(Color.lightGray).left();
|
||||||
t.row();
|
t.row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ public class LiquidDisplay extends Table{
|
|||||||
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.lightGray);
|
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.lightGray);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(liquid.localizedName());
|
add(liquid.localizedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class DatabaseDialog extends FloatingDialog{
|
|||||||
|
|
||||||
if(unlocked(unlock)){
|
if(unlocked(unlock)){
|
||||||
image.clicked(() -> Vars.ui.content.show(unlock));
|
image.clicked(() -> Vars.ui.content.show(unlock));
|
||||||
image.addListener(new Tooltip(t -> t.background(Tex.button).add(unlock.localizedName())));
|
image.addListener(new Tooltip(t -> t.background(Tex.button).add(unlock.localizedName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if((++count) % maxWidth == 0){
|
if((++count) % maxWidth == 0){
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
}).color(Color.darkGray).grow()));
|
}).color(Color.darkGray).grow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TextButton button = Elements.newButton(Core.bundle.format("resume", slot.getZone().localizedName()), Styles.squaret, () -> {
|
TextButton button = Elements.newButton(Core.bundle.format("resume", slot.getZone().localizedName), Styles.squaret, () -> {
|
||||||
control.saves.getZoneSlot().cautiousLoad(() -> {
|
control.saves.getZoneSlot().cautiousLoad(() -> {
|
||||||
hide();
|
hide();
|
||||||
ui.loadAnd(() -> {
|
ui.loadAnd(() -> {
|
||||||
@@ -232,7 +232,7 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(zone.unlocked() && !hidden(zone)){
|
if(zone.unlocked() && !hidden(zone)){
|
||||||
button.labelWrap(zone.localizedName()).style(Styles.outlineLabel).width(140).growX().get().setAlignment(Align.center);
|
button.labelWrap(zone.localizedName).style(Styles.outlineLabel).width(140).growX().get().setAlignment(Align.center);
|
||||||
}else{
|
}else{
|
||||||
Cons<Element> flasher = zone.canUnlock() && !hidden(zone) ? e -> e.update(() -> e.getColor().set(Color.white).lerp(Pal.accent, Mathf.absin(3f, 1f))) : e -> {};
|
Cons<Element> flasher = zone.canUnlock() && !hidden(zone) ? e -> e.update(() -> e.getColor().set(Color.white).lerp(Pal.accent, Mathf.absin(3f, 1f))) : e -> {};
|
||||||
flasher.get(button.addImage(Icon.locked).get());
|
flasher.get(button.addImage(Icon.locked).get());
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
t.table(list -> {
|
t.table(list -> {
|
||||||
list.left();
|
list.left();
|
||||||
list.addImage(req.item.icon(Cicon.small)).size(8 * 3).padRight(3);
|
list.addImage(req.item.icon(Cicon.small)).size(8 * 3).padRight(3);
|
||||||
list.add(req.item.localizedName()).color(Color.lightGray);
|
list.add(req.item.localizedName).color(Color.lightGray);
|
||||||
list.label(() -> " " + Math.min(data.getItem(req.item), req.amount) + " / " + req.amount)
|
list.label(() -> " " + Math.min(data.getItem(req.item), req.amount) + " / " + req.amount)
|
||||||
.update(l -> l.setColor(data.has(req.item, req.amount) ? Color.lightGray : Color.scarlet));
|
.update(l -> l.setColor(data.has(req.item, req.amount) ? Color.lightGray : Color.scarlet));
|
||||||
}).fillX().left();
|
}).fillX().left();
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class ZoneInfoDialog extends FloatingDialog{
|
|||||||
}).growX();
|
}).growX();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
cont.add(zone.localizedName()).color(Pal.accent).growX().center();
|
cont.add(zone.localizedName).color(Pal.accent).growX().center();
|
||||||
cont.row();
|
cont.row();
|
||||||
cont.addImage().color(Pal.accent).height(3).pad(6).growX();
|
cont.addImage().color(Pal.accent).height(3).pad(6).growX();
|
||||||
cont.row();
|
cont.row();
|
||||||
|
|||||||
@@ -395,11 +395,6 @@ public class Block extends BlockStorage{
|
|||||||
return sum / size / size;
|
return sum / size / size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localizedName(){
|
|
||||||
return localizedName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayInfo(Table table){
|
public void displayInfo(Table table){
|
||||||
ContentDisplay.displayBlock(table, this);
|
ContentDisplay.displayBlock(table, this);
|
||||||
@@ -552,7 +547,7 @@ public class Block extends BlockStorage{
|
|||||||
}else{
|
}else{
|
||||||
current = entity -> entity.liquids.current();
|
current = entity -> entity.liquids.current();
|
||||||
}
|
}
|
||||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName(),
|
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName,
|
||||||
() -> current.get(entity).barColor(), () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
() -> current.get(entity).barColor(), () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class OreBlock extends OverlayFloor{
|
|||||||
|
|
||||||
public OreBlock(Item ore){
|
public OreBlock(Item ore){
|
||||||
super("ore-" + ore.name);
|
super("ore-" + ore.name);
|
||||||
this.localizedName = ore.localizedName();
|
this.localizedName = ore.localizedName;
|
||||||
this.itemDrop = ore;
|
this.itemDrop = ore;
|
||||||
this.variants = 3;
|
this.variants = 3;
|
||||||
this.color.set(ore.color);
|
this.color.set(ore.color);
|
||||||
@@ -29,7 +29,7 @@ public class OreBlock extends OverlayFloor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setup(Item ore){
|
public void setup(Item ore){
|
||||||
this.localizedName = ore.localizedName();
|
this.localizedName = ore.localizedName;
|
||||||
this.itemDrop = ore;
|
this.itemDrop = ore;
|
||||||
this.color.set(ore.color);
|
this.color.set(ore.color);
|
||||||
}
|
}
|
||||||
@@ -80,6 +80,6 @@ public class OreBlock extends OverlayFloor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(Tile tile){
|
public String getDisplayName(Tile tile){
|
||||||
return itemDrop.localizedName();
|
return itemDrop.localizedName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class Drill extends Block{
|
|||||||
Item item = list.get(i);
|
Item item = list.get(i);
|
||||||
|
|
||||||
table.addImage(Core.atlas.find(item.name + "1")).size(8 * 3).padRight(2).padLeft(2).padTop(3).padBottom(3);
|
table.addImage(Core.atlas.find(item.name + "1")).size(8 * 3).padRight(2).padLeft(2).padTop(3).padBottom(3);
|
||||||
table.add(item.localizedName());
|
table.add(item.localizedName);
|
||||||
if(i != list.size - 1){
|
if(i != list.size - 1){
|
||||||
table.add("/").padLeft(5).padRight(5);
|
table.add("/").padLeft(5).padRight(5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class AmmoListValue<T extends UnlockableContent> implements StatValue{
|
|||||||
for(T t : map.keys()){
|
for(T t : map.keys()){
|
||||||
BulletType type = map.get(t);
|
BulletType type = map.get(t);
|
||||||
table.addImage(icon(t)).size(3 * 8).padRight(4).right().top();
|
table.addImage(icon(t)).size(3 * 8).padRight(4).right().top();
|
||||||
table.add(t.localizedName()).padRight(10).left().top();
|
table.add(t.localizedName).padRight(10).left().top();
|
||||||
table.table(Tex.underline, bt -> {
|
table.table(Tex.underline, bt -> {
|
||||||
bt.left().defaults().padRight(3).left();
|
bt.left().defaults().padRight(3).left();
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class BoosterListValue implements StatValue{
|
|||||||
if(!filter.get(liquid)) continue;
|
if(!filter.get(liquid)) continue;
|
||||||
|
|
||||||
c.addImage(liquid.icon(Cicon.medium)).size(3 * 8).padRight(4).right().top();
|
c.addImage(liquid.icon(Cicon.medium)).size(3 * 8).padRight(4).right().top();
|
||||||
c.add(liquid.localizedName()).padRight(10).left().top();
|
c.add(liquid.localizedName).padRight(10).left().top();
|
||||||
c.table(Tex.underline, bt -> {
|
c.table(Tex.underline, bt -> {
|
||||||
bt.left().defaults().padRight(3).left();
|
bt.left().defaults().padRight(3).left();
|
||||||
|
|
||||||
|
|||||||
@@ -357,6 +357,10 @@ public class ServerControl implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.register("js", "<script...>", "Run arbitrary Javascript.", arg -> {
|
||||||
|
info("&lc" + mods.getScripts().runConsole(arg[0]));
|
||||||
|
});
|
||||||
|
|
||||||
handler.register("say", "<message...>", "Send a message to all players.", arg -> {
|
handler.register("say", "<message...>", "Send a message to all players.", arg -> {
|
||||||
if(!state.is(State.playing)){
|
if(!state.is(State.playing)){
|
||||||
err("Not hosting. Host a game first.");
|
err("Not hosting. Host a game first.");
|
||||||
|
|||||||
Reference in New Issue
Block a user