mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-27 15:02:03 -08:00
Untested support for JSON planets
This commit is contained in:
parent
5fd139261f
commit
fce3cf818e
10 changed files with 112 additions and 15 deletions
|
|
@ -300,10 +300,11 @@ public class UI implements ApplicationListener, Loadable{
|
|||
}
|
||||
|
||||
public void showInfoFade(String info){
|
||||
var cinfo = Core.scene.find("coreinfo");
|
||||
Table table = new Table();
|
||||
table.touchable = Touchable.disabled;
|
||||
table.setFillParent(true);
|
||||
table.marginTop(Core.scene.find("coreinfo").getPrefHeight() / Scl.scl() / 2);
|
||||
if(cinfo.visible && !state.isMenu()) table.marginTop(cinfo.getPrefHeight() / Scl.scl() / 2);
|
||||
table.actions(Actions.fadeOut(7f, Interp.fade), Actions.remove());
|
||||
table.top().add(info).style(Styles.outlineLabel).padTop(10);
|
||||
Core.scene.add(table);
|
||||
|
|
@ -311,10 +312,11 @@ public class UI implements ApplicationListener, Loadable{
|
|||
|
||||
/** Shows a fading label at the top of the screen. */
|
||||
public void showInfoToast(String info, float duration){
|
||||
var cinfo = Core.scene.find("coreinfo");
|
||||
Table table = new Table();
|
||||
table.touchable = Touchable.disabled;
|
||||
table.setFillParent(true);
|
||||
table.marginTop(Core.scene.find("coreinfo").getPrefHeight() / Scl.scl() / 2);
|
||||
if(cinfo.visible && !state.isMenu()) table.marginTop(cinfo.getPrefHeight() / Scl.scl() / 2);
|
||||
table.update(() -> {
|
||||
if(state.isMenu()) table.remove();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ public class Damage{
|
|||
float amount = calculateDamage(scaled ? Math.max(0, entity.dst(x, y) - entity.type.hitSize/2) : entity.dst(x, y), radius, damage);
|
||||
entity.damage(amount);
|
||||
//TODO better velocity displacement
|
||||
float dst = tr.set(entity.getX() - x, entity.getY() - y).len();
|
||||
float dst = tr.set(entity.x - x, entity.y - y).len();
|
||||
entity.vel.add(tr.setLength((1f - dst / radius) * 2f / entity.mass()));
|
||||
|
||||
if(complete && damage >= 9999999f && entity.isPlayer()){
|
||||
|
|
|
|||
|
|
@ -57,20 +57,28 @@ public abstract class DrawPart{
|
|||
return p -> value;
|
||||
}
|
||||
|
||||
default float getClamp(PartParams p){
|
||||
return Mathf.clamp(get(p));
|
||||
}
|
||||
|
||||
default PartProgress inv(){
|
||||
return p -> 1f - get(p);
|
||||
}
|
||||
|
||||
default PartProgress clamp(){
|
||||
return p -> Mathf.clamp(get(p));
|
||||
}
|
||||
|
||||
default PartProgress add(float amount){
|
||||
return p -> Mathf.clamp(get(p) + amount);
|
||||
return p -> get(p) + amount;
|
||||
}
|
||||
|
||||
default PartProgress delay(float amount){
|
||||
return p -> Mathf.clamp((get(p) - amount) / (1f - amount));
|
||||
return p -> (get(p) - amount) / (1f - amount);
|
||||
}
|
||||
|
||||
default PartProgress shorten(float amount){
|
||||
return p -> Mathf.clamp(get(p) / (1f - amount));
|
||||
return p -> get(p) / (1f - amount);
|
||||
}
|
||||
|
||||
default PartProgress blend(PartProgress other, float amount){
|
||||
|
|
@ -82,7 +90,7 @@ public abstract class DrawPart{
|
|||
}
|
||||
|
||||
default PartProgress mul(float amount){
|
||||
return p -> Mathf.clamp(get(p) * amount);
|
||||
return p -> get(p) * amount;
|
||||
}
|
||||
|
||||
default PartProgress min(PartProgress other){
|
||||
|
|
@ -90,11 +98,11 @@ public abstract class DrawPart{
|
|||
}
|
||||
|
||||
default PartProgress sin(float scl, float mag){
|
||||
return p -> Mathf.clamp(get(p) + Mathf.sin(scl, mag));
|
||||
return p -> get(p) + Mathf.sin(scl, mag);
|
||||
}
|
||||
|
||||
default PartProgress absin(float scl, float mag){
|
||||
return p -> Mathf.clamp(get(p) + Mathf.absin(scl, mag));
|
||||
return p -> get(p) + Mathf.absin(scl, mag);
|
||||
}
|
||||
|
||||
default PartProgress apply(PartProgress other, PartFunc func){
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class RegionPart extends DrawPart{
|
|||
Draw.z(Draw.z() + layerOffset);
|
||||
|
||||
float prevZ = Draw.z();
|
||||
float prog = progress.get(params);
|
||||
float prog = progress.getClamp(params);
|
||||
|
||||
int len = mirror && params.sideOverride == -1 ? 2 : 1;
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ public class RegionPart extends DrawPart{
|
|||
}
|
||||
|
||||
if(heat.found()){
|
||||
Drawf.additive(heat, heatColor.write(Tmp.c1).a(heatProgress.get(params) * heatColor.a), rx, ry, rot, turretShading ? Layer.turretHeat : z + 1f);
|
||||
Drawf.additive(heat, heatColor.write(Tmp.c1).a(heatProgress.getClamp(params) * heatColor.a), rx, ry, rot, turretShading ? Layer.turretHeat : z + 1f);
|
||||
}
|
||||
|
||||
Draw.xscl = 1f;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class ShapePart extends DrawPart{
|
|||
|
||||
Draw.z(Draw.z() + layerOffset);
|
||||
|
||||
float prog = progress.get(params);
|
||||
float prog = progress.getClamp(params);
|
||||
int len = mirror && params.sideOverride == -1 ? 2 : 1;
|
||||
|
||||
for(int s = 0; s < len; s++){
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import arc.func.*;
|
|||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.serialization.*;
|
||||
|
|
@ -30,7 +31,10 @@ import mindustry.game.*;
|
|||
import mindustry.game.Objectives.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.maps.generators.*;
|
||||
import mindustry.maps.planet.*;
|
||||
import mindustry.mod.Mods.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.ammo.*;
|
||||
|
|
@ -164,6 +168,7 @@ public class ContentParser{
|
|||
//I have to hard-code this, no easy way of getting parameter names, unfortunately
|
||||
return switch(op){
|
||||
case "inv" -> base.inv();
|
||||
case "clamp" -> base.clamp();
|
||||
case "delay" -> base.delay(data.getFloat("amount"));
|
||||
case "shorten" -> base.shorten(data.getFloat("amount"));
|
||||
case "add" -> base.add(data.getFloat("amount"));
|
||||
|
|
@ -176,6 +181,64 @@ public class ContentParser{
|
|||
default -> throw new RuntimeException("Unknown operation '" + op + "', check PartProgress class for a list of methods.");
|
||||
};
|
||||
});
|
||||
put(PlanetGenerator.class, (type, data) -> {
|
||||
var result = new AsteroidGenerator(); //only one type for now
|
||||
readFields(result, data);
|
||||
return result;
|
||||
});
|
||||
put(GenericMesh.class, (type, data) -> {
|
||||
if(!data.isObject()) throw new RuntimeException("Meshes must be objects.");
|
||||
if(!(currentContent instanceof Planet planet)) throw new RuntimeException("Meshes can only be parsed as parts of planets.");
|
||||
|
||||
String tname = Strings.capitalize(data.getString("type", "NoiseMesh"));
|
||||
|
||||
return switch(tname){
|
||||
//TODO NoiseMesh is bad
|
||||
case "NoiseMesh" -> new NoiseMesh(planet,
|
||||
data.getInt("seed", 0), data.getInt("divisions", 1), data.getFloat("radius", 1f),
|
||||
data.getInt("octaves", 1), data.getFloat("persistence", 0.5f), data.getFloat("scale", 1f), data.getFloat("mag", 0.5f),
|
||||
Color.valueOf(data.getString("color1", data.getString("color", "ffffff"))),
|
||||
Color.valueOf(data.getString("color2", data.getString("color", "ffffff"))),
|
||||
data.getInt("colorOct", 1), data.getFloat("colorPersistence", 0.5f), data.getFloat("colorScale", 1f),
|
||||
data.getFloat("colorThreshold", 0.5f));
|
||||
case "MultiMesh" -> new MultiMesh(parser.readValue(GenericMesh[].class, data.get("meshes")));
|
||||
case "MatMesh" -> new MatMesh(parser.readValue(GenericMesh.class, data.get("mesh")), parser.readValue(Mat3D.class, data.get("mat")));
|
||||
default -> throw new RuntimeException("Unknown mesh type: " + tname);
|
||||
};
|
||||
});
|
||||
put(Mat3D.class, (type, data) -> {
|
||||
if(data == null) return new Mat3D();
|
||||
|
||||
//transform x y z format
|
||||
if(data.has("x") && data.has("y") && data.has("z")){
|
||||
return new Mat3D().translate(data.getFloat("x", 0f), data.getFloat("y", 0f), data.getFloat("z", 0f));
|
||||
}
|
||||
|
||||
//transform array format
|
||||
if(data.isArray() && data.size == 3){
|
||||
return new Mat3D().setToTranslation(new Vec3(data.asFloatArray()));
|
||||
}
|
||||
|
||||
Mat3D mat = new Mat3D();
|
||||
|
||||
//TODO this is kinda bad
|
||||
for(var val : data){
|
||||
switch(val.name){
|
||||
case "translate", "trans" -> mat.translate(parser.readValue(Vec3.class, data));
|
||||
case "scale", "scl" -> mat.scale(parser.readValue(Vec3.class, data));
|
||||
case "rotate", "rot" -> mat.rotate(parser.readValue(Vec3.class, data), data.getFloat("degrees", 0f));
|
||||
case "multiply", "mul" -> mat.mul(parser.readValue(Mat3D.class, data));
|
||||
case "x", "y", "z" -> {}
|
||||
default -> throw new RuntimeException("Unknown matrix transformation: '" + val.name + "'");
|
||||
}
|
||||
}
|
||||
|
||||
return mat;
|
||||
});
|
||||
put(Vec3.class, (type, data) -> {
|
||||
if(data.isArray()) return new Vec3(data.asFloatArray());
|
||||
return new Vec3(data.getFloat("x", 0f), data.getFloat("y", 0f), data.getFloat("z", 0f));
|
||||
});
|
||||
put(Sound.class, (type, data) -> {
|
||||
if(fieldOpt(Sounds.class, data) != null) return fieldOpt(Sounds.class, data);
|
||||
if(Vars.headless) return new Sound();
|
||||
|
|
@ -202,6 +265,7 @@ public class ContentParser{
|
|||
readFields(obj, data);
|
||||
return obj;
|
||||
});
|
||||
|
||||
put(Ability.class, (type, data) -> {
|
||||
Class<? extends Ability> oc = resolve(data.getString("type", ""));
|
||||
data.remove("type");
|
||||
|
|
@ -437,6 +501,21 @@ public class ContentParser{
|
|||
value.remove("planet");
|
||||
read(() -> readFields(out, value));
|
||||
return out;
|
||||
},
|
||||
ContentType.planet, (TypeParser<Planet>)(mod, name, value) -> {
|
||||
if(value.isString()) return locate(ContentType.planet, name);
|
||||
|
||||
Planet parent = locate(ContentType.planet, value.getString("parent"));
|
||||
Planet planet = new Planet(name, parent, value.getFloat("radius", 1f), value.getInt("sectorSize", 0));
|
||||
|
||||
//TODO unimplemented; still needs generator + mesh
|
||||
if(value.has("mesh")){
|
||||
planet.meshLoader = () -> parser.readValue(GenericMesh.class, value.get("mesh"));
|
||||
}
|
||||
|
||||
//TODO unimplemented!!
|
||||
read(() -> readFields(planet, value));
|
||||
return planet;
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class Planet extends UnlockableContent{
|
|||
/** Content (usually planet-specific) that is unlocked upon landing here. */
|
||||
public Seq<UnlockableContent> unlockedOnLand = new Seq<>();
|
||||
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
||||
protected Prov<GenericMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2), cloudMeshLoader = () -> null;
|
||||
public Prov<GenericMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2), cloudMeshLoader = () -> null;
|
||||
|
||||
public Planet(String name, Planet parent, float radius){
|
||||
super(name);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import static mindustry.Vars.*;
|
|||
|
||||
public class RegenProjector extends Block{
|
||||
private static final IntSet taken = new IntSet();
|
||||
//map ID to mend amount
|
||||
//map building pos to mend amount (TODO just use buildings as keys? no lookup)
|
||||
private static final IntFloatMap mendMap = new IntFloatMap();
|
||||
private static long lastUpdateFrame = -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -135,6 +135,14 @@ public class UnitPayload implements Payload{
|
|||
//TODO should not happen
|
||||
if(unit.type == null) return;
|
||||
|
||||
//TODO this would be more accurate but has all sorts of associated problems
|
||||
if(false){
|
||||
unit.elevation = 0f;
|
||||
//avoids drawing mining or building
|
||||
unit.type.draw(unit);
|
||||
return;
|
||||
}
|
||||
|
||||
unit.type.drawSoftShadow(unit);
|
||||
Draw.rect(unit.type.fullIcon, unit.x, unit.y, unit.rotation - 90);
|
||||
unit.type.drawCell(unit);
|
||||
|
|
|
|||
|
|
@ -24,4 +24,4 @@ android.useAndroidX=true
|
|||
#used for slow jitpack builds; TODO see if this actually works
|
||||
org.gradle.internal.http.socketTimeout=100000
|
||||
org.gradle.internal.http.connectionTimeout=100000
|
||||
archash=f61c00f400
|
||||
archash=31e09b436b
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue