Misc cleanup & fixes
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function log(context, obj){
|
let scriptName = "base.js"
|
||||||
Vars.mods.scripts.log(context, String(obj))
|
let modName = "none"
|
||||||
}
|
|
||||||
|
|
||||||
|
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||||
|
const print = text => log(modName + "/" + scriptName, text)
|
||||||
const readString = path => Vars.mods.scripts.readString(path)
|
const readString = path => Vars.mods.scripts.readString(path)
|
||||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
||||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
||||||
@@ -13,11 +14,20 @@ const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext
|
|||||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
||||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
||||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
||||||
|
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||||
|
|
||||||
let scriptName = "base.js"
|
//these are not strictly necessary, but are kept for edge cases
|
||||||
let modName = "none"
|
const run = method => new java.lang.Runnable(){run: method}
|
||||||
|
const boolf = method => new Boolf(){get: method}
|
||||||
|
const boolp = method => new Boolp(){get: method}
|
||||||
|
const floatf = method => new Floatf(){get: method}
|
||||||
|
const floatp = method => new Floatp(){get: method}
|
||||||
|
const cons = method => new Cons(){get: method}
|
||||||
|
const prov = method => new Prov(){get: method}
|
||||||
|
const func = method => new Func(){get: method}
|
||||||
|
|
||||||
const print = text => log(modName + "/" + scriptName, text);
|
const newEffect = (lifetime, renderer) => new Effect.Effect(lifetime, new Effect.EffectRenderer({render: renderer}))
|
||||||
|
Call = Packages.mindustry.gen.Call
|
||||||
|
|
||||||
//js 'extend(Base, ..., {})' = java 'new Base(...) {}'
|
//js 'extend(Base, ..., {})' = java 'new Base(...) {}'
|
||||||
function extend(/*Base, ..., def*/){
|
function extend(/*Base, ..., def*/){
|
||||||
@@ -39,16 +49,3 @@ function extend(/*Base, ..., def*/){
|
|||||||
|
|
||||||
//For backwards compatibility, use extend instead
|
//For backwards compatibility, use extend instead
|
||||||
const extendContent = extend;
|
const extendContent = extend;
|
||||||
|
|
||||||
//these are not strictly necessary, but are kept for edge cases
|
|
||||||
const run = method => new java.lang.Runnable(){run: method}
|
|
||||||
const boolf = method => new Boolf(){get: method}
|
|
||||||
const boolp = method => new Boolp(){get: method}
|
|
||||||
const floatf = method => new Floatf(){get: method}
|
|
||||||
const floatp = method => new Floatp(){get: method}
|
|
||||||
const cons = method => new Cons(){get: method}
|
|
||||||
const prov = method => new Prov(){get: method}
|
|
||||||
const func = method => new Func(){get: method}
|
|
||||||
|
|
||||||
const newEffect = (lifetime, renderer) => new Effect.Effect(lifetime, new Effect.EffectRenderer({render: renderer}))
|
|
||||||
Call = Packages.mindustry.gen.Call
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function log(context, obj){
|
let scriptName = "base.js"
|
||||||
Vars.mods.scripts.log(context, String(obj))
|
let modName = "none"
|
||||||
}
|
|
||||||
|
|
||||||
|
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||||
|
const print = text => log(modName + "/" + scriptName, text)
|
||||||
const readString = path => Vars.mods.scripts.readString(path)
|
const readString = path => Vars.mods.scripts.readString(path)
|
||||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
||||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
||||||
@@ -15,11 +16,20 @@ const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext
|
|||||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
||||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
||||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
||||||
|
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||||
|
|
||||||
let scriptName = "base.js"
|
//these are not strictly necessary, but are kept for edge cases
|
||||||
let modName = "none"
|
const run = method => new java.lang.Runnable(){run: method}
|
||||||
|
const boolf = method => new Boolf(){get: method}
|
||||||
|
const boolp = method => new Boolp(){get: method}
|
||||||
|
const floatf = method => new Floatf(){get: method}
|
||||||
|
const floatp = method => new Floatp(){get: method}
|
||||||
|
const cons = method => new Cons(){get: method}
|
||||||
|
const prov = method => new Prov(){get: method}
|
||||||
|
const func = method => new Func(){get: method}
|
||||||
|
|
||||||
const print = text => log(modName + "/" + scriptName, text);
|
const newEffect = (lifetime, renderer) => new Effect.Effect(lifetime, new Effect.EffectRenderer({render: renderer}))
|
||||||
|
Call = Packages.mindustry.gen.Call
|
||||||
|
|
||||||
//js 'extend(Base, ..., {})' = java 'new Base(...) {}'
|
//js 'extend(Base, ..., {})' = java 'new Base(...) {}'
|
||||||
function extend(/*Base, ..., def*/){
|
function extend(/*Base, ..., def*/){
|
||||||
@@ -42,19 +52,6 @@ function extend(/*Base, ..., def*/){
|
|||||||
//For backwards compatibility, use extend instead
|
//For backwards compatibility, use extend instead
|
||||||
const extendContent = extend;
|
const extendContent = extend;
|
||||||
|
|
||||||
//these are not strictly necessary, but are kept for edge cases
|
|
||||||
const run = method => new java.lang.Runnable(){run: method}
|
|
||||||
const boolf = method => new Boolf(){get: method}
|
|
||||||
const boolp = method => new Boolp(){get: method}
|
|
||||||
const floatf = method => new Floatf(){get: method}
|
|
||||||
const floatp = method => new Floatp(){get: method}
|
|
||||||
const cons = method => new Cons(){get: method}
|
|
||||||
const prov = method => new Prov(){get: method}
|
|
||||||
const func = method => new Func(){get: method}
|
|
||||||
|
|
||||||
const newEffect = (lifetime, renderer) => new Effect.Effect(lifetime, new Effect.EffectRenderer({render: renderer}))
|
|
||||||
Call = Packages.mindustry.gen.Call
|
|
||||||
|
|
||||||
importPackage(Packages.arc)
|
importPackage(Packages.arc)
|
||||||
importPackage(Packages.arc.func)
|
importPackage(Packages.arc.func)
|
||||||
importPackage(Packages.arc.graphics)
|
importPackage(Packages.arc.graphics)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
public @Nullable Bloom bloom;
|
public @Nullable Bloom bloom;
|
||||||
public FrameBuffer effectBuffer = new FrameBuffer();
|
public FrameBuffer effectBuffer = new FrameBuffer();
|
||||||
public boolean animateShields, drawWeather = true;
|
public boolean animateShields, drawWeather = true, drawStatus;
|
||||||
/** minZoom = zooming out, maxZoom = zooming in */
|
/** minZoom = zooming out, maxZoom = zooming in */
|
||||||
public float minZoom = 1.5f, maxZoom = 6f;
|
public float minZoom = 1.5f, maxZoom = 6f;
|
||||||
|
|
||||||
@@ -81,6 +81,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
laserOpacity = settings.getInt("lasersopacity") / 100f;
|
laserOpacity = settings.getInt("lasersopacity") / 100f;
|
||||||
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
|
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
|
||||||
animateShields = settings.getBool("animatedshields");
|
animateShields = settings.getBool("animatedshields");
|
||||||
|
drawStatus = Core.settings.getBool("blockstatus");
|
||||||
|
|
||||||
if(landTime > 0){
|
if(landTime > 0){
|
||||||
landTime -= Time.delta;
|
landTime -= Time.delta;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class BlockRenderer implements Disposable{
|
|||||||
private Seq<Building> outArray2 = new Seq<>();
|
private Seq<Building> outArray2 = new Seq<>();
|
||||||
private Seq<Tile> shadowEvents = new Seq<>();
|
private Seq<Tile> shadowEvents = new Seq<>();
|
||||||
private IntSet procEntities = new IntSet(), procLinks = new IntSet(), procLights = new IntSet();
|
private IntSet procEntities = new IntSet(), procLinks = new IntSet(), procLights = new IntSet();
|
||||||
private boolean displayStatus = false;
|
|
||||||
|
|
||||||
public BlockRenderer(){
|
public BlockRenderer(){
|
||||||
|
|
||||||
@@ -177,7 +176,6 @@ public class BlockRenderer implements Disposable{
|
|||||||
|
|
||||||
/** Process all blocks to draw. */
|
/** Process all blocks to draw. */
|
||||||
public void processBlocks(){
|
public void processBlocks(){
|
||||||
displayStatus = Core.settings.getBool("blockstatus");
|
|
||||||
|
|
||||||
int avgx = (int)(camera.position.x / tilesize);
|
int avgx = (int)(camera.position.x / tilesize);
|
||||||
int avgy = (int)(camera.position.y / tilesize);
|
int avgy = (int)(camera.position.y / tilesize);
|
||||||
@@ -275,7 +273,7 @@ public class BlockRenderer implements Disposable{
|
|||||||
Draw.z(Layer.block);
|
Draw.z(Layer.block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(displayStatus && block.consumes.any()){
|
if(renderer.drawStatus && block.consumes.any()){
|
||||||
entity.drawStatus();
|
entity.drawStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,22 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
public class Drawf{
|
public class Drawf{
|
||||||
|
|
||||||
|
public static void target(float x, float y, float rad, Color color){
|
||||||
|
target(x, y, rad, 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void target(float x, float y, float rad, float alpha, Color color){
|
||||||
|
Lines.stroke(3f);
|
||||||
|
Draw.color(Pal.gray, alpha);
|
||||||
|
Lines.poly(x, y, 4, rad, Time.time * 1.5f);
|
||||||
|
Lines.spikes(x, y, 3f/7f * rad, 6f/7f * rad, 4, Time.time * 1.5f);
|
||||||
|
Lines.stroke(1f);
|
||||||
|
Draw.color(color, alpha);
|
||||||
|
Lines.poly(x, y, 4, rad, Time.time * 1.5f);
|
||||||
|
Lines.spikes(x, y, 3f/7f * rad, 6f/7f * rad, 4, Time.time * 1.5f);
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
|
||||||
public static float text(){
|
public static float text(){
|
||||||
float z = Draw.z();
|
float z = Draw.z();
|
||||||
if(renderer.pixelator.enabled()){
|
if(renderer.pixelator.enabled()){
|
||||||
|
|||||||
@@ -374,13 +374,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
|
|
||||||
crosshairScale = Mathf.lerpDelta(crosshairScale, 1f, 0.2f);
|
crosshairScale = Mathf.lerpDelta(crosshairScale, 1f, 0.2f);
|
||||||
|
|
||||||
Draw.color(Pal.remove);
|
Drawf.target(target.getX(), target.getY(), 7f * Interp.swingIn.apply(crosshairScale), Pal.remove);
|
||||||
Lines.stroke(1f);
|
|
||||||
|
|
||||||
float radius = Interp.swingIn.apply(crosshairScale);
|
|
||||||
|
|
||||||
Lines.poly(target.getX(), target.getY(), 4, 7f * radius, Time.time * 1.5f);
|
|
||||||
Lines.spikes(target.getX(), target.getY(), 3f * radius, 6f * radius, 4, Time.time * 1.5f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ public class Scripts implements Disposable{
|
|||||||
|
|
||||||
//region utility mod functions
|
//region utility mod functions
|
||||||
|
|
||||||
|
public float[] newFloats(int capacity){
|
||||||
|
return new float[capacity];
|
||||||
|
}
|
||||||
|
|
||||||
public String readString(String path){
|
public String readString(String path){
|
||||||
return Vars.tree.get(path, true).readString();
|
return Vars.tree.get(path, true).readString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ public interface Payload{
|
|||||||
return size() / tilesize <= s;
|
return size() / tilesize <= s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return rotation of this payload. */
|
||||||
|
default float rotation(){
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
/** writes the payload for saving. */
|
/** writes the payload for saving. */
|
||||||
void write(Writes write);
|
void write(Writes write);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ public class UnitPayload implements Payload{
|
|||||||
@Override
|
@Override
|
||||||
public void set(float x, float y, float rotation){
|
public void set(float x, float y, float rotation){
|
||||||
unit.set(x, y);
|
unit.set(x, y);
|
||||||
unit.rotation(rotation);
|
unit.rotation = rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float rotation(){
|
||||||
|
return unit.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import mindustry.world.blocks.payloads.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class PayloadAcceptor extends Block{
|
public class PayloadAcceptor extends Block{
|
||||||
public float payloadSpeed = 0.5f;
|
public float payloadSpeed = 0.5f, payloadRotateSpeed = 5f;
|
||||||
|
|
||||||
public @Load(value = "@-top", fallback = "factory-top-@size") TextureRegion topRegion;
|
public @Load(value = "@-top", fallback = "factory-top-@size") TextureRegion topRegion;
|
||||||
public @Load(value = "@-out", fallback = "factory-out-@size") TextureRegion outRegion;
|
public @Load(value = "@-out", fallback = "factory-out-@size") TextureRegion outRegion;
|
||||||
@@ -66,7 +66,7 @@ public class PayloadAcceptor extends Block{
|
|||||||
public void handlePayload(Building source, Payload payload){
|
public void handlePayload(Building source, Payload payload){
|
||||||
this.payload = (T)payload;
|
this.payload = (T)payload;
|
||||||
this.payVector.set(source).sub(this).clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
this.payVector.set(source).sub(this).clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
||||||
this.payRotation = source.angleTo(this);
|
this.payRotation = payload.rotation();
|
||||||
|
|
||||||
updatePayload();
|
updatePayload();
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ public class PayloadAcceptor extends Block{
|
|||||||
|
|
||||||
updatePayload();
|
updatePayload();
|
||||||
|
|
||||||
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
payRotation = Angles.moveToward(payRotation, rotate ? rotdeg() : 90f, payloadRotateSpeed * edelta());
|
||||||
payVector.approach(Vec2.ZERO, payloadSpeed * delta());
|
payVector.approach(Vec2.ZERO, payloadSpeed * delta());
|
||||||
|
|
||||||
return hasArrived();
|
return hasArrived();
|
||||||
@@ -126,10 +126,12 @@ public class PayloadAcceptor extends Block{
|
|||||||
|
|
||||||
updatePayload();
|
updatePayload();
|
||||||
|
|
||||||
payVector.trns(rotdeg(), payVector.len() + delta() * payloadSpeed);
|
Vec2 dest = Tmp.v1.trns(rotdeg(), size* tilesize/2f);
|
||||||
payRotation = rotdeg();
|
|
||||||
|
|
||||||
if(payVector.len() >= size * tilesize/2f){
|
payRotation = Angles.moveToward(payRotation, rotdeg(), payloadRotateSpeed * edelta());
|
||||||
|
payVector.approach(dest, payloadSpeed * delta());
|
||||||
|
|
||||||
|
if(payVector.within(dest, 0.001f)){
|
||||||
payVector.clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
payVector.clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
||||||
|
|
||||||
Building front = front();
|
Building front = front();
|
||||||
@@ -155,7 +157,7 @@ public class PayloadAcceptor extends Block{
|
|||||||
|
|
||||||
public void drawPayload(){
|
public void drawPayload(){
|
||||||
if(payload != null){
|
if(payload != null){
|
||||||
payload.set(x + payVector.x, y + payVector.y, payRotation);
|
updatePayload();
|
||||||
|
|
||||||
Draw.z(Layer.blockOver);
|
Draw.z(Layer.blockOver);
|
||||||
payload.draw();
|
payload.draw();
|
||||||
|
|||||||
@@ -142,13 +142,12 @@ public class Reconstructor extends UnitBlock{
|
|||||||
if(constructing() && hasArrived()){
|
if(constructing() && hasArrived()){
|
||||||
Draw.draw(Layer.blockOver, () -> {
|
Draw.draw(Layer.blockOver, () -> {
|
||||||
Draw.alpha(1f - progress/ constructTime);
|
Draw.alpha(1f - progress/ constructTime);
|
||||||
Draw.rect(payload.unit.type.icon(Cicon.full), x, y, rotdeg() - 90);
|
Draw.rect(payload.unit.type.icon(Cicon.full), x, y, payload.rotation() - 90);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
Drawf.construct(this, upgrade(payload.unit.type), rotdeg() - 90f, progress / constructTime, speedScl, time);
|
Drawf.construct(this, upgrade(payload.unit.type), payload.rotation() - 90f, progress / constructTime, speedScl, time);
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
Draw.z(Layer.blockOver);
|
Draw.z(Layer.blockOver);
|
||||||
payRotation = rotdeg();
|
|
||||||
|
|
||||||
drawPayload();
|
drawPayload();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user