This commit is contained in:
Anuken
2020-09-19 11:40:11 -04:00
parent b29c0ab401
commit e19e74cdc5
34 changed files with 155 additions and 131 deletions

View File

@@ -1010,6 +1010,7 @@ public class UnitTypes implements ContentList{
abilities.add(new HealFieldAbility(5f, 60f * 5, 50f));
weapons.add(new Weapon("heal-weapon-mount"){{
top = false;
y = -2.5f;
x = 3.5f;
reload = 30f;

View File

@@ -64,8 +64,12 @@ public class DrawOperation{
if(type == OpType.floor.ordinal()){
tile.setFloor((Floor)content.block(to));
}else if(type == OpType.block.ordinal()){
tile.getLinkedTiles(t -> editor.renderer.updatePoint(t.x, t.y));
Block block = content.block(to);
tile.setBlock(block, tile.team(), tile.build == null ? 0 : tile.build.rotation);
tile.getLinkedTiles(t -> editor.renderer.updatePoint(t.x, t.y));
}else if(type == OpType.rotation.ordinal()){
if(tile.build != null) tile.build.rotation = to;
}else if(type == OpType.team.ordinal()){
@@ -74,7 +78,7 @@ public class DrawOperation{
tile.setOverlayID(to);
}
});
editor.renderer().updatePoint(tile.x, tile.y);
editor.renderer.updatePoint(tile.x, tile.y);
}
@Struct

View File

@@ -46,14 +46,14 @@ public class EditorTile extends Tile{
return;
}
//if(this.block == type && (build == null || build.rotation == rotation)){
// ui.editor.editor.renderer().updatePoint(x, y);
// return;
//}
if(this.block == type && (build == null || build.rotation == rotation)){
update();
return;
}
if(rotation != 0) op(OpType.rotation, (byte)rotation);
if(team() != Team.derelict) op(OpType.team, (byte)team().id);
op(OpType.block, block.id);
if(rotation != 0) op(OpType.rotation, (byte)rotation);
if(team != Team.derelict) op(OpType.team, (byte)team.id);
super.setBlock(type, team, rotation);
}
@@ -87,7 +87,7 @@ public class EditorTile extends Tile{
if(skip()){
super.fireChanged();
}else{
ui.editor.editor.renderer().updatePoint(x, y);
update();
}
}
@@ -121,6 +121,10 @@ public class EditorTile extends Tile{
}
}
private void update(){
ui.editor.editor.renderer.updatePoint(x, y);
}
private boolean skip(){
return state.isGame() || ui.editor.editor.isLoading();
}

View File

@@ -18,10 +18,10 @@ import static mindustry.Vars.*;
public class MapEditor{
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15, 20};
private final Context context = new Context();
private StringMap tags = new StringMap();
private MapRenderer renderer = new MapRenderer(this);
public StringMap tags = new StringMap();
public MapRenderer renderer = new MapRenderer(this);
private final Context context = new Context();
private OperationStack stack = new OperationStack();
private DrawOperation currentOp;
private boolean loading;
@@ -35,10 +35,6 @@ public class MapEditor{
return loading;
}
public StringMap getTags(){
return tags;
}
public void beginEdit(int width, int height){
reset();
@@ -214,10 +210,6 @@ public class MapEditor{
}
}
public MapRenderer renderer(){
return renderer;
}
public void resize(int width, int height){
clearOp();

View File

@@ -116,9 +116,9 @@ public class MapEditorDialog extends Dialog implements Disposable{
t.button("@editor.export", Icon.upload, () -> createDialog("@editor.export",
"@editor.exportfile", "@editor.exportfile.description", Icon.file,
(Runnable)() -> platform.export(editor.getTags().get("name", "unknown"), mapExtension, file -> MapIO.writeMap(file, editor.createMap(file))),
(Runnable)() -> platform.export(editor.tags.get("name", "unknown"), mapExtension, file -> MapIO.writeMap(file, editor.createMap(file))),
"@editor.exportimage", "@editor.exportimage.description", Icon.fileImage,
(Runnable)() -> platform.export(editor.getTags().get("name", "unknown"), "png", file -> {
(Runnable)() -> platform.export(editor.tags.get("name", "unknown"), "png", file -> {
Pixmap out = MapIO.writeImage(editor.tiles());
file.writePNG(out);
out.dispose();
@@ -129,16 +129,16 @@ public class MapEditorDialog extends Dialog implements Disposable{
if(steam){
menu.cont.button("@editor.publish.workshop", Icon.link, () -> {
Map builtin = maps.all().find(m -> m.name().equals(editor.getTags().get("name", "").trim()));
Map builtin = maps.all().find(m -> m.name().equals(editor.tags.get("name", "").trim()));
if(editor.getTags().containsKey("steamid") && builtin != null && !builtin.custom){
platform.viewListingID(editor.getTags().get("steamid"));
if(editor.tags.containsKey("steamid") && builtin != null && !builtin.custom){
platform.viewListingID(editor.tags.get("steamid"));
return;
}
Map map = save();
if(editor.getTags().containsKey("steamid") && map != null){
if(editor.tags.containsKey("steamid") && map != null){
platform.viewListing(map);
return;
}
@@ -156,7 +156,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
}
platform.publish(map);
}).padTop(-3).size(swidth * 2f + 10, 60f).update(b -> b.setText(editor.getTags().containsKey("steamid") ? editor.getTags().get("author").equals(player.name) ? "@workshop.listing" : "@view.workshop" : "@editor.publish.workshop"));
}).padTop(-3).size(swidth * 2f + 10, 60f).update(b -> b.setText(editor.tags.containsKey("steamid") ? editor.tags.get("author").equals(player.name) ? "@workshop.listing" : "@view.workshop" : "@editor.publish.workshop"));
menu.cont.row();
}
@@ -235,7 +235,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
state.rules = (lastSavedRules == null ? new Rules() : lastSavedRules);
lastSavedRules = null;
saved = false;
editor.renderer().updateAll();
editor.renderer.updateAll();
}
private void playtest(){
@@ -264,10 +264,10 @@ public class MapEditorDialog extends Dialog implements Disposable{
public @Nullable Map save(){
boolean isEditor = state.rules.editor;
state.rules.editor = false;
String name = editor.getTags().get("name", "").trim();
editor.getTags().put("rules", JsonIO.write(state.rules));
editor.getTags().remove("width");
editor.getTags().remove("height");
String name = editor.tags.get("name", "").trim();
editor.tags.put("rules", JsonIO.write(state.rules));
editor.tags.remove("width");
editor.tags.remove("height");
player.clearUnit();
@@ -281,7 +281,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
if(map != null && !map.custom){
handleSaveBuiltin(map);
}else{
returned = maps.saveMap(editor.getTags());
returned = maps.saveMap(editor.tags);
ui.showInfoFade("@editor.saved");
}
}
@@ -352,7 +352,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
@Override
public void dispose(){
editor.renderer().dispose();
editor.renderer.dispose();
}
public void beginEditMap(Fi file){
@@ -614,12 +614,12 @@ public class MapEditorDialog extends Dialog implements Disposable{
Tile tile = editor.tile(x, y);
if(tile.block().breakable && tile.block() instanceof Boulder){
tile.setBlock(Blocks.air);
editor.renderer().updatePoint(x, y);
editor.renderer.updatePoint(x, y);
}
if(tile.overlay() != Blocks.air && tile.overlay() != Blocks.spawn){
tile.setOverlay(Blocks.air);
editor.renderer().updatePoint(x, y);
editor.renderer.updatePoint(x, y);
}
}
}

View File

@@ -144,7 +144,7 @@ public class MapGenerateDialog extends BaseDialog{
}
//reset undo stack as generation... messes things up
editor.renderer().updateAll();
editor.renderer.updateAll();
editor.clearOp();
}

View File

@@ -29,7 +29,7 @@ public class MapInfoDialog extends BaseDialog{
private void setup(){
cont.clear();
ObjectMap<String, String> tags = editor.getTags();
ObjectMap<String, String> tags = editor.tags;
cont.pane(t -> {
t.add("@editor.mapname").padRight(8).left();
@@ -73,8 +73,8 @@ public class MapInfoDialog extends BaseDialog{
t.row();
t.add("@editor.generation").padRight(8).left();
t.button("@edit", () -> {
generate.show(Vars.maps.readFilters(editor.getTags().get("genfilters", "")),
filters -> editor.getTags().put("genfilters", JsonIO.write(filters)));
generate.show(Vars.maps.readFilters(editor.tags.get("genfilters", "")),
filters -> editor.tags.put("genfilters", JsonIO.write(filters)));
hide();
}).left().width(200f);

View File

@@ -248,7 +248,7 @@ public class MapView extends Element implements GestureListener{
Draw.color(Pal.remove);
Lines.stroke(2f);
Lines.rect(centerx - sclwidth / 2 - 1, centery - sclheight / 2 - 1, sclwidth + 2, sclheight + 2);
editor.renderer().draw(centerx - sclwidth / 2, centery - sclheight / 2, sclwidth, sclheight);
editor.renderer.draw(centerx - sclwidth / 2, centery - sclheight / 2, sclwidth, sclheight);
Draw.reset();
if(grid){

View File

@@ -1,5 +1,6 @@
package mindustry.entities;
import arc.*;
import arc.func.*;
import arc.math.geom.*;
import mindustry.annotations.Annotations.*;
@@ -18,6 +19,15 @@ public class Units{
private static float cdist;
private static boolean boolResult;
@Remote(called = Loc.server)
public static void unitCapDeath(Unit unit){
if(unit != null){
unit.dead = true;
Fx.unitCapKill.at(unit);
Core.app.post(() -> Call.unitDeath(unit.id));
}
}
@Remote(called = Loc.server)
public static void unitDeath(int uid){
Unit unit = Groups.unit.getByID(uid);

View File

@@ -209,6 +209,10 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
//check if over unit cap
if(count() > cap() && !spawnedByCore){
deactivated = true;
if(!dead){
Call.unitCapDeath(self());
}
}else{
teamIndex.updateActiveCount(team, type, 1);
}
@@ -245,6 +249,8 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
a.update(self());
}
}
}else if(!dead){
Call.unitCapDeath(self());
}
drag = type.drag * (isGrounded() ? (floorOn().dragMultiplier) : 1f);

View File

@@ -210,8 +210,8 @@ public class FloorRenderer implements Disposable{
tile.block().drawBase(tile);
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
floor.drawBase(tile);
}else if(floor.cacheLayer.ordinal() < layer.ordinal() && layer != CacheLayer.walls){
floor.drawNonLayer(tile);
}else if(floor.cacheLayer != layer && layer != CacheLayer.walls){
floor.drawNonLayer(tile, layer);
}
}
}

View File

@@ -146,7 +146,7 @@ public class Map implements Comparable<Map>, Publishable{
public void addSteamID(String id){
tags.put("steamid", id);
ui.editor.editor.getTags().put("steamid", id);
ui.editor.editor.tags.put("steamid", id);
try{
ui.editor.save();
}catch(Exception e){
@@ -159,7 +159,7 @@ public class Map implements Comparable<Map>, Publishable{
public void removeSteamID(){
tags.remove("steamid");
ui.editor.editor.getTags().remove("steamid");
ui.editor.editor.tags.remove("steamid");
try{
ui.editor.save();
}catch(Exception e){
@@ -203,7 +203,7 @@ public class Map implements Comparable<Map>, Publishable{
@Override
public boolean prePublish(){
tags.put("author", player.name);
ui.editor.editor.getTags().put("author", tags.get("author"));
ui.editor.editor.tags.put("author", tags.get("author"));
ui.editor.save();
return true;

View File

@@ -54,7 +54,7 @@ public class MapsDialog extends BaseDialog{
Runnable show = () -> ui.loadAnd(() -> {
hide();
ui.editor.show();
ui.editor.editor.getTags().put("name", text);
ui.editor.editor.tags.put("name", text);
Events.fire(new MapMakeEvent());
});

View File

@@ -67,7 +67,7 @@ public class Floor extends Block{
protected TextureRegion[][] edges;
protected Seq<Block> blenders = new Seq<>();
protected IntSet blended = new IntSet();
protected Bits blended = new Bits(256);
protected TextureRegion edgeRegion;
public Floor(String name){
@@ -170,30 +170,43 @@ public class Floor extends Block{
return drownTime > 0;
}
public void drawNonLayer(Tile tile){
public void drawNonLayer(Tile tile, CacheLayer layer){
Mathf.rand.setSeed(tile.pos());
drawEdges(tile, true);
}
protected void drawEdges(Tile tile){
drawEdges(tile, false);
}
protected void drawEdges(Tile tile, boolean sameLayer){
blenders.clear();
blended.clear();
for(int i = 0; i < 8; i++){
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
if(other != null && doEdge(other.floor(), sameLayer) && other.floor().edges() != null){
if(blended.add(other.floor().id)){
if(other != null && other.floor().cacheLayer == layer && other.floor().edges() != null){
if(!blended.getAndSet(other.floor().id)){
blenders.add(other.floor());
}
}
}
drawBlended(tile);
}
protected void drawEdges(Tile tile){
blenders.clear();
blended.clear();
for(int i = 0; i < 8; i++){
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
if(other != null && doEdge(other.floor()) && other.floor().cacheLayer == cacheLayer && other.floor().edges() != null){
if(!blended.getAndSet(other.floor().id)){
blenders.add(other.floor());
}
}
}
drawBlended(tile);
}
protected void drawBlended(Tile tile){
blenders.sort(a -> a.id);
for(Block block : blenders){
@@ -201,23 +214,18 @@ public class Floor extends Block{
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
if(other != null && other.floor() == block){
TextureRegion region = edge((Floor)block, 2 - (point.x + 1), 2 - (point.y + 1));
TextureRegion region = edge((Floor)block, 1 - point.x, 1 - point.y);
Draw.rect(region, tile.worldx(), tile.worldy());
if(!sameLayer && block.cacheLayer.ordinal() > cacheLayer.ordinal()){
Draw.rect(block.variantRegions()[0], tile.worldx() + point.x*tilesize, tile.worldy() + point.y*tilesize);
}
}
}
}
}
//'new' style of edges with shadows instead of colors, not used currently
protected void drawEdgesFlat(Tile tile, boolean sameLayer){
for(int i = 0; i < 4; i++){
Tile other = tile.getNearby(i);
if(other != null && doEdge(other.floor(), sameLayer)){
if(other != null && doEdge(other.floor())){
Color color = other.floor().mapColor;
Draw.color(color.r, color.g, color.b, 1f);
Draw.rect(edgeRegion, tile.worldx(), tile.worldy(), i*90);
@@ -231,8 +239,8 @@ public class Floor extends Block{
return ((Floor)blendGroup).edges;
}
protected boolean doEdge(Floor other, boolean sameLayer){
return (((other.blendGroup.id > blendGroup.id) || edges() == null) && (other.cacheLayer.ordinal() > this.cacheLayer.ordinal() || !sameLayer));
protected boolean doEdge(Floor other){
return other.blendGroup.id > blendGroup.id || edges() == null;
}
TextureRegion edge(Floor block, int x, int y){