1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-21 21:38:29 +03:00

Merge branches 'master' and 'rhino-js-suffering' of https://github.com/Anuken/Mindustry

# Conflicts:
#	core/src/io/anuke/mindustry/content/Blocks.java
#	gradle.properties
This commit is contained in:
Anuken 2019-12-08 00:15:42 -05:00
commit 268f3cc3c2
98 changed files with 910 additions and 337 deletions

View File

@ -28,6 +28,7 @@ dependencies{
implementation project(":core")
implementation arcModule("backends:backend-android")
implementation 'com.faendir.rhino:rhino-android:1.5.2'
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"

View File

@ -9,10 +9,11 @@ import android.os.Build.*;
import android.os.*;
import android.provider.Settings.*;
import android.telephony.*;
import com.faendir.rhino_android.*;
import io.anuke.arc.*;
import io.anuke.arc.backends.android.surfaceview.*;
import io.anuke.arc.files.*;
import io.anuke.arc.func.Cons;
import io.anuke.arc.func.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.serialization.*;
@ -65,6 +66,11 @@ public class AndroidLauncher extends AndroidApplication{
}
}
@Override
public org.mozilla.javascript.Context getScriptContext(){
return new RhinoAndroidHelper(Core.files.local("script-output").file()).enterContext();
}
@Override
public void shareFile(FileHandle file){
}

View File

@ -257,6 +257,7 @@ project(":core"){
compile arcModule("arc-core")
compile arcModule("extensions:freetype")
compile arcModule("extensions:arcnet")
compile "org.mozilla:rhino:1.7.11"
if(localArc() && debugged()) compile arcModule("extensions:recorder")
compileOnly project(":annotations")
@ -298,6 +299,7 @@ project(":tools"){
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "org.reflections:reflections:0.9.11"
compile arcModule("backends:backend-sdl")
}

View File

@ -26,6 +26,7 @@ load.image = Images
load.content = Content
load.system = System
load.mod = Mods
load.scripts = Scripts
schematic = Schematic
schematic.add = Save Schematic...

13
core/assets/scripts/base.js Executable file
View File

@ -0,0 +1,13 @@
const log = function(context, obj){
Vars.mods.getScripts().log(context, obj ? String(obj) : "null")
}
const extendContent = function(classType, name, params){
return new JavaAdapter(classType, params, name)
}
const extend = function(classType, params){
return new JavaAdapter(classType, params)
}
const base = {}

70
core/assets/scripts/global.js Executable file
View File

@ -0,0 +1,70 @@
//Generated class. Do not modify.
const log = function(context, obj){
Vars.mods.getScripts().log(context, obj ? String(obj) : "null")
}
const extendContent = function(classType, name, params){
return new JavaAdapter(classType, params, name)
}
const extend = function(classType, params){
return new JavaAdapter(classType, params)
}
const base = {}
importPackage(Packages.io.anuke.arc)
importPackage(Packages.io.anuke.arc.collection)
importPackage(Packages.io.anuke.arc.graphics)
importPackage(Packages.io.anuke.arc.graphics.g2d)
importPackage(Packages.io.anuke.arc.math)
importPackage(Packages.io.anuke.arc.scene)
importPackage(Packages.io.anuke.arc.scene.actions)
importPackage(Packages.io.anuke.arc.scene.event)
importPackage(Packages.io.anuke.arc.scene.style)
importPackage(Packages.io.anuke.arc.scene.ui)
importPackage(Packages.io.anuke.arc.scene.ui.layout)
importPackage(Packages.io.anuke.arc.scene.utils)
importPackage(Packages.io.anuke.arc.util)
importPackage(Packages.io.anuke.mindustry)
importPackage(Packages.io.anuke.mindustry.ai)
importPackage(Packages.io.anuke.mindustry.content)
importPackage(Packages.io.anuke.mindustry.core)
importPackage(Packages.io.anuke.mindustry.ctype)
importPackage(Packages.io.anuke.mindustry.editor)
importPackage(Packages.io.anuke.mindustry.entities)
importPackage(Packages.io.anuke.mindustry.entities.bullet)
importPackage(Packages.io.anuke.mindustry.entities.effect)
importPackage(Packages.io.anuke.mindustry.entities.traits)
importPackage(Packages.io.anuke.mindustry.entities.type)
importPackage(Packages.io.anuke.mindustry.entities.type.base)
importPackage(Packages.io.anuke.mindustry.entities.units)
importPackage(Packages.io.anuke.mindustry.game)
importPackage(Packages.io.anuke.mindustry.graphics)
importPackage(Packages.io.anuke.mindustry.input)
importPackage(Packages.io.anuke.mindustry.maps)
importPackage(Packages.io.anuke.mindustry.maps.filters)
importPackage(Packages.io.anuke.mindustry.maps.generators)
importPackage(Packages.io.anuke.mindustry.maps.zonegen)
importPackage(Packages.io.anuke.mindustry.type)
importPackage(Packages.io.anuke.mindustry.ui)
importPackage(Packages.io.anuke.mindustry.ui.dialogs)
importPackage(Packages.io.anuke.mindustry.ui.fragments)
importPackage(Packages.io.anuke.mindustry.ui.layout)
importPackage(Packages.io.anuke.mindustry.world)
importPackage(Packages.io.anuke.mindustry.world.blocks)
importPackage(Packages.io.anuke.mindustry.world.blocks.defense)
importPackage(Packages.io.anuke.mindustry.world.blocks.defense.turrets)
importPackage(Packages.io.anuke.mindustry.world.blocks.distribution)
importPackage(Packages.io.anuke.mindustry.world.blocks.liquid)
importPackage(Packages.io.anuke.mindustry.world.blocks.logic)
importPackage(Packages.io.anuke.mindustry.world.blocks.power)
importPackage(Packages.io.anuke.mindustry.world.blocks.production)
importPackage(Packages.io.anuke.mindustry.world.blocks.sandbox)
importPackage(Packages.io.anuke.mindustry.world.blocks.storage)
importPackage(Packages.io.anuke.mindustry.world.blocks.units)
importPackage(Packages.io.anuke.mindustry.world.consumers)
importPackage(Packages.io.anuke.mindustry.world.meta)
importPackage(Packages.io.anuke.mindustry.world.meta.values)
importPackage(Packages.io.anuke.mindustry.world.modules)
importPackage(Packages.io.anuke.mindustry.world.producers)

10
core/assets/scripts/wrapper.js Executable file
View File

@ -0,0 +1,10 @@
modName = "$MOD_NAME$"
!function(){
const scriptName = "$SCRIPT_NAME$"
const print = text => log(scriptName, text);
$CODE$
}();

View File

@ -70,8 +70,11 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
Sounds.load();
assets.loadRun("contentcreate", Content.class, () -> {
content.createContent();
content.createBaseContent();
content.loadColors();
}, () -> {
mods.loadScripts();
content.createModContent();
});
add(logic = new Logic());
@ -193,7 +196,8 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
if(assets.getCurrentLoading() != null){
String name = assets.getCurrentLoading().fileName.toLowerCase();
String key = name.contains("content") ? "content" : name.contains("mod") ? "mods" : name.contains("msav") || name.contains("maps") ? "map" : name.contains("ogg") || name.contains("mp3") ? "sound" : name.contains("png") ? "image" : "system";
String key = name.contains("script") ? "scripts" : name.contains("content") ? "content" : name.contains("mod") ? "mods" : name.contains("msav") ||
name.contains("maps") ? "map" : name.contains("ogg") || name.contains("mp3") ? "sound" : name.contains("png") ? "image" : "system";
font.draw(bundle.get("load." + key, ""), graphics.getWidth() / 2f, graphics.getHeight() / 2f - height / 2f - Scl.scl(10f), Align.center);
}
}

View File

@ -7,7 +7,7 @@ import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.ctype.ContentList;
import io.anuke.mindustry.ctype.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.bullet.*;
import io.anuke.mindustry.entities.type.*;
@ -19,8 +19,7 @@ import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.blocks.defense.*;
import io.anuke.mindustry.world.blocks.defense.turrets.*;
import io.anuke.mindustry.world.blocks.distribution.*;
import io.anuke.mindustry.world.blocks.liquid.Conduit;
import io.anuke.mindustry.world.blocks.liquid.LiquidTank;
import io.anuke.mindustry.world.blocks.liquid.*;
import io.anuke.mindustry.world.blocks.logic.*;
import io.anuke.mindustry.world.blocks.power.*;
import io.anuke.mindustry.world.blocks.production.*;
@ -915,6 +914,7 @@ public class Blocks implements ContentList{
phaseConveyor = new ItemBridge("phase-conveyor"){{
requirements(Category.distribution, ItemStack.with(Items.phasefabric, 5, Items.silicon, 7, Items.lead, 10, Items.graphite, 10));
range = 12;
canOverdrive = false;
hasPower = true;
consumes.power(0.30f);
}};
@ -977,7 +977,7 @@ public class Blocks implements ContentList{
size = 3;
}};
conduit = new io.anuke.mindustry.world.blocks.liquid.Conduit("conduit"){{
conduit = new Conduit("conduit"){{
requirements(Category.liquid, ItemStack.with(Items.metaglass, 1));
health = 45;
}};
@ -989,14 +989,14 @@ public class Blocks implements ContentList{
health = 90;
}};
platedConduit = new io.anuke.mindustry.world.blocks.liquid.ArmoredConduit("plated-conduit"){{
platedConduit = new ArmoredConduit("plated-conduit"){{
requirements(Category.liquid, ItemStack.with(Items.thorium, 2, Items.metaglass, 1, Items.plastanium, 1));
liquidCapacity = 16f;
liquidPressure = 1.025f;
health = 220;
}};
liquidRouter = new io.anuke.mindustry.world.blocks.liquid.LiquidRouter("liquid-router"){{
liquidRouter = new LiquidRouter("liquid-router"){{
requirements(Category.liquid, ItemStack.with(Items.graphite, 4, Items.metaglass, 2));
liquidCapacity = 20f;
}};
@ -1008,20 +1008,21 @@ public class Blocks implements ContentList{
health = 500;
}};
liquidJunction = new io.anuke.mindustry.world.blocks.liquid.LiquidJunction("liquid-junction"){{
liquidJunction = new LiquidJunction("liquid-junction"){{
requirements(Category.liquid, ItemStack.with(Items.graphite, 2, Items.metaglass, 2));
}};
bridgeConduit = new io.anuke.mindustry.world.blocks.liquid.LiquidExtendingBridge("bridge-conduit"){{
bridgeConduit = new LiquidExtendingBridge("bridge-conduit"){{
requirements(Category.liquid, ItemStack.with(Items.graphite, 4, Items.metaglass, 8));
range = 4;
hasPower = false;
}};
phaseConduit = new io.anuke.mindustry.world.blocks.liquid.LiquidBridge("phase-conduit"){{
phaseConduit = new LiquidBridge("phase-conduit"){{
requirements(Category.liquid, ItemStack.with(Items.phasefabric, 5, Items.silicon, 7, Items.metaglass, 20, Items.titanium, 10));
range = 12;
hasPower = true;
canOverdrive = false;
consumes.power(0.30f);
}};

View File

@ -3,6 +3,7 @@ package io.anuke.mindustry.core;
import io.anuke.arc.collection.*;
import io.anuke.arc.func.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.ctype.*;
@ -20,10 +21,10 @@ import static io.anuke.mindustry.Vars.mods;
*/
@SuppressWarnings("unchecked")
public class ContentLoader{
private boolean loaded = false;
private ObjectMap<String, MappableContent>[] contentNameMap = new ObjectMap[ContentType.values().length];
private Array<Content>[] contentMap = new Array[ContentType.values().length];
private MappableContent[][] temporaryMapper;
private @Nullable LoadedMod currentMod;
private ObjectSet<Cons<Content>> initialization = new ObjectSet<>();
private ContentList[] content = {
new Fx(),
@ -43,35 +44,40 @@ public class ContentLoader{
new LegacyColorMapper(),
};
public ContentLoader(){
clear();
}
/** Clears all initialized content.*/
public void clear(){
contentNameMap = new ObjectMap[ContentType.values().length];
contentMap = new Array[ContentType.values().length];
initialization = new ObjectSet<>();
loaded = false;
}
/** Creates all content types. */
public void createContent(){
if(loaded){
Log.info("Content already loaded, skipping.");
return;
}
for(ContentType type : ContentType.values()){
contentMap[type.ordinal()] = new Array<>();
contentNameMap[type.ordinal()] = new ObjectMap<>();
}
}
/** Creates all base types. */
public void createBaseContent(){
for(ContentList list : content){
list.load();
}
}
/** Creates mod content, if applicable. */
public void createModContent(){
if(mods != null){
mods.loadContent();
}
}
//check up ID mapping, make sure it's linear
/** Logs content statistics.*/
public void logContent(){
//check up ID mapping, make sure it's linear (debug only)
for(Array<Content> arr : contentMap){
for(int i = 0; i < arr.size; i++){
int id = arr.get(i).id;
@ -81,11 +87,6 @@ public class ContentLoader{
}
}
loaded = true;
}
/** Logs content statistics.*/
public void logContent(){
Log.info("--- CONTENT INFO ---");
for(int k = 0; k < contentMap.length; k++){
Log.info("[{0}]: loaded {1}", ContentType.values()[k].name(), contentMap[k].size);
@ -147,13 +148,23 @@ public class ContentLoader{
public void handleContent(Content content){
contentMap[content.getContentType().ordinal()].add(content);
}
public void setCurrentMod(LoadedMod mod){
this.currentMod = mod;
}
public String transformName(String name){
return currentMod == null ? name : currentMod.name + "-" + name;
}
public void handleMappableContent(MappableContent content){
if(contentNameMap[content.getContentType().ordinal()].containsKey(content.name)){
throw new IllegalArgumentException("Two content objects cannot have the same name! (issue: '" + content.name + "')");
}
if(currentMod != null){
content.mod = currentMod;
}
contentNameMap[content.getContentType().ordinal()].put(content.name, content);
}

View File

@ -451,12 +451,12 @@ public class Control implements ApplicationListener, Loadable{
platform.updateRPC();
}
if(Core.input.keyTap(Binding.pause) && !scene.hasDialog() && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){
if(Core.input.keyTap(Binding.pause) && !scene.hasDialog() && !scene.hasKeyboard() && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){
state.set(state.is(State.playing) ? State.paused : State.playing);
}
if(Core.input.keyTap(Binding.menu) && !ui.restart.isShown()){
if(ui.chatfrag.chatOpen()){
if(ui.chatfrag.shown()){
ui.chatfrag.hide();
}else if(!ui.paused.isShown() && !scene.hasDialog()){
ui.paused.show();
@ -464,7 +464,7 @@ public class Control implements ApplicationListener, Loadable{
}
}
if(!mobile && Core.input.keyTap(Binding.screenshot) && !(scene.getKeyboardFocus() instanceof TextField) && !ui.chatfrag.chatOpen()){
if(!mobile && Core.input.keyTap(Binding.screenshot) && !(scene.getKeyboardFocus() instanceof TextField) && !scene.hasKeyboard()){
renderer.takeMapScreenshot();
}

View File

@ -491,7 +491,7 @@ public class NetClient implements ApplicationListener{
player.pointerX, player.pointerY, player.rotation, player.baseRotation,
player.velocity().x, player.velocity().y,
player.getMineTile(),
player.isBoosting, player.isShooting, ui.chatfrag.chatOpen(), player.isBuilding,
player.isBoosting, player.isShooting, ui.chatfrag.shown(), player.isBuilding,
requests,
Core.camera.position.x, Core.camera.position.y,
Core.camera.width * viewScale, Core.camera.height * viewScale);

View File

@ -8,10 +8,12 @@ import io.anuke.arc.func.*;
import io.anuke.arc.math.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.serialization.*;
import io.anuke.mindustry.mod.*;
import io.anuke.mindustry.net.*;
import io.anuke.mindustry.net.Net.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.dialogs.*;
import org.mozilla.javascript.*;
import static io.anuke.mindustry.Vars.mobile;
@ -45,6 +47,17 @@ public interface Platform{
return new ArcNetImpl();
}
/** Gets the scripting implementation. */
default Scripts createScripts(){
return new Scripts();
}
default Context getScriptContext(){
Context c = Context.enter();
c.setOptimizationLevel(9);
return c;
}
/** Add a text input dialog that should show up after the field is tapped. */
default void addDialog(TextField field){
addDialog(field, 16);

View File

@ -42,6 +42,7 @@ public class UI implements ApplicationListener, Loadable{
public MenuFragment menufrag;
public HudFragment hudfrag;
public ChatFragment chatfrag;
public ScriptConsoleFragment scriptfrag;
public PlayerListFragment listfrag;
public LoadingFragment loadfrag;
@ -211,6 +212,7 @@ public class UI implements ApplicationListener, Loadable{
chatfrag = new ChatFragment();
listfrag = new PlayerListFragment();
loadfrag = new LoadingFragment();
scriptfrag = new ScriptConsoleFragment();
picker = new ColorPicker();
editor = new MapEditorDialog();
@ -253,6 +255,7 @@ public class UI implements ApplicationListener, Loadable{
menufrag.build(menuGroup);
chatfrag.container().build(hudGroup);
listfrag.build(hudGroup);
scriptfrag.container().build(hudGroup);
loadfrag.build(group);
new FadeInFragment().build(group);
}

View File

@ -6,7 +6,7 @@ public abstract class MappableContent extends Content{
public final String name;
public MappableContent(String name){
this.name = name;
this.name = Vars.content.transformName(name);
Vars.content.handleMappableContent(this);
}

View File

@ -20,8 +20,8 @@ public abstract class UnlockableContent extends MappableContent{
public UnlockableContent(String name){
super(name);
this.localizedName = Core.bundle.get(getContentType() + "." + name + ".name", name);
this.description = Core.bundle.getOrNull(getContentType() + "." + name + ".description");
this.localizedName = Core.bundle.get(getContentType() + "." + this.name + ".name", this.name);
this.description = Core.bundle.getOrNull(getContentType() + "." + this.name + ".description");
}
/** Generate any special icons for this content. Called asynchronously.*/

View File

@ -556,7 +556,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
updateKeyboard();
}
isTyping = ui.chatfrag.chatOpen();
isTyping = ui.chatfrag.shown();
updateMechanics();
@ -604,7 +604,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
movement.limit(speed).scl(Time.delta());
if(!ui.chatfrag.chatOpen()){
if(!Core.scene.hasKeyboard()){
velocity.add(movement.x, movement.y);
}else{
isShooting = false;
@ -613,7 +613,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
updateVelocityStatus();
moved = dst(prex, prey) > 0.001f;
if(!ui.chatfrag.chatOpen()){
if(!Core.scene.hasKeyboard()){
float baseLerp = mech.getRotationAlpha(this);
if(!isShooting() || !mech.turnCursor){
if(!movement.isZero()){

View File

@ -54,6 +54,7 @@ public enum Binding implements KeyBind{
chat_history_prev(KeyCode.UP),
chat_history_next(KeyCode.DOWN),
chat_scroll(new Axis(KeyCode.SCROLL)),
console(KeyCode.BACKTICK),
;
private final KeybindValue defaultValue;

View File

@ -122,7 +122,7 @@ public class DesktopInput extends InputHandler{
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
}
if(Core.input.keyDown(Binding.schematic_select) && !ui.chatfrag.chatOpen()){
if(Core.input.keyDown(Binding.schematic_select) && !Core.scene.hasKeyboard()){
drawSelection(schemX, schemY, cursorX, cursorY, Vars.maxSchematicSize);
}
@ -139,7 +139,7 @@ public class DesktopInput extends InputHandler{
player.isShooting = false;
}
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && (scene.getKeyboardFocus() == ui.minimap || !scene.hasDialog()) && !ui.chatfrag.chatOpen() && !(scene.getKeyboardFocus() instanceof TextField)){
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && (scene.getKeyboardFocus() == ui.minimap || !scene.hasDialog()) && !Core.scene.hasKeyboard() && !(scene.getKeyboardFocus() instanceof TextField)){
if(!ui.minimap.isShown()){
ui.minimap.show();
}else{
@ -293,12 +293,12 @@ public class DesktopInput extends InputHandler{
player.clearBuilding();
}
if(Core.input.keyTap(Binding.schematic_select) && !ui.chatfrag.chatOpen()){
if(Core.input.keyTap(Binding.schematic_select) && !Core.scene.hasKeyboard()){
schemX = rawCursorX;
schemY = rawCursorY;
}
if(Core.input.keyTap(Binding.schematic_menu) && !ui.chatfrag.chatOpen()){
if(Core.input.keyTap(Binding.schematic_menu) && !Core.scene.hasKeyboard()){
if(ui.schematics.isShown()){
ui.schematics.hide();
}else{
@ -311,7 +311,7 @@ public class DesktopInput extends InputHandler{
selectRequests.clear();
}
if(Core.input.keyRelease(Binding.schematic_select) && !ui.chatfrag.chatOpen()){
if(Core.input.keyRelease(Binding.schematic_select) && !Core.scene.hasKeyboard()){
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
useSchematic(lastSchematic);
if(selectRequests.isEmpty()){
@ -371,10 +371,10 @@ public class DesktopInput extends InputHandler{
}else if(selected != null){
//only begin shooting if there's no cursor event
if(!tileTapped(selected) && !tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && (player.buildQueue().size == 0 || !player.isBuilding) && !droppingItem &&
!tryBeginMine(selected) && player.getMineTile() == null && !ui.chatfrag.chatOpen()){
!tryBeginMine(selected) && player.getMineTile() == null && !Core.scene.hasKeyboard()){
player.isShooting = true;
}
}else if(!ui.chatfrag.chatOpen()){ //if it's out of bounds, shooting is just fine
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine
player.isShooting = true;
}
}else if(Core.input.keyTap(Binding.deselect) && block != null){

View File

@ -1,5 +1,5 @@
package io.anuke.mindustry.input;
enum PlaceMode{
public enum PlaceMode{
none, breaking, placing, schematicSelect
}

File diff suppressed because one or more lines are too long

View File

@ -52,6 +52,11 @@ public class ContentParser{
}
}
});
put(StatusEffect.class, (type, data) -> {
StatusEffect effect = new StatusEffect();
readFields(effect, data);
return effect;
});
put(Color.class, (type, data) -> Color.valueOf(data.asString()));
put(BulletType.class, (type, data) -> {
if(data.isString()){

View File

@ -15,11 +15,6 @@ public class Mod{
}
/** Create any content needed here. */
public void loadContent(){
}
/** Register any commands to be used on the server side, e.g. from the console. */
public void registerServerCommands(CommandHandler handler){

View File

@ -30,6 +30,7 @@ import static io.anuke.mindustry.Vars.*;
public class Mods implements Loadable{
private Json json = new Json();
private @Nullable Scripts scripts;
private ContentParser parser = new ContentParser();
private ObjectMap<String, Array<FileHandle>> bundles = new ObjectMap<>();
private ObjectSet<String> specialFolders = ObjectSet.with("bundles", "sprites");
@ -202,6 +203,16 @@ public class Mods implements Loadable{
requiresReload = true;
}
public Scripts getScripts(){
if(scripts == null) scripts = platform.createScripts();
return scripts;
}
/** @return whether the scripting engine has been initialized. */
public boolean hasScripts(){
return scripts != null;
}
public boolean requiresReload(){
return requiresReload;
}
@ -352,8 +363,15 @@ public class Mods implements Loadable{
Sounds.dispose();
Sounds.load();
Core.assets.finishLoading();
if(scripts != null){
scripts.dispose();
scripts = null;
}
content.clear();
content.createContent();
content.createBaseContent();
content.loadColors();
loadScripts();
content.createModContent();
loadAsync();
loadSync();
content.init();
@ -365,8 +383,44 @@ public class Mods implements Loadable{
Events.fire(new ContentReloadEvent());
}
/** This must be run on the main thread! */
public void loadScripts(){
Time.mark();
try{
for(LoadedMod mod : loaded){
if(mod.root.child("scripts").exists()){
content.setCurrentMod(mod);
mod.scripts = mod.root.child("scripts").findAll(f -> f.extension().equals("js"));
Log.info("[{0}] Found {1} scripts.", mod.meta.name, mod.scripts.size);
for(FileHandle file : mod.scripts){
try{
if(scripts == null){
scripts = platform.createScripts();
}
scripts.run(mod, file);
}catch(Throwable e){
Core.app.post(() -> {
Log.err("Error loading script {0} for mod {1}.", file.name(), mod.meta.name);
e.printStackTrace();
//if(!headless) ui.showException(e);
});
break;
}
}
}
}
}finally{
content.setCurrentMod(null);
}
Log.info("Time to initialize modded scripts: {0}", Time.elapsed());
}
/** Creates all the content found in mod files. */
public void loadContent(){
class LoadRun implements Comparable<LoadRun>{
final ContentType type;
final FileHandle file;
@ -419,9 +473,6 @@ public class Mods implements Loadable{
//this finishes parsing content fields
parser.finishParsing();
//load content for code mods
each(Mod::loadContent);
}
/** @return all loaded mods. */
@ -587,6 +638,8 @@ public class Mods implements Loadable{
public Array<LoadedMod> dependencies = new Array<>();
/** All missing dependencies of this mod as strings. */
public Array<String> missingDependencies = new Array<>();
/** Script files to run. */
public Array<FileHandle> scripts = new Array<>();
public LoadedMod(FileHandle file, FileHandle root, Mod mod, ModMeta meta){
this.root = root;

View File

@ -0,0 +1,83 @@
package io.anuke.mindustry.mod;
import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.mod.Mods.*;
import org.mozilla.javascript.*;
import static io.anuke.mindustry.Vars.*;
public class Scripts implements Disposable{
private final Context context;
private final String wrapper;
private Scriptable scope;
private Array<String> logBuffer = new Array<>();
public Scripts(){
Time.mark();
context = Vars.platform.getScriptContext();
context.setClassShutter(type -> (ClassAccess.allowedClassNames.contains(type) || type.startsWith("adapter") || type.contains("PrintStream") || type.startsWith("io.anuke.mindustry")) && !type.equals("io.anuke.mindustry.mod.ClassAccess"));
scope = new ImporterTopLevel(context);
wrapper = Core.files.internal("scripts/wrapper.js").readString();
run(Core.files.internal("scripts/global.js").readString(), "global.js");
Log.info("Time to load script engine: {0}", Time.elapsed());
}
public String runConsole(String text){
try{
Object o = context.evaluateString(scope, text, "console.js", 1, null);
if(o instanceof NativeJavaObject){
o = ((NativeJavaObject)o).unwrap();
}
if(o instanceof Undefined){
o = "undefined";
}
return String.valueOf(o);
}catch(Throwable t){
return getError(t);
}
}
private String getError(Throwable t){
t = Strings.getFinalCause(t);
return t.getClass().getSimpleName() + (t.getMessage() == null ? "" : ": " + t.getMessage());
}
public void log(String source, String message){
Log.info("[{0}]: {1}", source, message);
logBuffer.add("[accent][" + source + "]:[] " + message);
if(!headless & ui.scriptfrag != null){
onLoad();
}
}
public void onLoad(){
if(!headless){
logBuffer.each(ui.scriptfrag::addMessage);
}
logBuffer.clear();
}
public void run(LoadedMod mod, FileHandle file){
run(wrapper.replace("$SCRIPT_NAME$", mod.name + "/" + file.nameWithoutExtension()).replace("$CODE$", file.readString()).replace("$MOD_NAME$", mod.name), file.name());
}
private void run(String script, String file){
try{
context.evaluateString(scope, script, file, 1, null);
}catch(Throwable t){
log(file, "[scarlet]" + getError(t));
}
}
@Override
public void dispose(){
Context.exit();
}
}

View File

@ -34,7 +34,6 @@ public class Item extends UnlockableContent{
public Item(String name, Color color){
super(name);
this.color = color;
this.description = Core.bundle.getOrNull("item." + this.name + ".description");
}
public Item(String name){

View File

@ -31,7 +31,6 @@ public class Liquid extends UnlockableContent{
public Liquid(String name, Color color){
super(name);
this.color = new Color(color);
this.description = Core.bundle.getOrNull("liquid." + name + ".description");
}
/** For modding only.*/

View File

@ -39,7 +39,6 @@ public class Mech extends UnlockableContent{
public Mech(String name, boolean flying){
super(name);
this.flying = flying;
this.description = Core.bundle.get("mech." + name + ".description");
}
public Mech(String name){

View File

@ -51,7 +51,6 @@ public class UnitType extends UnlockableContent{
public <T extends BaseUnit> UnitType(String name){
super(name);
this.description = Core.bundle.getOrNull("unit." + name + ".description");
}
public <T extends BaseUnit> void create(Prov<T> mainConstructor){

View File

@ -24,7 +24,7 @@ public class ChatFragment extends Table{
private final static int messagesShown = 10;
private Array<ChatMessage> messages = new Array<>();
private float fadetime;
private boolean chatOpen = false;
private boolean shown = false;
private TextField chatfield;
private Label fieldlabel = new Label(">");
private BitmapFont font;
@ -52,7 +52,7 @@ public class ChatFragment extends Table{
if(!net.active() && messages.size > 0){
clearMessages();
if(chatOpen){
if(shown){
hide();
}
}
@ -66,7 +66,7 @@ public class ChatFragment extends Table{
toggle();
}
if(chatOpen){
if(shown){
if(input.keyTap(Binding.chat_history_prev) && historyPos < history.size - 1){
if(historyPos == 0) history.set(0, chatfield.getText());
historyPos++;
@ -123,7 +123,7 @@ public class ChatFragment extends Table{
Draw.color(shadowColor);
if(chatOpen){
if(shown){
Fill.crect(offsetx, chatfield.getY(), chatfield.getWidth() + 15f, chatfield.getHeight() - 1);
}
@ -131,14 +131,14 @@ public class ChatFragment extends Table{
float spacing = chatspace;
chatfield.visible(chatOpen);
fieldlabel.visible(chatOpen);
chatfield.visible(shown);
fieldlabel.visible(shown);
Draw.color(shadowColor);
Draw.alpha(shadowColor.a * opacity);
float theight = offsety + spacing + getMarginBottom();
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || chatOpen); i++){
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || shown); i++){
layout.setText(font, messages.get(i).formattedMessage, Color.white, textWidth, Align.bottomLeft, true);
theight += layout.height + textspacing;
@ -147,7 +147,7 @@ public class ChatFragment extends Table{
font.getCache().clear();
font.getCache().addText(messages.get(i).formattedMessage, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
if(!chatOpen && fadetime - i < 1f && fadetime - i >= 0f){
if(!shown && fadetime - i < 1f && fadetime - i >= 0f){
font.getCache().setAlphas((fadetime - i) * opacity);
Draw.color(0, 0, 0, shadowColor.a * (fadetime - i) * opacity);
}else{
@ -163,7 +163,7 @@ public class ChatFragment extends Table{
Draw.color();
if(fadetime > 0 && !chatOpen)
if(fadetime > 0 && !shown)
fadetime -= Time.delta() / 180f;
}
@ -180,9 +180,9 @@ public class ChatFragment extends Table{
public void toggle(){
if(!chatOpen){
if(!shown){
scene.setKeyboardFocus(chatfield);
chatOpen = !chatOpen;
shown = !shown;
if(mobile){
TextInput input = new TextInput();
input.maxLength = maxTextLength;
@ -199,7 +199,7 @@ public class ChatFragment extends Table{
}
}else{
scene.setKeyboardFocus(null);
chatOpen = !chatOpen;
shown = !shown;
scrollPos = 0;
sendMessage();
}
@ -207,7 +207,7 @@ public class ChatFragment extends Table{
public void hide(){
scene.setKeyboardFocus(null);
chatOpen = false;
shown = false;
clearChatInput();
}
@ -222,12 +222,8 @@ public class ChatFragment extends Table{
chatfield.setText("");
}
public boolean chatOpen(){
return chatOpen;
}
public int getMessagesSize(){
return messages.size;
public boolean shown(){
return shown;
}
public void addMessage(String message, String sender){

View File

@ -83,7 +83,7 @@ public class HudFragment extends Fragment{
select.addImageButton(Icon.chatSmall, style,() -> {
if(net.active() && mobile){
if(ui.chatfrag.chatOpen()){
if(ui.chatfrag.shown()){
ui.chatfrag.hide();
}else{
ui.chatfrag.toggle();
@ -131,7 +131,7 @@ public class HudFragment extends Fragment{
}
cont.update(() -> {
if(Core.input.keyTap(Binding.toggle_menus) && !ui.chatfrag.chatOpen() && !Core.scene.hasDialog() && !(Core.scene.getKeyboardFocus() instanceof TextField)){
if(Core.input.keyTap(Binding.toggle_menus) && !ui.chatfrag.shown() && !Core.scene.hasDialog() && !(Core.scene.getKeyboardFocus() instanceof TextField)){
toggleMenus();
}
});

View File

@ -103,7 +103,8 @@ public class PlacementFragment extends Fragment{
}
}
if(ui.chatfrag.chatOpen()) return false;
if(ui.chatfrag.shown() || Core.scene.hasKeyboard()) return false;
for(int i = 0; i < blockSelect.length; i++){
if(Core.input.keyTap(blockSelect[i])){
if(i > 9) { //select block directionally

View File

@ -0,0 +1,224 @@
package io.anuke.mindustry.ui.fragments;
import io.anuke.arc.*;
import io.anuke.arc.Input.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*;
import io.anuke.arc.scene.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.Label.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.input.*;
import io.anuke.mindustry.ui.*;
import static io.anuke.arc.Core.*;
import static io.anuke.mindustry.Vars.*;
public class ScriptConsoleFragment extends Table{
private final static int messagesShown = 14;
private Array<String> messages = new Array<>();
private boolean open = false, shown;
private TextField chatfield;
private Label fieldlabel = new Label(">");
private BitmapFont font;
private GlyphLayout layout = new GlyphLayout();
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50);
private Color shadowColor = new Color(0, 0, 0, 0.4f);
private float textspacing = Scl.scl(10);
private Array<String> history = new Array<>();
private int historyPos = 0;
private int scrollPos = 0;
private Fragment container = new Fragment(){
@Override
public void build(Group parent){
scene.add(ScriptConsoleFragment.this);
}
};
public ScriptConsoleFragment(){
setFillParent(true);
font = Fonts.def;
visible(() -> {
if(input.keyTap(Binding.console) && !Vars.net.client() && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null)){
shown = !shown;
if(shown && !open){
toggle();
}
clearChatInput();
}
return shown && !Vars.net.client();
});
update(() -> {
if(input.keyTap(Binding.chat) && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null)){
toggle();
}
if(open){
if(input.keyTap(Binding.chat_history_prev) && historyPos < history.size - 1){
if(historyPos == 0) history.set(0, chatfield.getText());
historyPos++;
updateChat();
}
if(input.keyTap(Binding.chat_history_next) && historyPos > 0){
historyPos--;
updateChat();
}
scrollPos = (int)Mathf.clamp(scrollPos + input.axis(Binding.chat_scroll), 0, Math.max(0, messages.size - messagesShown));
}
});
history.insert(0, "");
setup();
if(mods.hasScripts()){
app.post(() -> mods.getScripts().onLoad());
}
}
public Fragment container(){
return container;
}
public void clearMessages(){
messages.clear();
history.clear();
history.insert(0, "");
}
private void setup(){
fieldlabel.setStyle(new LabelStyle(fieldlabel.getStyle()));
fieldlabel.getStyle().font = font;
fieldlabel.setStyle(fieldlabel.getStyle());
chatfield = new TextField("", new TextField.TextFieldStyle(scene.getStyle(TextField.TextFieldStyle.class)));
chatfield.setMaxLength(Vars.maxTextLength);
chatfield.getStyle().background = null;
chatfield.getStyle().font = Fonts.chat;
chatfield.getStyle().fontColor = Color.white;
chatfield.setStyle(chatfield.getStyle());
bottom().left().marginBottom(offsety).marginLeft(offsetx * 2).add(fieldlabel).padBottom(6f);
add(chatfield).padBottom(offsety).padLeft(offsetx).growX().padRight(offsetx).height(28);
}
@Override
public void draw(){
float opacity = 1f;
float textWidth = graphics.getWidth() - offsetx*2f;
Draw.color(shadowColor);
if(open){
Fill.crect(offsetx, chatfield.getY(), chatfield.getWidth() + 15f, chatfield.getHeight() - 1);
}
super.draw();
float spacing = chatspace;
chatfield.visible(open);
fieldlabel.visible(open);
Draw.color(shadowColor);
Draw.alpha(shadowColor.a * opacity);
float theight = offsety + spacing + getMarginBottom();
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos; i++){
layout.setText(font, messages.get(i), Color.white, textWidth, Align.bottomLeft, true);
theight += layout.height + textspacing;
if(i - scrollPos == 0) theight -= textspacing + 1;
font.getCache().clear();
font.getCache().addText(messages.get(i), fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
if(!open){
font.getCache().setAlphas(opacity);
Draw.color(0, 0, 0, shadowColor.a * opacity);
}else{
font.getCache().setAlphas(opacity);
}
Fill.crect(offsetx, theight - layout.height - 2, textWidth + Scl.scl(4f), layout.height + textspacing);
Draw.color(shadowColor);
Draw.alpha(opacity * shadowColor.a);
font.getCache().draw();
}
Draw.color();
}
private void sendMessage(){
String message = chatfield.getText();
clearChatInput();
if(message.replaceAll(" ", "").isEmpty()) return;
history.insert(1, message);
addMessage("[lightgray]> " + message);
addMessage(mods.getScripts().runConsole(message));
}
public void toggle(){
if(!open){
scene.setKeyboardFocus(chatfield);
open = !open;
if(mobile){
TextInput input = new TextInput();
input.maxLength = maxTextLength;
input.accepted = text -> {
chatfield.setText(text);
sendMessage();
hide();
Core.input.setOnscreenKeyboardVisible(false);
};
input.canceled = this::hide;
Core.input.getTextInput(input);
}else{
chatfield.fireClick();
}
}else{
scene.setKeyboardFocus(null);
open = !open;
scrollPos = 0;
sendMessage();
}
}
public void hide(){
scene.setKeyboardFocus(null);
open = false;
clearChatInput();
}
public void updateChat(){
chatfield.setText(history.get(historyPos));
chatfield.setCursorPosition(chatfield.getText().length());
}
public void clearChatInput(){
historyPos = 0;
history.set(0, "");
chatfield.setText("");
}
public boolean open(){
return open;
}
public void addMessage(String message){
messages.insert(0, message);
}
}

View File

@ -158,7 +158,6 @@ public class Block extends BlockStorage{
public Block(String name){
super(name);
this.description = Core.bundle.getOrNull("block." + name + ".description");
this.solid = false;
}

View File

@ -18,11 +18,11 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class Door extends Wall{
protected final Rectangle rect = new Rectangle();
protected final static Rectangle rect = new Rectangle();
protected int timerToggle = timers++;
protected Effect openfx = Fx.dooropen;
protected Effect closefx = Fx.doorclose;
public final int timerToggle = timers++;
public Effect openfx = Fx.dooropen;
public Effect closefx = Fx.doorclose;
protected TextureRegion openRegion;

View File

@ -21,17 +21,17 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class ForceProjector extends Block{
protected int timerUse = timers++;
protected float phaseUseTime = 350f;
public final int timerUse = timers++;
public float phaseUseTime = 350f;
protected float phaseRadiusBoost = 80f;
protected float radius = 101.7f;
protected float breakage = 550f;
protected float cooldownNormal = 1.75f;
protected float cooldownLiquid = 1.5f;
protected float cooldownBrokenBase = 0.35f;
protected float basePowerDraw = 0.2f;
protected TextureRegion topRegion;
public float phaseRadiusBoost = 80f;
public float radius = 101.7f;
public float breakage = 550f;
public float cooldownNormal = 1.75f;
public float cooldownLiquid = 1.5f;
public float cooldownBrokenBase = 0.35f;
public float basePowerDraw = 0.2f;
public TextureRegion topRegion;
private static Tile paramTile;
private static ForceProjector paramBlock;

View File

@ -18,19 +18,18 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class MendProjector extends Block{
private static Color color = Color.valueOf("84f491");
private static Color phase = Color.valueOf("ffd59e");
private static IntSet healed = new IntSet();
private static final IntSet healed = new IntSet();
protected int timerUse = timers++;
protected TextureRegion topRegion;
protected float reload = 250f;
protected float range = 60f;
protected float healPercent = 12f;
protected float phaseBoost = 12f;
protected float phaseRangeBoost = 50f;
protected float useTime = 400f;
public final int timerUse = timers++;
public Color baseColor = Color.valueOf("84f491");
public Color phaseColor = Color.valueOf("ffd59e");
public TextureRegion topRegion;
public float reload = 250f;
public float range = 60f;
public float healPercent = 12f;
public float phaseBoost = 12f;
public float phaseRangeBoost = 50f;
public float useTime = 400f;
public MendProjector(String name){
super(name);
@ -92,7 +91,7 @@ public class MendProjector extends Block{
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.efficiency());
Effects.effect(Fx.healBlockFull, Tmp.c1.set(color).lerp(phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
Effects.effect(Fx.healBlockFull, Tmp.c1.set(baseColor).lerp(phaseColor, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
healed.add(other.pos());
}
}
@ -110,7 +109,7 @@ public class MendProjector extends Block{
MendEntity entity = tile.entity();
float realRange = range + entity.phaseHeat * phaseRangeBoost;
Drawf.dashCircle(tile.drawx(), tile.drawy(), realRange, color);
Drawf.dashCircle(tile.drawx(), tile.drawy(), realRange, baseColor);
}
@Override
@ -120,7 +119,7 @@ public class MendProjector extends Block{
MendEntity entity = tile.entity();
float f = 1f - (Time.time() / 100f) % 1f;
Draw.color(color, phase, entity.phaseHeat);
Draw.color(baseColor, phaseColor, entity.phaseHeat);
Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f);
//Draw.blend(Blending.additive);
Draw.rect(topRegion, tile.drawx(), tile.drawy());
@ -135,7 +134,7 @@ public class MendProjector extends Block{
@Override
public void drawLight(Tile tile){
renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), color, 0.7f * tile.entity.efficiency());
renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), baseColor, 0.7f * tile.entity.efficiency());
}
class MendEntity extends TileEntity{

View File

@ -16,19 +16,19 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class OverdriveProjector extends Block{
private static Color color = Color.valueOf("feb380");
private static Color phase = Color.valueOf("ffd59e");
private static IntSet healed = new IntSet();
private static final IntSet healed = new IntSet();
protected int timerUse = timers++;
public final int timerUse = timers++;
protected TextureRegion topRegion;
protected float reload = 60f;
protected float range = 80f;
protected float speedBoost = 1.5f;
protected float speedBoostPhase = 0.75f;
protected float useTime = 400f;
protected float phaseRangeBoost = 20f;
public TextureRegion topRegion;
public float reload = 60f;
public float range = 80f;
public float speedBoost = 1.5f;
public float speedBoostPhase = 0.75f;
public float useTime = 400f;
public float phaseRangeBoost = 20f;
public Color baseColor = Color.valueOf("feb380");
public Color phaseColor = Color.valueOf("ffd59e");
public OverdriveProjector(String name){
super(name);
@ -69,7 +69,7 @@ public class OverdriveProjector extends Block{
@Override
public void drawLight(Tile tile){
renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), color, 0.7f * tile.entity.efficiency());
renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), baseColor, 0.7f * tile.entity.efficiency());
}
@Override
@ -118,7 +118,7 @@ public class OverdriveProjector extends Block{
OverdriveEntity entity = tile.entity();
float realRange = range + entity.phaseHeat * phaseRangeBoost;
Drawf.dashCircle(tile.drawx(), tile.drawy(), realRange, color);
Drawf.dashCircle(tile.drawx(), tile.drawy(), realRange, baseColor);
}
@Override
@ -128,7 +128,7 @@ public class OverdriveProjector extends Block{
OverdriveEntity entity = tile.entity();
float f = 1f - (Time.time() / 100f) % 1f;
Draw.color(color, phase, entity.phaseHeat);
Draw.color(baseColor, phaseColor, entity.phaseHeat);
Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f);
Draw.rect(topRegion, tile.drawx(), tile.drawy());
Draw.alpha(1f);

View File

@ -11,13 +11,13 @@ import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
public class ShockMine extends Block{
protected int timerDamage = timers++;
public final int timerDamage = timers++;
protected float cooldown = 80f;
protected float tileDamage = 5f;
protected float damage = 13;
protected int length = 10;
protected int tendrils = 6;
public float cooldown = 80f;
public float tileDamage = 5f;
public float damage = 13;
public int length = 10;
public int tendrils = 6;
public ShockMine(String name){
super(name);

View File

@ -7,9 +7,9 @@ import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.graphics.Pal;
public class SurgeWall extends Wall{
protected float lightningChance = 0.05f;
protected float lightningDamage = 15f;
protected int lightningLength = 17;
public float lightningChance = 0.05f;
public float lightningDamage = 15f;
public int lightningLength = 17;
public SurgeWall(String name){
super(name);

View File

@ -9,7 +9,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockGroup;
public class Wall extends Block{
protected int variants = 0;
public int variants = 0;
public Wall(String name){
super(name);

View File

@ -13,7 +13,7 @@ import static io.anuke.mindustry.Vars.tilesize;
* Artillery turrets have special shooting calculations done to hit targets.
*/
public class ArtilleryTurret extends ItemTurret{
protected float velocityInaccuracy = 0f;
public float velocityInaccuracy = 0f;
public ArtilleryTurret(String name){
super(name);

View File

@ -8,7 +8,7 @@ import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.tilesize;
public class BurstTurret extends ItemTurret{
protected float burstSpacing = 5;
public float burstSpacing = 5;
public BurstTurret(String name){
super(name);

View File

@ -12,11 +12,11 @@ import static io.anuke.mindustry.Vars.tilesize;
public class ChargeTurret extends PowerTurret{
protected float chargeTime = 30f;
protected int chargeEffects = 5;
protected float chargeMaxDelay = 10f;
protected Effect chargeEffect = Fx.none;
protected Effect chargeBeginEffect = Fx.none;
public float chargeTime = 30f;
public int chargeEffects = 5;
public float chargeMaxDelay = 10f;
public Effect chargeEffect = Fx.none;
public Effect chargeBeginEffect = Fx.none;
public ChargeTurret(String name){
super(name);

View File

@ -17,8 +17,8 @@ import static io.anuke.mindustry.Vars.tilesize;
public class CooledTurret extends Turret{
/** How much reload is lowered by for each unit of liquid of heat capacity. */
protected float coolantMultiplier = 5f;
protected Effect coolEffect = Fx.fuelburn;
public float coolantMultiplier = 5f;
public Effect coolEffect = Fx.fuelburn;
public CooledTurret(String name){
super(name);

View File

@ -9,7 +9,7 @@ import io.anuke.mindustry.world.meta.StatUnit;
import static io.anuke.mindustry.Vars.tilesize;
public class DoubleTurret extends ItemTurret{
protected float shotWidth = 2f;
public float shotWidth = 2f;
public DoubleTurret(String name){
super(name);

View File

@ -22,8 +22,8 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class ItemTurret extends CooledTurret{
protected int maxAmmo = 30;
protected ObjectMap<Item, BulletType> ammo = new ObjectMap<>();
public int maxAmmo = 30;
public ObjectMap<Item, BulletType> ammo = new ObjectMap<>();
public ItemTurret(String name){
super(name);

View File

@ -14,8 +14,8 @@ import io.anuke.mindustry.world.meta.values.*;
import static io.anuke.mindustry.Vars.tilesize;
public class LaserTurret extends PowerTurret{
protected float firingMoveFract = 0.25f;
protected float shootDuration = 100f;
public float firingMoveFract = 0.25f;
public float shootDuration = 100f;
public LaserTurret(String name){
super(name);

View File

@ -15,7 +15,7 @@ import io.anuke.mindustry.world.meta.values.*;
import static io.anuke.mindustry.Vars.*;
public class LiquidTurret extends Turret{
protected ObjectMap<Liquid, BulletType> ammo = new ObjectMap<>();
public ObjectMap<Liquid, BulletType> ammo = new ObjectMap<>();
public LiquidTurret(String name){
super(name);

View File

@ -7,8 +7,8 @@ import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
public class PowerTurret extends CooledTurret{
protected @NonNull BulletType shootType;
protected float powerUse = 1f;
public @NonNull BulletType shootType;
public float powerUse = 1f;
public PowerTurret(String name){
super(name);

View File

@ -28,40 +28,39 @@ import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.tilesize;
public abstract class Turret extends Block{
protected static final int targetInterval = 20;
public final int timerTarget = timers++;
public int targetInterval = 20;
protected final int timerTarget = timers++;
public Color heatColor = Pal.turretHeat;
public Effect shootEffect = Fx.none;
public Effect smokeEffect = Fx.none;
public Effect ammoUseEffect = Fx.none;
public Sound shootSound = Sounds.shoot;
protected Color heatColor = Pal.turretHeat;
protected Effect shootEffect = Fx.none;
protected Effect smokeEffect = Fx.none;
protected Effect ammoUseEffect = Fx.none;
protected Sound shootSound = Sounds.shoot;
protected int ammoPerShot = 1;
protected float ammoEjectBack = 1f;
protected float range = 50f;
protected float reload = 10f;
protected float inaccuracy = 0f;
protected int shots = 1;
protected float spread = 4f;
protected float recoil = 1f;
protected float restitution = 0.02f;
protected float cooldown = 0.02f;
protected float rotatespeed = 5f; //in degrees per tick
protected float shootCone = 8f;
protected float shootShake = 0f;
protected float xRand = 0f;
protected boolean targetAir = true;
protected boolean targetGround = true;
public int ammoPerShot = 1;
public float ammoEjectBack = 1f;
public float range = 50f;
public float reload = 10f;
public float inaccuracy = 0f;
public int shots = 1;
public float spread = 4f;
public float recoil = 1f;
public float restitution = 0.02f;
public float cooldown = 0.02f;
public float rotatespeed = 5f; //in degrees per tick
public float shootCone = 8f;
public float shootShake = 0f;
public float xRand = 0f;
public boolean targetAir = true;
public boolean targetGround = true;
protected Vector2 tr = new Vector2();
protected Vector2 tr2 = new Vector2();
protected TextureRegion baseRegion, heatRegion;
public TextureRegion baseRegion, heatRegion;
protected Cons2<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
protected Cons2<Tile, TurretEntity> heatDrawer = (tile, entity) -> {
public Cons2<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
public Cons2<Tile, TurretEntity> heatDrawer = (tile, entity) -> {
if(entity.heat <= 0.00001f) return;
Draw.color(heatColor, entity.heat);
Draw.blend(Blending.additive);

View File

@ -7,10 +7,10 @@ import io.anuke.mindustry.world.*;
import java.io.*;
public class BufferedItemBridge extends ExtendingItemBridge{
protected int timerAccept = timers++;
public final int timerAccept = timers++;
protected float speed = 40f;
protected int bufferCapacity = 50;
public float speed = 40f;
public int bufferCapacity = 50;
public BufferedItemBridge(String name){
super(name);

View File

@ -32,7 +32,7 @@ public class Conveyor extends Block implements Autotiler{
private final Vector2 tr2 = new Vector2();
private TextureRegion[][] regions = new TextureRegion[7][4];
protected float speed = 0f;
public float speed = 0f;
protected Conveyor(String name){
super(name);

View File

@ -20,12 +20,12 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class ItemBridge extends Block{
protected int timerTransport = timers++;
protected int range;
protected float transportTime = 2f;
protected TextureRegion endRegion, bridgeRegion, arrowRegion;
protected BuildRequest otherReq;
public final int timerTransport = timers++;
public int range;
public float transportTime = 2f;
public TextureRegion endRegion, bridgeRegion, arrowRegion;
private static BuildRequest otherReq;
private static int lastPlaced = Pos.invalid;
public ItemBridge(String name){

View File

@ -17,8 +17,8 @@ import java.io.IOException;
import static io.anuke.mindustry.Vars.content;
public class Junction extends Block{
protected float speed = 26; //frames taken to go through this junction
protected int capacity = 6;
public float speed = 26; //frames taken to go through this junction
public int capacity = 6;
public Junction(String name){
super(name);

View File

@ -20,17 +20,17 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class MassDriver extends Block{
protected float range;
protected float rotateSpeed = 0.04f;
protected float translation = 7f;
protected int minDistribute = 10;
protected float knockback = 4f;
protected float reloadTime = 100f;
protected Effect shootEffect = Fx.shootBig2;
protected Effect smokeEffect = Fx.shootBigSmoke2;
protected Effect recieveEffect = Fx.mineBig;
protected float shake = 3f;
protected TextureRegion baseRegion;
public float range;
public float rotateSpeed = 0.04f;
public float translation = 7f;
public int minDistribute = 10;
public float knockback = 4f;
public float reloadTime = 100f;
public Effect shootEffect = Fx.shootBig2;
public Effect smokeEffect = Fx.shootBigSmoke2;
public Effect recieveEffect = Fx.mineBig;
public float shake = 3f;
public TextureRegion baseRegion;
public MassDriver(String name){
super(name);

View File

@ -10,7 +10,7 @@ import io.anuke.mindustry.world.meta.BlockGroup;
import java.io.*;
public class OverflowGate extends Block{
protected float speed = 1f;
public float speed = 1f;
public OverflowGate(String name){
super(name);

View File

@ -9,7 +9,7 @@ import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.BlockGroup;
public class Router extends Block{
protected float speed = 8f;
public float speed = 8f;
public Router(String name){
super(name);

View File

@ -18,7 +18,7 @@ import static io.anuke.mindustry.Vars.content;
public class Sorter extends Block{
private static Item lastItem;
protected boolean invert;
public boolean invert;
public Sorter(String name){
super(name);

View File

@ -9,7 +9,7 @@ import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile;
public class ArmoredConduit extends Conduit{
protected TextureRegion capRegion;
public TextureRegion capRegion;
public ArmoredConduit(String name){
super(name);

View File

@ -16,12 +16,12 @@ import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.modules.*;
public class Conduit extends LiquidBlock implements Autotiler{
protected final int timerFlow = timers++;
public final int timerFlow = timers++;
protected TextureRegion[] topRegions = new TextureRegion[7];
protected TextureRegion[] botRegions = new TextureRegion[7];
public TextureRegion[] topRegions = new TextureRegion[7];
public TextureRegion[] botRegions = new TextureRegion[7];
protected float leakResistance = 1.5f;
public float leakResistance = 1.5f;
public Conduit(String name){
super(name);

View File

@ -9,7 +9,7 @@ import io.anuke.mindustry.world.meta.*;
//TODO implement later
public class LiquidOverflowGate extends LiquidBlock{
int topRegion;
public int topRegion;
public LiquidOverflowGate(String name){
super(name);

View File

@ -19,17 +19,17 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class ImpactReactor extends PowerGenerator{
protected int timerUse = timers++;
public final int timerUse = timers++;
protected int plasmas = 4;
protected float warmupSpeed = 0.001f;
protected float itemDuration = 60f;
protected int explosionRadius = 50;
protected int explosionDamage = 2000;
public int plasmas = 4;
public float warmupSpeed = 0.001f;
public float itemDuration = 60f;
public int explosionRadius = 50;
public int explosionDamage = 2000;
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
protected int bottomRegion;
protected int[] plasmaRegions;
public Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
public int bottomRegion;
public int[] plasmaRegions;
public ImpactReactor(String name){
super(name);

View File

@ -20,20 +20,20 @@ import static io.anuke.mindustry.Vars.*;
* Liquids will take priority over items.
*/
public class ItemLiquidGenerator extends PowerGenerator{
protected float minItemEfficiency = 0.2f;
public float minItemEfficiency = 0.2f;
/** The time in number of ticks during which a single item will produce power. */
protected float itemDuration = 70f;
public float itemDuration = 70f;
protected float minLiquidEfficiency = 0.2f;
public float minLiquidEfficiency = 0.2f;
/** Maximum liquid used per frame. */
protected float maxLiquidGenerate = 0.4f;
public float maxLiquidGenerate = 0.4f;
protected Effect generateEffect = Fx.generatespark;
protected Effect explodeEffect = Fx.generatespark;
protected Color heatColor = Color.valueOf("ff9b59");
protected TextureRegion topRegion, liquidRegion;
protected boolean randomlyExplode = true;
protected boolean defaults = false;
public Effect generateEffect = Fx.generatespark;
public Effect explodeEffect = Fx.generatespark;
public Color heatColor = Color.valueOf("ff9b59");
public TextureRegion topRegion, liquidRegion;
public boolean randomlyExplode = true;
public boolean defaults = false;
public ItemLiquidGenerator(boolean hasItems, boolean hasLiquids, String name){
this(name);

View File

@ -16,9 +16,9 @@ import static io.anuke.mindustry.Vars.*;
public class LightBlock extends Block{
private static int lastColor = 0;
protected float brightness = 0.9f;
protected float radius = 200f;
protected int topRegion;
public float brightness = 0.9f;
public float radius = 200f;
public int topRegion;
public LightBlock(String name){
super(name);

View File

@ -22,22 +22,22 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class NuclearReactor extends PowerGenerator{
protected final int timerFuel = timers++;
public final int timerFuel = timers++;
protected final Vector2 tr = new Vector2();
public final Vector2 tr = new Vector2();
protected Color lightColor = Color.valueOf("7f19ea");
protected Color coolColor = new Color(1, 1, 1, 0f);
protected Color hotColor = Color.valueOf("ff9575a3");
protected float itemDuration = 120; //time to consume 1 fuel
protected float heating = 0.01f; //heating per frame * fullness
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
protected int explosionRadius = 40;
protected int explosionDamage = 1350;
protected float flashThreshold = 0.46f; //heat threshold at which the lights start flashing
protected float coolantPower = 0.5f;
public Color lightColor = Color.valueOf("7f19ea");
public Color coolColor = new Color(1, 1, 1, 0f);
public Color hotColor = Color.valueOf("ff9575a3");
public float itemDuration = 120; //time to consume 1 fuel
public float heating = 0.01f; //heating per frame * fullness
public float smokeThreshold = 0.3f; //threshold at which block starts smoking
public int explosionRadius = 40;
public int explosionDamage = 1350;
public float flashThreshold = 0.46f; //heat threshold at which the lights start flashing
public float coolantPower = 0.5f;
protected TextureRegion topRegion, lightsRegion;
public TextureRegion topRegion, lightsRegion;
public NuclearReactor(String name){
super(name);

View File

@ -13,7 +13,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.traits.BuilderTrait;
public class PowerDiode extends Block{
protected TextureRegion arrow;
public TextureRegion arrow;
public PowerDiode(String name){
super(name);
@ -50,7 +50,7 @@ public class PowerDiode extends Block{
}
// battery % of the graph on either side, defaults to zero
protected float bar(Tile tile){
public float bar(Tile tile){
return (tile != null && tile.block().hasPower) ? tile.entity.power.graph.getBatteryStored() / tile.entity.power.graph.getTotalBatteryCapacity() : 0f;
}

View File

@ -13,7 +13,7 @@ import java.io.*;
public class PowerGenerator extends PowerDistributor{
/** The amount of power produced per tick in case of an efficiency of 1.0, which represents 100%. */
protected float powerProduction;
public float powerProduction;
public BlockStat generationType = BlockStat.basePowerGeneration;
public PowerGenerator(String name){

View File

@ -21,12 +21,12 @@ import static io.anuke.mindustry.Vars.*;
public class PowerNode extends PowerBlock{
protected static boolean returnValue = false;
protected ObjectSet<PowerGraph> graphs = new ObjectSet<>();
protected Vector2 t1 = new Vector2(), t2 = new Vector2();
protected TextureRegion laser, laserEnd;
protected final ObjectSet<PowerGraph> graphs = new ObjectSet<>();
protected final Vector2 t1 = new Vector2(), t2 = new Vector2();
protected float laserRange = 6;
protected int maxNodes = 3;
public TextureRegion laser, laserEnd;
public float laserRange = 6;
public int maxNodes = 3;
public PowerNode(String name){
super(name);

View File

@ -12,7 +12,7 @@ import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.renderer;
public class ThermalGenerator extends PowerGenerator{
protected Effect generateEffect = Fx.none;
public Effect generateEffect = Fx.none;
public ThermalGenerator(String name){
super(name);

View File

@ -16,14 +16,14 @@ import io.anuke.mindustry.world.meta.Attribute;
import java.io.*;
public class Cultivator extends GenericCrafter{
protected static final Color plantColor = Color.valueOf("5541b1");
protected static final Color plantColorLight = Color.valueOf("7457ce");
protected static final Color bottomColor = Color.valueOf("474747");
public Color plantColor = Color.valueOf("5541b1");
public Color plantColorLight = Color.valueOf("7457ce");
public Color bottomColor = Color.valueOf("474747");
protected TextureRegion middleRegion, topRegion;
protected RandomXS128 random = new RandomXS128(0);
protected float recurrence = 6f;
protected Attribute attribute = Attribute.spores;
public TextureRegion middleRegion, topRegion;
public RandomXS128 random = new RandomXS128(0);
public float recurrence = 6f;
public Attribute attribute = Attribute.spores;
public Cultivator(String name){
super(name);

View File

@ -21,41 +21,40 @@ import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.*;
public class Drill extends Block{
protected final static float hardnessDrillMultiplier = 50f;
public float hardnessDrillMultiplier = 50f;
protected final ObjectIntMap<Item> oreCount = new ObjectIntMap<>();
protected final Array<Item> itemArray = new Array<>();
/** Maximum tier of blocks this drill can mine. */
protected int tier;
public int tier;
/** Base time to drill one ore, in frames. */
protected float drillTime = 300;
public float drillTime = 300;
/** How many times faster the drill will progress when boosted by liquid. */
protected float liquidBoostIntensity = 1.6f;
public float liquidBoostIntensity = 1.6f;
/** Speed at which the drill speeds up. */
protected float warmupSpeed = 0.02f;
public float warmupSpeed = 0.02f;
//return variables for countOre
protected Item returnItem;
protected int returnCount;
/** Whether to draw the item this drill is mining. */
protected boolean drawMineItem = false;
public boolean drawMineItem = false;
/** Effect played when an item is produced. This is colored. */
protected Effect drillEffect = Fx.mine;
public Effect drillEffect = Fx.mine;
/** Speed the drill bit rotates at. */
protected float rotateSpeed = 2f;
public float rotateSpeed = 2f;
/** Effect randomly played while drilling. */
protected Effect updateEffect = Fx.pulverizeSmall;
public Effect updateEffect = Fx.pulverizeSmall;
/** Chance the update effect will appear. */
protected float updateEffectChance = 0.02f;
public float updateEffectChance = 0.02f;
protected boolean drawRim = false;
protected Color heatColor = Color.valueOf("ff5512");
protected TextureRegion rimRegion;
protected TextureRegion rotatorRegion;
protected TextureRegion topRegion;
public boolean drawRim = false;
public Color heatColor = Color.valueOf("ff5512");
public TextureRegion rimRegion;
public TextureRegion rotatorRegion;
public TextureRegion topRegion;
public Drill(String name){
super(name);

View File

@ -6,11 +6,11 @@ import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.*;
public class Fracker extends SolidPump{
protected final float itemUseTime = 100f;
public float itemUseTime = 100f;
protected TextureRegion liquidRegion;
protected TextureRegion rotatorRegion;
protected TextureRegion topRegion;
public TextureRegion liquidRegion;
public TextureRegion rotatorRegion;
public TextureRegion topRegion;
public Fracker(String name){
super(name);

View File

@ -17,16 +17,16 @@ import io.anuke.mindustry.world.meta.*;
import java.io.*;
public class GenericCrafter extends Block{
protected ItemStack outputItem;
protected LiquidStack outputLiquid;
public ItemStack outputItem;
public LiquidStack outputLiquid;
protected float craftTime = 80;
protected Effect craftEffect = Fx.none;
protected Effect updateEffect = Fx.none;
protected float updateEffectChance = 0.04f;
public float craftTime = 80;
public Effect craftEffect = Fx.none;
public Effect updateEffect = Fx.none;
public float updateEffectChance = 0.04f;
protected Cons<Tile> drawer = null;
protected Prov<TextureRegion[]> drawIcons = null;
public Cons<Tile> drawer = null;
public Prov<TextureRegion[]> drawIcons = null;
public GenericCrafter(String name){
super(name);

View File

@ -11,8 +11,8 @@ import static io.anuke.mindustry.Vars.renderer;
/** A GenericCrafter with a new glowing region drawn on top. */
public class GenericSmelter extends GenericCrafter{
protected Color flameColor = Color.valueOf("ffc999");
protected TextureRegion topRegion;
public Color flameColor = Color.valueOf("ffc999");
public TextureRegion topRegion;
public GenericSmelter(String name){
super(name);

View File

@ -15,8 +15,8 @@ import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
public class Incinerator extends Block{
protected Effect effect = Fx.fuelburn;
protected Color flameColor = Color.valueOf("ffad9d");
public Effect effect = Fx.fuelburn;
public Color flameColor = Color.valueOf("ffad9d");
public Incinerator(String name){
super(name);

View File

@ -19,7 +19,7 @@ public class Pump extends LiquidBlock{
protected final Array<Tile> drawTiles = new Array<>();
protected final Array<Tile> updateTiles = new Array<>();
protected final int timerContentCheck = timers++;
public final int timerContentCheck = timers++;
/** Pump amount, total. */
protected float pumpAmount = 1f;

View File

@ -20,12 +20,12 @@ import io.anuke.mindustry.world.meta.BlockStat;
* Pump that makes liquid from solids and takes in power. Only works on solid floor blocks.
*/
public class SolidPump extends Pump{
protected Liquid result = Liquids.water;
protected Effect updateEffect = Fx.none;
protected float updateEffectChance = 0.02f;
protected float rotateSpeed = 1f;
public Liquid result = Liquids.water;
public Effect updateEffect = Fx.none;
public float updateEffectChance = 0.02f;
public float rotateSpeed = 1f;
/** Attribute that is checked when calculating output. */
protected Attribute attribute;
public Attribute attribute;
public SolidPump(String name){
super(name);

View File

@ -21,7 +21,7 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class LiquidSource extends Block{
private static Liquid lastLiquid;
public static Liquid lastLiquid;
public LiquidSource(String name){
super(name);

View File

@ -24,7 +24,7 @@ import io.anuke.mindustry.world.modules.*;
import static io.anuke.mindustry.Vars.*;
public class CoreBlock extends StorageBlock{
protected Mech mech = Mechs.starter;
public Mech mech = Mechs.starter;
public CoreBlock(String name){
super(name);

View File

@ -21,9 +21,9 @@ import static io.anuke.mindustry.Vars.data;
import static io.anuke.mindustry.Vars.world;
public class LaunchPad extends StorageBlock{
protected final int timerLaunch = timers++;
public final int timerLaunch = timers++;
/** Time inbetween launches. */
protected float launchTime;
public float launchTime;
public LaunchPad(String name){
super(name);

View File

@ -15,8 +15,8 @@ import java.io.*;
import static io.anuke.mindustry.Vars.content;
public class Unloader extends Block{
protected float speed = 1f;
protected final int timerUnload = timers++;
public float speed = 1f;
public final int timerUnload = timers++;
private static Item lastItem;

View File

@ -26,7 +26,7 @@ import static io.anuke.mindustry.Vars.*;
public class MechPad extends Block{
public @NonNull Mech mech;
protected float buildTime = 60 * 5;
public float buildTime = 60 * 5;
public MechPad(String name){
super(name);

View File

@ -19,13 +19,13 @@ import io.anuke.mindustry.world.meta.BlockFlag;
public class RepairPoint extends Block{
private static Rectangle rect = new Rectangle();
protected int timerTarget = timers++;
public int timerTarget = timers++;
protected float repairRadius = 50f;
protected float repairSpeed = 0.3f;
protected float powerUse;
protected TextureRegion baseRegion;
protected TextureRegion laser, laserEnd;
public float repairRadius = 50f;
public float repairSpeed = 0.3f;
public float powerUse;
public TextureRegion baseRegion;
public TextureRegion laser, laserEnd;
public RepairPoint(String name){
super(name);

View File

@ -27,12 +27,12 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class UnitFactory extends Block{
protected UnitType unitType;
protected float produceTime = 1000f;
protected float launchVelocity = 0f;
protected TextureRegion topRegion;
protected int maxSpawn = 4;
protected int[] capacities;
public UnitType unitType;
public float produceTime = 1000f;
public float launchVelocity = 0f;
public TextureRegion topRegion;
public int maxSpawn = 4;
public int[] capacities;
public UnitFactory(String name){
super(name);

View File

@ -19,7 +19,7 @@ import io.anuke.arc.util.io.*;
import io.anuke.arc.util.serialization.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.core.Version;
import io.anuke.mindustry.core.*;
import io.anuke.mindustry.desktop.steam.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.mod.Mods.*;

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=2caecb328322b840a760dbb8877952867abd54d1
archash=6d310772fec1f69efeae2e487cab3bd64728ae05

View File

@ -33,7 +33,9 @@ public class MindustryServer implements ApplicationListener{
Vars.loadSettings();
Vars.init();
content.createContent();
content.createBaseContent();
mods.loadScripts();
content.createModContent();
content.init();
Core.app.addListener(logic = new Logic());

View File

@ -47,7 +47,7 @@ public class ApplicationTests{
net = new Net(null);
tree = new FileTree();
Vars.init();
content.createContent();
content.createBaseContent();
add(logic = new Logic());
add(netServer = new NetServer());

View File

@ -33,7 +33,7 @@ public class PowerTestFixture{
}
};
content.createContent();
content.createBaseContent();
Log.setUseColors(false);
Time.setDeltaProvider(() -> 0.5f);
}

View File

@ -297,7 +297,7 @@ task pack(dependsOn: classes){
//run generation task; generate all needed sprites
file(genFolder).mkdirs()
javaexec{
main = "io.anuke.mindustry.ImagePacker"
main = "io.anuke.mindustry.tools.ImagePacker"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = genFolder
@ -310,7 +310,7 @@ task pack(dependsOn: classes){
}
jvmArgs("-Djava.awt.headless=true")
main = "io.anuke.mindustry.Upscaler"
main = "io.anuke.mindustry.tools.Upscaler"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../core/assets-raw/sprites_out/ui/icons"
@ -351,7 +351,7 @@ task pack(dependsOn: classes){
task genSprites(dependsOn: classes, type: JavaExec){
finalizedBy 'antialiasGen'
main = "io.anuke.mindustry.ImagePacker"
main = "io.anuke.mindustry.tools.ImagePacker"
classpath = sourceSets.main.runtimeClasspath
jvmArgs("-Djava.awt.headless=true")
standardInput = System.in
@ -361,7 +361,7 @@ task genSprites(dependsOn: classes, type: JavaExec){
task updateBundles(dependsOn: classes, type: JavaExec){
file(genFolder).mkdirs()
main = "io.anuke.mindustry.BundleLauncher"
main = "io.anuke.mindustry.tools.BundleLauncher"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../core/assets/bundles/"

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.OrderedMap;

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*;
@ -6,7 +6,7 @@ import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.noise.*;
import io.anuke.mindustry.ImagePacker.*;
import io.anuke.mindustry.tools.ImagePacker.*;
import io.anuke.mindustry.ctype.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.*;

View File

@ -1,9 +1,9 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.ImagePacker.GenRegion;
import io.anuke.mindustry.tools.ImagePacker.GenRegion;
import javax.imageio.ImageIO;
import java.awt.*;

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.Core;
import io.anuke.arc.collection.ObjectMap;
@ -7,6 +7,7 @@ import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
import io.anuke.arc.util.*;
import io.anuke.arc.util.Log.LogHandler;
import io.anuke.arc.util.Log.NoopLogHandler;
import io.anuke.mindustry.*;
import io.anuke.mindustry.core.ContentLoader;
import javax.imageio.ImageIO;
@ -23,7 +24,7 @@ public class ImagePacker{
Log.setLogger(new NoopLogHandler());
Vars.content = new ContentLoader();
Vars.content.createContent();
Vars.content.createBaseContent();
Log.setLogger(new LogHandler());
Files.walk(Paths.get("../../../assets-raw/sprites_out")).forEach(path -> {

View File

@ -0,0 +1,78 @@
package io.anuke.mindustry.tools;
import io.anuke.arc.*;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.TextureAtlas.*;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import org.reflections.*;
import org.reflections.scanners.*;
import org.reflections.util.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
public class ScriptStubGenerator{
public static void main(String[] args){
String base = "io.anuke.mindustry";
Array<String> blacklist = Array.with("plugin", "mod", "net", "io", "tools", "gen");
Array<String> nameBlacklist = Array.with("ClientLauncher", "NetClient", "NetServer", "ClassAccess");
Array<Class<?>> whitelist = Array.with(Draw.class, Fill.class, Lines.class, Core.class, TextureAtlas.class, TextureRegion.class, Time.class, System.class, PrintStream.class, AtlasRegion.class, String.class, Mathf.class, Angles.class, Color.class);
Array<String> nopackage = Array.with("io.anuke.arc.func", "java.lang", "java");
Array<String> imported = Array.with("io.anuke.mindustry.type", "io.anuke.mindustry.world");
String fileTemplate = "package io.anuke.mindustry.mod;\n" +
"\n" +
"import io.anuke.arc.collection.*;\n" +
"//obviously autogenerated, do not touch\n" +
"public class ClassAccess{\n" +
//"\tstatic final Array<Class<?>> allowedClasses = Array.with($ALLOWED_CLASSES$);\n" +
"\tpublic static final ObjectSet<String> allowedClassNames = ObjectSet.with($ALLOWED_CLASS_NAMES$);\n" +
"}";
List<ClassLoader> classLoadersList = new LinkedList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder()
.include(FilterBuilder.prefix("io.anuke.mindustry"))
.include(FilterBuilder.prefix("io.anuke.arc.func"))
.include(FilterBuilder.prefix("io.anuke.arc.collection"))
.include(FilterBuilder.prefix("io.anuke.arc.scene"))
));
Array<Class<?>> classes = Array.with(reflections.getSubTypesOf(Object.class));
classes.addAll(reflections.getSubTypesOf(Enum.class));
classes.addAll(whitelist);
classes.sort(Structs.comparing(Class::getName));
classes.removeAll(type -> type.isSynthetic() || type.isAnonymousClass() || type.getCanonicalName() == null || Modifier.isPrivate(type.getModifiers())
|| blacklist.contains(s -> type.getName().startsWith(base + "." + s + ".")) || nameBlacklist.contains(type.getSimpleName()));
classes.distinct();
ObjectSet<String> used = ObjectSet.with();
StringBuilder result = new StringBuilder("//Generated class. Do not modify.\n");
result.append("\n").append(new FileHandle("core/assets/scripts/base.js").readString()).append("\n");
for(Class type : classes){
if(used.contains(type.getPackage().getName()) || nopackage.contains(s -> type.getName().startsWith(s))) continue;
result.append("importPackage(Packages.").append(type.getPackage().getName()).append(")\n");
used.add(type.getPackage().getName());
}
//Log.info(result);
new FileHandle("core/assets/scripts/global.js").writeString(result.toString());
new FileHandle("core/src/io/anuke/mindustry/mod/ClassAccess.java").writeString(fileTemplate
.replace("$ALLOWED_CLASSES$", classes.toString(", ", type -> type.getName() + ".class"))
.replace("$ALLOWED_CLASS_NAMES$", classes.toString(", ", type -> "\"" + type.getName() + "\"")));
}
}

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.Core;
import io.anuke.arc.files.FileHandle;

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry;
package io.anuke.mindustry.tools;
import io.anuke.arc.*;
import io.anuke.arc.backends.sdl.*;