Fixed GWT build errors and rotation axis bug

This commit is contained in:
Anuken
2017-12-24 11:55:08 -05:00
parent 003457ba72
commit ea63451f49
16 changed files with 169 additions and 123 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

View File

@@ -4,4 +4,5 @@
<source path="io/anuke/mindustry" /> <source path="io/anuke/mindustry" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.enemies" /> <extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.enemies" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.Tile" /> <extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.Tile" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.Maps" />
</module> </module>

View File

@@ -30,9 +30,9 @@ public class Vars{
//discord group URL //discord group URL
public static final String discordURL = "https://discord.gg/r8BkXNd"; public static final String discordURL = "https://discord.gg/r8BkXNd";
//directory for user-created map data //directory for user-created map data
public static final FileHandle customMapDirectory = Gdx.files.local("mindustry-maps/"); public static final FileHandle customMapDirectory = gwt ? null : Gdx.files.local("mindustry-maps/");
//save file directory //save file directory
public static final FileHandle saveDirectory = Gdx.files.local("mindustry-saves/"); public static final FileHandle saveDirectory = gwt ? null : Gdx.files.local("mindustry-saves/");
//scale of the font //scale of the font
public static float fontscale = Math.max(Unit.dp.scl(1f)/2f, 0.5f); public static float fontscale = Math.max(Unit.dp.scl(1f)/2f, 0.5f);
//camera zoom displayed on startup //camera zoom displayed on startup

View File

@@ -237,7 +237,7 @@ public class Control extends Module{
//multiplying by 2 so you start with more time in the beginning //multiplying by 2 so you start with more time in the beginning
wavetime = waveSpacing()*2; wavetime = waveSpacing()*2;
if(mode == GameMode.sandbox){ if(mode.infiniteResources){
Arrays.fill(items, 999999999); Arrays.fill(items, 999999999);
} }
@@ -347,7 +347,7 @@ public class Control extends Module{
int last = Settings.getInt("hiscore" + world.getMap().name); int last = Settings.getInt("hiscore" + world.getMap().name);
if(wave > last && mode != GameMode.sandbox){ if(wave > last && !mode.infiniteResources && !mode.toggleWaves){
Settings.putInt("hiscore" + world.getMap().name, wave); Settings.putInt("hiscore" + world.getMap().name, wave);
Settings.save(); Settings.save();
hiscore = true; hiscore = true;
@@ -622,7 +622,7 @@ public class Control extends Module{
tutorial.update(); tutorial.update();
} }
if(!tutorial.active() && mode != GameMode.sandbox){ if(!tutorial.active() && !mode.toggleWaves){
if(enemies <= 0){ if(enemies <= 0){
wavetime -= delta(); wavetime -= delta();

View File

@@ -152,7 +152,7 @@ public class Renderer extends RendererModule{
camera.position.set(lastx - deltax, lasty - deltay, 0); camera.position.set(lastx - deltax, lasty - deltay, 0);
record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't if(Vars.debug) record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
} }
} }
FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);

View File

@@ -51,7 +51,7 @@ public class UI extends SceneModule{
Tooltip tooltip; Tooltip tooltip;
Tile configTile; Tile configTile;
Array<String> statlist = new Array<>(); Array<String> statlist = new Array<>();
MapEditor editor = new MapEditor(); MapEditor editor;
boolean wasPaused = false; boolean wasPaused = false;
private Fragment blockfrag = new BlocksFragment(), private Fragment blockfrag = new BlocksFragment(),
@@ -175,7 +175,10 @@ public class UI extends SceneModule{
configtable = new Table(); configtable = new Table();
scene.add(configtable); scene.add(configtable);
if(!Vars.gwt) editorDialog = new MapEditorDialog(editor); if(!Vars.gwt){
editor = new MapEditor();
editorDialog = new MapEditorDialog(editor);
}
settingserror = new Dialog("Warning", "dialog"); settingserror = new Dialog("Warning", "dialog");
settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved."); settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved.");

View File

@@ -113,6 +113,10 @@ public class World extends Module{
} }
public Tile[] getNearby(int x, int y){ public Tile[] getNearby(int x, int y){
return getNearby(x, y, temptiles);
}
public Tile[] getNearby(int x, int y, Tile[] temptiles){
temptiles[0] = tile(x+1, y); temptiles[0] = tile(x+1, y);
temptiles[1] = tile(x, y+1); temptiles[1] = tile(x, y+1);
temptiles[2] = tile(x-1, y); temptiles[2] = tile(x-1, y);

View File

@@ -27,6 +27,7 @@ public class DesktopInput extends InputHandler{
int endx, endy; int endx, endy;
private boolean enableHold = false; private boolean enableHold = false;
private boolean beganBreak; private boolean beganBreak;
private boolean rotated = false;
@Override public float getCursorEndX(){ return endx; } @Override public float getCursorEndX(){ return endx; }
@Override public float getCursorEndY(){ return endy; } @Override public float getCursorEndY(){ return endy; }
@@ -64,7 +65,12 @@ public class DesktopInput extends InputHandler{
renderer.scaleCamera((int)Inputs.getAxis("zoom")); renderer.scaleCamera((int)Inputs.getAxis("zoom"));
} }
player.rotation += Inputs.getAxis("rotate_alt"); if(!rotated) {
player.rotation += Inputs.getAxis("rotate_alt");
rotated = true;
}
if(!Inputs.getAxisActive("rotate_alt")) rotated = false;
player.rotation += Inputs.getAxis("rotate"); player.rotation += Inputs.getAxis("rotate");
player.rotation = Mathf.mod(player.rotation, 4); player.rotation = Mathf.mod(player.rotation, 4);
@@ -74,8 +80,8 @@ public class DesktopInput extends InputHandler{
player.breakMode = PlaceMode.hold; player.breakMode = PlaceMode.hold;
} }
for(int i = 1; i <= 6 && i < control.getWeapons().size; i ++){ for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
if(Inputs.keyTap("weapon_" + i) && i < control.getWeapons().size){ if(Inputs.keyTap("weapon_" + i)){
player.weapon = control.getWeapons().get(i - 1); player.weapon = control.getWeapons().get(i - 1);
ui.updateWeapons(); ui.updateWeapons();
} }

View File

@@ -15,6 +15,8 @@ import io.anuke.mindustry.resource.Section;
import io.anuke.mindustry.ui.FloatingDialog; import io.anuke.mindustry.ui.FloatingDialog;
import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Hue; import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.scene.builders.button;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.table; import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.*; import io.anuke.ucore.scene.ui.*;
@@ -25,112 +27,122 @@ import io.anuke.ucore.util.Mathf;
public class BlocksFragment implements Fragment{ public class BlocksFragment implements Fragment{
private Table desctable; private Table desctable;
private Array<String> statlist = new Array<>(); private Array<String> statlist = new Array<>();
private boolean shown = true;
public void build(){ public void build(){
new table(){{ new table(){{
abottom(); abottom();
aright(); aright();
new table("button"){{ new table(){{
visible(()->player.recipe != null);
desctable = get();
fillX();
}}.end().uniformX();
row();
new table("pane"){{
get().setTouchable(Touchable.enabled);
int rows = 4;
int maxcol = 0;
float size = 48;
Stack stack = new Stack();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Array<Recipe> recipes = new Array<Recipe>();
for(Section sec : Section.values()){
recipes.clear();
Recipe.getBy(sec, recipes);
maxcol = Math.max((int)((float)recipes.size/rows+1), maxcol);
}
for(Section sec : Section.values()){
recipes.clear();
Recipe.getBy(sec, recipes);
Table table = new Table();
ImageButton button = new ImageButton("icon-"+sec.name(), "toggle");
button.clicked(()->{
if(!table.isVisible() && player.recipe != null){
player.recipe = null;
}
});
button.setName("sectionbutton" + sec.name());
add(button).growX().height(54).padTop(sec.ordinal() <= 2 ? -10 : -5);
button.getImageCell().size(40).padBottom(4).padTop(2);
group.add(button);
if(sec.ordinal() % 3 == 2 && sec.ordinal() > 0){
row();
}
table.margin(4);
table.top().left();
int i = 0;
for(Recipe r : recipes){
TextureRegion region = Draw.hasRegion(r.result.name() + "-icon") ?
Draw.region(r.result.name() + "-icon") : Draw.region(r.result.name());
ImageButton image = new ImageButton(region, "select");
image.clicked(()->{
if(player.recipe == r){
player.recipe = null;
}else{
player.recipe = r;
updateRecipe();
}
});
table.add(image).size(size+8).pad(2);
image.getImageCell().size(size);
image.update(()->{
boolean canPlace = !control.getTutorial().active() || control.getTutorial().canPlace();
boolean has = (control.hasItems(r.requirements)) && canPlace;
//image.setDisabled(!has);
image.setChecked(player.recipe == r);
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
});
if(i % rows == rows-1)
table.row();
i++;
}
table.setVisible(()-> button.isChecked());
stack.add(table);
}
new table("button") {{
visible(() -> player.recipe != null);
desctable = get();
fillX();
}}.end().uniformX();
row(); row();
add(stack).colspan(Section.values().length);
margin(10f);
get().marginLeft(0f); new table("pane") {{
get().marginRight(0f); touchable(Touchable.enabled);
int rows = 4;
int maxcol = 0;
float size = 48;
end(); Stack stack = new Stack();
}}.right().bottom().uniformX(); ButtonGroup<ImageButton> group = new ButtonGroup<>();
Array<Recipe> recipes = new Array<Recipe>();
visible(()->!GameState.is(State.menu)); for (Section sec : Section.values()) {
recipes.clear();
Recipe.getBy(sec, recipes);
maxcol = Math.max((int) ((float) recipes.size / rows + 1), maxcol);
}
for (Section sec : Section.values()) {
recipes.clear();
Recipe.getBy(sec, recipes);
Table table = new Table();
ImageButton button = new ImageButton("icon-" + sec.name(), "toggle");
button.clicked(() -> {
if (!table.isVisible() && player.recipe != null) {
player.recipe = null;
}
});
button.setName("sectionbutton" + sec.name());
add(button).growX().height(54).padTop(sec.ordinal() <= 2 ? -10 : -5);
button.getImageCell().size(40).padBottom(4).padTop(2);
group.add(button);
if (sec.ordinal() % 3 == 2 && sec.ordinal() > 0) {
row();
}
table.margin(4);
table.top().left();
int i = 0;
for (Recipe r : recipes) {
TextureRegion region = Draw.hasRegion(r.result.name() + "-icon") ?
Draw.region(r.result.name() + "-icon") : Draw.region(r.result.name());
ImageButton image = new ImageButton(region, "select");
image.clicked(() -> {
if (player.recipe == r) {
player.recipe = null;
} else {
player.recipe = r;
updateRecipe();
}
});
table.add(image).size(size + 8).pad(2);
image.getImageCell().size(size);
image.update(() -> {
boolean canPlace = !control.getTutorial().active() || control.getTutorial().canPlace();
boolean has = (control.hasItems(r.requirements)) && canPlace;
//image.setDisabled(!has);
image.setChecked(player.recipe == r);
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
});
if (i % rows == rows - 1)
table.row();
i++;
}
table.setVisible(button::isChecked);
stack.add(table);
}
row();
add(stack).colspan(Section.values().length);
margin(10f);
get().marginLeft(0f);
get().marginRight(0f);
end();
}}.right().bottom().uniformX();
visible(() -> !GameState.is(State.menu) && shown);
}}.end();
//new imagebutton("icon-arrow-right", 10*2, () -> {
// shown = !shown;
//}).uniformY().fillY();
}}.end(); }}.end();
} }

View File

@@ -67,7 +67,7 @@ public class HudFragment implements Fragment{
itemtable = new table("button").end().top().left().fillX().size(-1).get(); itemtable = new table("button").end().top().left().fillX().size(-1).get();
itemtable.setTouchable(Touchable.enabled); itemtable.setTouchable(Touchable.enabled);
itemtable.setVisible(()-> control.getMode() != GameMode.sandbox); itemtable.setVisible(()-> !control.getMode().infiniteResources);
itemcell = get().getCell(itemtable); itemcell = get().getCell(itemtable);
get().setVisible(()->!GameState.is(State.menu)); get().setVisible(()->!GameState.is(State.menu));
@@ -169,7 +169,7 @@ public class HudFragment implements Fragment{
new label(()-> control.getEnemiesRemaining() > 0 ? new label(()-> control.getEnemiesRemaining() > 0 ?
control.getEnemiesRemaining() + printEnemiesRemaining() : control.getEnemiesRemaining() + printEnemiesRemaining() :
(control.getTutorial().active() || Vars.control.getMode() == GameMode.sandbox) ? "waiting..." : "Wave in " + (int) (control.getWaveCountdown() / 60f)) (control.getTutorial().active() || Vars.control.getMode().toggleWaves) ? "waiting..." : "Wave in " + (int) (control.getWaveCountdown() / 60f))
.minWidth(140).left(); .minWidth(140).left();
margin(12f); margin(12f);
@@ -186,7 +186,7 @@ public class HudFragment implements Fragment{
Vars.control.runWave(); Vars.control.runWave();
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36) }).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36)
.padLeft(-10f).width(40f).update(l->{ .padLeft(-10f).width(40f).update(l->{
boolean vis = Vars.control.getMode() == GameMode.sandbox && Vars.control.getEnemiesRemaining() <= 0; boolean vis = Vars.control.getMode().toggleWaves && Vars.control.getEnemiesRemaining() <= 0;
boolean paused = GameState.is(State.paused) || !vis; boolean paused = GameState.is(State.paused) || !vis;
l.setVisible(vis); l.setVisible(vis);
@@ -200,7 +200,7 @@ public class HudFragment implements Fragment{
itemtable.clear(); itemtable.clear();
itemtable.left(); itemtable.left();
if(control.getMode() == GameMode.sandbox){ if(control.getMode().infiniteResources){
return; return;
} }

View File

@@ -23,6 +23,7 @@ public class Block{
protected static TextureRegion temp = new TextureRegion(); protected static TextureRegion temp = new TextureRegion();
public Tile[] temptiles = new Tile[4];
/**internal name*/ /**internal name*/
public final String name; public final String name;
/**internal ID*/ /**internal ID*/
@@ -148,7 +149,7 @@ public class Block{
byte i = tile.getDump(); byte i = tile.getDump();
byte pdump = (byte)(i % 4); byte pdump = (byte)(i % 4);
Tile[] tiles = tile.getNearby(); Tile[] tiles = tile.getNearby(temptiles);
for(int j = 0; j < 4; j ++){ for(int j = 0; j < 4; j ++){
Tile other = tiles[i]; Tile other = tiles[i];
@@ -157,7 +158,6 @@ public class Block{
tile.setDump((byte)((i+1)%4)); tile.setDump((byte)((i+1)%4));
return; return;
} }
tiles = tile.getNearby();
i++; i++;
i %= 4; i %= 4;
} }
@@ -176,7 +176,7 @@ public class Block{
protected boolean tryDump(Tile tile, int direction, Item todump){ protected boolean tryDump(Tile tile, int direction, Item todump){
int i = tile.getDump()%4; int i = tile.getDump()%4;
Tile[] tiles = tile.getNearby(); Tile[] tiles = tile.getNearby(temptiles);
for(int j = 0; j < 4; j ++){ for(int j = 0; j < 4; j ++){
Tile other = tiles[i]; Tile other = tiles[i];
@@ -194,7 +194,6 @@ public class Block{
} }
} }
} }
tiles = tile.getNearby();
i++; i++;
i %= 4; i %= 4;
} }

View File

@@ -1,5 +1,18 @@
package io.anuke.mindustry.world; package io.anuke.mindustry.world;
public enum GameMode{ public enum GameMode{
waves, sandbox; waves,
sandbox{
{
infiniteResources = true;
toggleWaves = true;
}
},
freebuild{
{
toggleWaves = true;
}
};
public boolean infiniteResources;
public boolean toggleWaves;
} }

View File

@@ -42,11 +42,13 @@ public class Maps implements Disposable{
throw new RuntimeException("Failed to load maps!"); throw new RuntimeException("Failed to load maps!");
} }
if(!loadMapFile(Vars.customMapDirectory.child("maps.json"))){ if(!Vars.gwt) {
try{ if (!loadMapFile(Vars.customMapDirectory.child("maps.json"))) {
Vars.customMapDirectory.child("maps.json").writeString("{}", false); try {
}catch(Exception e){ Vars.customMapDirectory.child("maps.json").writeString("{}", false);
throw new RuntimeException("Failed to create custom map directory!"); } catch (Exception e) {
throw new RuntimeException("Failed to create custom map directory!");
}
} }
} }
} }

View File

@@ -214,6 +214,10 @@ public class Tile{
return Vars.world.getNearby(x, y); return Vars.world.getNearby(x, y);
} }
public Tile[] getNearby(Tile[] copy){
return Vars.world.getNearby(x, y);
}
public void changed(){ public void changed(){
if(entity != null){ if(entity != null){
if(entity.added) entity.remove(); if(entity.added) entity.remove();

View File

@@ -35,6 +35,8 @@ public class TunnelConveyor extends Block{
@Override @Override
public boolean acceptItem(Item item, Tile dest, Tile source){ public boolean acceptItem(Item item, Tile dest, Tile source){
int rot = source.relativeTo(dest.x, dest.y);
if(rot != (dest.getRotation() + 2)%4) return false;
Tile tunnel = getDestTunnel(dest); Tile tunnel = getDestTunnel(dest);
if(tunnel != null){ if(tunnel != null){
Tile to = tunnel.getNearby()[tunnel.getRotation()]; Tile to = tunnel.getNearby()[tunnel.getRotation()];

View File

@@ -10,10 +10,10 @@ gwt {
modules 'io.anuke.mindustry.GdxDefinition' modules 'io.anuke.mindustry.GdxDefinition'
devModules 'io.anuke.mindustry.GdxDefinitionSuperdev' devModules 'io.anuke.mindustry.GdxDefinitionSuperdev'
project.webAppDirName = 'webapp' project.webAppDirName = 'webapp'
compiler.style = de.richsource.gradle.plugins.gwt.Style.PRETTY;
compiler { compiler {
strict = true; strict = true;
//enableClosureCompiler = true;
disableCastChecking = true; disableCastChecking = true;
} }
} }