Merge
This commit is contained in:
@@ -1132,13 +1132,13 @@ public class Blocks implements ContentList{
|
||||
differentialGenerator = new SingleTypeGenerator("differential-generator"){{
|
||||
requirements(Category.power, ItemStack.with(Items.copper, 70, Items.titanium, 50, Items.lead, 100, Items.silicon, 65, Items.metaglass, 50));
|
||||
powerProduction = 16f;
|
||||
itemDuration = 120f;
|
||||
itemDuration = 140f;
|
||||
hasLiquids = true;
|
||||
hasItems = true;
|
||||
size = 3;
|
||||
|
||||
consumes.item(Items.pyratite).optional(true, false);
|
||||
consumes.liquid(Liquids.cryofluid, 0.18f);
|
||||
consumes.liquid(Liquids.cryofluid, 0.15f);
|
||||
}};
|
||||
|
||||
rtgGenerator = new DecayGenerator("rtg-generator"){{
|
||||
|
||||
@@ -255,34 +255,62 @@ public class NetClient implements ApplicationListener{
|
||||
ui.loadfrag.hide();
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void setHudText(String message){
|
||||
if(message == null) return;
|
||||
|
||||
ui.hudfrag.setHudText(message);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void hideHudText(){
|
||||
ui.hudfrag.toggleHudText(false);
|
||||
}
|
||||
|
||||
/** TCP version */
|
||||
@Remote(variants = Variant.both)
|
||||
public static void setHudTextReliable(String message){
|
||||
setHudText(message);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void onInfoMessage(String message){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showText("", message);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void onInfoPopup(String message, float duration, int align, int top, int left, int bottom, int right){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showInfoPopup(message, duration, align, top, left, bottom, right);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void onLabel(String info, float duration, float worldx, float worldy){
|
||||
ui.showLabel(info, duration, worldx, worldy);
|
||||
public static void onLabel(String message, float duration, float worldx, float worldy){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showLabel(message, duration, worldx, worldy);
|
||||
}
|
||||
|
||||
/*
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void onEffect(Effect effect, float x, float y, float rotation, Color color){
|
||||
if(effect == null) return;
|
||||
|
||||
effect.at(x, y, rotation, color);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void onEffectReliable(Effect effect, float x, float y, float rotation, Color color){
|
||||
effect.at(x, y, rotation, color);
|
||||
onEffect(effect, x, y, rotation, color);
|
||||
}*/
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void onInfoToast(String message, float duration){
|
||||
if(message == null) return;
|
||||
|
||||
ui.showInfoToast(message, duration);
|
||||
}
|
||||
|
||||
@@ -529,6 +557,11 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
|
||||
String getUsid(String ip){
|
||||
//consistently use the latter part of an IP, if possible
|
||||
if(ip.contains("/")){
|
||||
ip = ip.substring(ip.indexOf("/") + 1);
|
||||
}
|
||||
|
||||
if(Core.settings.getString("usid-" + ip, null) != null){
|
||||
return Core.settings.getString("usid-" + ip, null);
|
||||
}else{
|
||||
|
||||
@@ -8,6 +8,7 @@ import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.CommandHandler.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.serialization.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.entities.units.*;
|
||||
@@ -88,6 +89,16 @@ public class NetServer implements ApplicationListener{
|
||||
}
|
||||
|
||||
String uuid = packet.uuid;
|
||||
byte[] buuid = Base64Coder.decode(uuid);
|
||||
CRC32 crc = new CRC32();
|
||||
crc.update(buuid, 0, 8);
|
||||
ByteBuffer buff = ByteBuffer.allocate(8);
|
||||
buff.put(buuid, 8, 8);
|
||||
buff.position(0);
|
||||
if(crc.getValue() != buff.getLong()){
|
||||
con.kick(KickReason.clientOutdated);
|
||||
return;
|
||||
}
|
||||
|
||||
if(admins.isIPBanned(con.address) || admins.isSubnetBanned(con.address)) return;
|
||||
|
||||
@@ -116,7 +127,7 @@ public class NetServer implements ApplicationListener{
|
||||
return;
|
||||
}
|
||||
|
||||
if(admins.getPlayerLimit() > 0 && Groups.player.size() >= admins.getPlayerLimit()){
|
||||
if(admins.getPlayerLimit() > 0 && Groups.player.size() >= admins.getPlayerLimit() && !netServer.admins.isAdmin(uuid, packet.usid)){
|
||||
con.kick(KickReason.playerLimit);
|
||||
return;
|
||||
}
|
||||
@@ -197,6 +208,11 @@ public class NetServer implements ApplicationListener{
|
||||
player.name(packet.name);
|
||||
player.color().set(packet.color).a(1f);
|
||||
|
||||
//save admin ID but don't overwrite it
|
||||
if(!player.admin() && !info.admin){
|
||||
info.adminUsid = packet.usid;
|
||||
}
|
||||
|
||||
try{
|
||||
writeBuffer.position(0);
|
||||
player.write(outputBuffer);
|
||||
|
||||
@@ -317,7 +317,7 @@ public class Mods implements Loadable{
|
||||
return result;
|
||||
}
|
||||
|
||||
private LoadedMod locateMod(String name){
|
||||
public LoadedMod locateMod(String name){
|
||||
return mods.find(mod -> mod.enabled() && mod.name.equals(name));
|
||||
}
|
||||
|
||||
@@ -460,22 +460,25 @@ public class Mods implements Loadable{
|
||||
eachEnabled(mod -> {
|
||||
if(mod.root.child("scripts").exists()){
|
||||
content.setCurrentMod(mod);
|
||||
mod.scripts = mod.root.child("scripts").findAll(f -> f.extension().equals("js"));
|
||||
Log.debug("[{0}] Found {1} scripts.", mod.meta.name, mod.scripts.size);
|
||||
|
||||
for(Fi file : mod.scripts){
|
||||
//if there's only one script file, use it (for backwards compatibility); if there isn't, use "main.js"
|
||||
Array<Fi> allScripts = mod.root.child("scripts").findAll(f -> f.extEquals("js"));
|
||||
Fi main = allScripts.size == 1 ? allScripts.first() : mod.root.child("scripts").child("main.js");
|
||||
if(main.exists() && !main.isDirectory()){
|
||||
try{
|
||||
if(scripts == null){
|
||||
scripts = platform.createScripts();
|
||||
}
|
||||
scripts.run(mod, file);
|
||||
scripts.run(mod, main);
|
||||
}catch(Throwable e){
|
||||
Core.app.post(() -> {
|
||||
Log.err("Error loading script {0} for mod {1}.", file.name(), mod.meta.name);
|
||||
Log.err("Error loading main script {0} for mod {1}.", main.name(), mod.meta.name);
|
||||
e.printStackTrace();
|
||||
});
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
Core.app.post(() -> {
|
||||
Log.err("No main.js found for mod {0}.", mod.meta.name);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,6 +8,12 @@ import arc.util.Log.*;
|
||||
import mindustry.*;
|
||||
import mindustry.mod.Mods.*;
|
||||
import org.mozilla.javascript.*;
|
||||
import org.mozilla.javascript.commonjs.module.*;
|
||||
import org.mozilla.javascript.commonjs.module.provider.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Scripts implements Disposable{
|
||||
private final Array<String> blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk",
|
||||
@@ -15,9 +21,9 @@ public class Scripts implements Disposable{
|
||||
".awt", "socket", "classloader", "oracle", "invoke");
|
||||
private final Array<String> whitelist = Array.with("mindustry.net");
|
||||
private final Context context;
|
||||
private final String wrapper;
|
||||
private Scriptable scope;
|
||||
private boolean errored;
|
||||
private LoadedMod currentMod = null;
|
||||
|
||||
public Scripts(){
|
||||
Time.mark();
|
||||
@@ -25,9 +31,12 @@ public class Scripts implements Disposable{
|
||||
context = Vars.platform.getScriptContext();
|
||||
context.setClassShutter(type -> !blacklist.contains(type.toLowerCase()::contains) || whitelist.contains(type.toLowerCase()::contains));
|
||||
context.getWrapFactory().setJavaPrimitiveWrap(false);
|
||||
|
||||
|
||||
scope = new ImporterTopLevel(context);
|
||||
wrapper = Core.files.internal("scripts/wrapper.js").readString();
|
||||
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(new ScriptModuleProvider()))
|
||||
.setSandboxed(true).createRequire(context, scope).install(scope);
|
||||
|
||||
if(!run(Core.files.internal("scripts/global.js").readString(), "global.js")){
|
||||
errored = true;
|
||||
@@ -68,11 +77,17 @@ public class Scripts implements Disposable{
|
||||
}
|
||||
|
||||
public void run(LoadedMod mod, Fi file){
|
||||
run(wrapper.replace("$SCRIPT_NAME$", mod.name + "/" + file.nameWithoutExtension()).replace("$CODE$", file.readString()).replace("$MOD_NAME$", mod.name), file.name());
|
||||
currentMod = mod;
|
||||
run(file.readString(), file.name());
|
||||
currentMod = null;
|
||||
}
|
||||
|
||||
private boolean run(String script, String file){
|
||||
try{
|
||||
if(currentMod != null){
|
||||
//inject script info into file (TODO maybe rhino handles this?)
|
||||
context.evaluateString(scope, "modName = \"" + currentMod.name + "\"\nscriptName = \"" + file + "\"", "initscript.js", 1, null);
|
||||
}
|
||||
context.evaluateString(scope, script, file, 1, null);
|
||||
return true;
|
||||
}catch(Throwable t){
|
||||
@@ -85,4 +100,38 @@ public class Scripts implements Disposable{
|
||||
public void dispose(){
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
private class ScriptModuleProvider extends UrlModuleSourceProvider{
|
||||
private Pattern directory = Pattern.compile("^(.+?)/(.+)");
|
||||
|
||||
public ScriptModuleProvider(){
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleSource loadSource(String moduleId, Scriptable paths, Object validator) throws IOException, URISyntaxException{
|
||||
if(currentMod == null) return null;
|
||||
return loadSource(moduleId, currentMod.root.child("scripts"), validator);
|
||||
}
|
||||
|
||||
private ModuleSource loadSource(String moduleId, Fi root, Object validator) throws URISyntaxException{
|
||||
Matcher matched = directory.matcher(moduleId);
|
||||
if(matched.find()){
|
||||
LoadedMod required = Vars.mods.locateMod(matched.group(1));
|
||||
String script = matched.group(2);
|
||||
if(required == null || root.equals(required.root.child("scripts"))){ // Mod not found, or already using a mod
|
||||
Fi dir = root.child(matched.group(1));
|
||||
if(!dir.exists()) return null; // Mod and folder not found
|
||||
return loadSource(script, dir, validator);
|
||||
}
|
||||
return loadSource(script, required.root.child("scripts"), validator);
|
||||
}
|
||||
|
||||
Fi module = root.child(moduleId + ".js");
|
||||
if(!module.exists() || module.isDirectory()) return null;
|
||||
return new ModuleSource(
|
||||
new InputStreamReader(new ByteArrayInputStream((module.readString()).getBytes())),
|
||||
null, new URI(moduleId), root.file().toURI(), validator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class Packets{
|
||||
usid = TypeIO.readString(buffer);
|
||||
mobile = buffer.get() == 1;
|
||||
color = buffer.getInt();
|
||||
byte[] idbytes = new byte[8];
|
||||
byte[] idbytes = new byte[16];
|
||||
buffer.get(idbytes);
|
||||
uuid = new String(Base64Coder.encode(idbytes));
|
||||
int totalMods = buffer.get();
|
||||
|
||||
@@ -35,6 +35,9 @@ public class HudFragment extends Fragment{
|
||||
private boolean shown = true;
|
||||
private float dsize = 47.2f;
|
||||
|
||||
private String hudText = "";
|
||||
private boolean showHudText;
|
||||
|
||||
private long lastToast;
|
||||
|
||||
public void build(Group parent){
|
||||
@@ -280,6 +283,19 @@ public class HudFragment extends Fragment{
|
||||
t.add("$saveload").style(Styles.outlineLabel);
|
||||
});
|
||||
|
||||
parent.fill(p -> {
|
||||
p.top().table(Styles.black3, t -> t.margin(4).label(() -> hudText)
|
||||
.style(Styles.outlineLabel)).padTop(10).visible(p.color.a >= 0.001f);
|
||||
p.update(() -> {
|
||||
p.color.a = Mathf.lerpDelta(p.color.a, Mathf.num(showHudText), 0.2f);
|
||||
if(state.is(State.menu)){
|
||||
p.color.a = 0f;
|
||||
showHudText = false;
|
||||
}
|
||||
});
|
||||
p.touchable(Touchable.disabled);
|
||||
});
|
||||
|
||||
blockfrag.build(parent);
|
||||
}
|
||||
|
||||
@@ -290,6 +306,15 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
}
|
||||
|
||||
public void setHudText(String text){
|
||||
showHudText = true;
|
||||
hudText = text;
|
||||
}
|
||||
|
||||
public void toggleHudText(boolean shown){
|
||||
showHudText = shown;
|
||||
}
|
||||
|
||||
private void scheduleToast(Runnable run){
|
||||
long duration = (int)(3.5 * 1000);
|
||||
long since = Time.timeSinceMillis(lastToast);
|
||||
|
||||
@@ -84,7 +84,7 @@ public interface Autotiler{
|
||||
default boolean blends(Tile tile, int rotation, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(rotation - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
return other != null && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
return other != null && other.team() == tile.team() && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
}
|
||||
|
||||
default boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemSelection{
|
||||
private static float scrollPos = 0f;
|
||||
|
||||
public static void buildItemTable(Table table, Prov<Item> holder, Cons<Item> consumer){
|
||||
|
||||
Array<Item> items = content.items();
|
||||
public static <T extends UnlockableContent> void buildTable(Table table, Array<T> items, Prov<T> holder, Cons<T> consumer){
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(38);
|
||||
cont.defaults().size(40);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(Item item : items){
|
||||
for(T item : items){
|
||||
if(!data.isUnlocked(item) && world.isZone()) continue;
|
||||
|
||||
ImageButton button = cont.addImageButton(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get();
|
||||
@@ -38,6 +36,21 @@ public class ItemSelection{
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
//add extra blank spaces so it looks nice
|
||||
if(i % 4 != 0){
|
||||
int remaining = 4 - (i % 4);
|
||||
for(int j = 0; j < remaining; j++){
|
||||
cont.addImage(Styles.black6);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(scrollPos);
|
||||
pane.update(() -> {
|
||||
scrollPos = pane.getScrollY();
|
||||
});
|
||||
|
||||
table.add(pane).maxHeight(40 * 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class Sorter extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
SorterEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class Battery extends PowerDistributor{
|
||||
public int topRegion = reg("-top");
|
||||
|
||||
public Color emptyLightColor = Color.valueOf("f8c266");
|
||||
public Color fullLightColor = Color.valueOf("fb9567");
|
||||
|
||||
public Battery(String name){
|
||||
super(name);
|
||||
outputsPower = true;
|
||||
consumesPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
Draw.color(emptyLightColor, fullLightColor, tile.entity.power().status);
|
||||
Fill.square(tile.drawx(), tile.drawy(), tilesize * size / 2f - 1);
|
||||
Draw.color();
|
||||
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ItemSource extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
ItemSourceEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.outputItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.outputItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package mindustry.world.blocks.sandbox;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.gen.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class LiquidSource extends Block{
|
||||
public static Liquid lastLiquid;
|
||||
@@ -82,29 +77,10 @@ public class LiquidSource extends Block{
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
LiquidSourceEntity entity = tile.ent();
|
||||
|
||||
Array<Liquid> items = content.liquids();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
|
||||
for(int i = 0; i < items.size; i++){
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton(Tex.clear, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).size(38).group(group).get();
|
||||
button.changed(() -> {
|
||||
tile.configure(button.isChecked() ? items.get(f).id : -1);
|
||||
control.input.frag.config.hideConfig();
|
||||
lastLiquid = items.get(f);
|
||||
});
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(items.get(i).icon(Cicon.medium));
|
||||
button.setChecked(entity.source == items.get(i));
|
||||
|
||||
if(i % 4 == 3){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
ItemSelection.buildTable(table, content.liquids(), () -> entity.source, liquid -> {
|
||||
lastLiquid = liquid;
|
||||
tile.configure(liquid == null ? -1 : liquid.id);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,7 +123,7 @@ public class Unloader extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
UnloaderEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user