Misc cleanup & fixes

This commit is contained in:
Anuken 2021-01-19 15:13:41 -05:00
parent 40908589b9
commit e3f388692f
11 changed files with 78 additions and 60 deletions

View file

@ -1,9 +1,10 @@
"use strict";
function log(context, obj){
Vars.mods.scripts.log(context, String(obj))
}
let scriptName = "base.js"
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 readBytes = path => Vars.mods.scripts.readBytes(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 writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
let scriptName = "base.js"
let modName = "none"
//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 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(...) {}'
function extend(/*Base, ..., def*/){
@ -39,16 +49,3 @@ function extend(/*Base, ..., def*/){
//For backwards compatibility, use extend instead
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

View file

@ -2,10 +2,11 @@
"use strict";
function log(context, obj){
Vars.mods.scripts.log(context, String(obj))
}
let scriptName = "base.js"
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 readBytes = path => Vars.mods.scripts.readBytes(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 writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
let scriptName = "base.js"
let modName = "none"
//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 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(...) {}'
function extend(/*Base, ..., def*/){
@ -42,19 +52,6 @@ function extend(/*Base, ..., def*/){
//For backwards compatibility, use extend instead
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.func)
importPackage(Packages.arc.graphics)

View file

@ -33,7 +33,7 @@ public class Renderer implements ApplicationListener{
public @Nullable Bloom bloom;
public FrameBuffer effectBuffer = new FrameBuffer();
public boolean animateShields, drawWeather = true;
public boolean animateShields, drawWeather = true, drawStatus;
/** minZoom = zooming out, maxZoom = zooming in */
public float minZoom = 1.5f, maxZoom = 6f;
@ -81,6 +81,7 @@ public class Renderer implements ApplicationListener{
laserOpacity = settings.getInt("lasersopacity") / 100f;
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
animateShields = settings.getBool("animatedshields");
drawStatus = Core.settings.getBool("blockstatus");
if(landTime > 0){
landTime -= Time.delta;

View file

@ -39,7 +39,6 @@ public class BlockRenderer implements Disposable{
private Seq<Building> outArray2 = new Seq<>();
private Seq<Tile> shadowEvents = new Seq<>();
private IntSet procEntities = new IntSet(), procLinks = new IntSet(), procLights = new IntSet();
private boolean displayStatus = false;
public BlockRenderer(){
@ -177,7 +176,6 @@ public class BlockRenderer implements Disposable{
/** Process all blocks to draw. */
public void processBlocks(){
displayStatus = Core.settings.getBool("blockstatus");
int avgx = (int)(camera.position.x / tilesize);
int avgy = (int)(camera.position.y / tilesize);
@ -275,7 +273,7 @@ public class BlockRenderer implements Disposable{
Draw.z(Layer.block);
}
if(displayStatus && block.consumes.any()){
if(renderer.drawStatus && block.consumes.any()){
entity.drawStatus();
}
}

View file

@ -17,6 +17,22 @@ import static mindustry.Vars.*;
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(){
float z = Draw.z();
if(renderer.pixelator.enabled()){

View file

@ -374,13 +374,7 @@ public class MobileInput extends InputHandler implements GestureListener{
crosshairScale = Mathf.lerpDelta(crosshairScale, 1f, 0.2f);
Draw.color(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);
Drawf.target(target.getX(), target.getY(), 7f * Interp.swingIn.apply(crosshairScale), Pal.remove);
}
Draw.reset();

View file

@ -80,6 +80,10 @@ public class Scripts implements Disposable{
//region utility mod functions
public float[] newFloats(int capacity){
return new float[capacity];
}
public String readString(String path){
return Vars.tree.get(path, true).readString();
}

View file

@ -32,6 +32,11 @@ public interface Payload{
return size() / tilesize <= s;
}
/** @return rotation of this payload. */
default float rotation(){
return 0f;
}
/** writes the payload for saving. */
void write(Writes write);

View file

@ -35,7 +35,12 @@ public class UnitPayload implements Payload{
@Override
public void set(float x, float y, float rotation){
unit.set(x, y);
unit.rotation(rotation);
unit.rotation = rotation;
}
@Override
public float rotation(){
return unit.rotation;
}
@Override

View file

@ -14,7 +14,7 @@ import mindustry.world.blocks.payloads.*;
import static mindustry.Vars.*;
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 = "@-out", fallback = "factory-out-@size") TextureRegion outRegion;
@ -66,7 +66,7 @@ public class PayloadAcceptor extends Block{
public void handlePayload(Building source, Payload 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.payRotation = source.angleTo(this);
this.payRotation = payload.rotation();
updatePayload();
}
@ -115,7 +115,7 @@ public class PayloadAcceptor extends Block{
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());
return hasArrived();
@ -126,10 +126,12 @@ public class PayloadAcceptor extends Block{
updatePayload();
payVector.trns(rotdeg(), payVector.len() + delta() * payloadSpeed);
payRotation = rotdeg();
Vec2 dest = Tmp.v1.trns(rotdeg(), size* tilesize/2f);
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);
Building front = front();
@ -155,7 +157,7 @@ public class PayloadAcceptor extends Block{
public void drawPayload(){
if(payload != null){
payload.set(x + payVector.x, y + payVector.y, payRotation);
updatePayload();
Draw.z(Layer.blockOver);
payload.draw();

View file

@ -142,13 +142,12 @@ public class Reconstructor extends UnitBlock{
if(constructing() && hasArrived()){
Draw.draw(Layer.blockOver, () -> {
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();
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{
Draw.z(Layer.blockOver);
payRotation = rotdeg();
drawPayload();
}