Cleanup / Fixed unlock system in custom games

This commit is contained in:
Anuken
2018-09-29 02:50:21 -07:00
parent 4810bbbbd9
commit d062dffc13
18 changed files with 42 additions and 62 deletions

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.ObjectMap;
@@ -11,7 +10,7 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.ContentDatabase;
import io.anuke.mindustry.game.Unlocks;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Saves;
import io.anuke.mindustry.input.DefaultKeybinds;
@@ -44,7 +43,7 @@ public class Control extends Module{
private boolean hiscore = false;
private boolean wasPaused = false;
private Saves saves;
private ContentDatabase db;
private Unlocks unlocks;
private InputHandler[] inputs = {};
private ObjectMap<Sound, Long> soundMap = new ObjectMap<>();
@@ -53,7 +52,7 @@ public class Control extends Module{
public Control(){
saves = new Saves();
db = new ContentDatabase();
unlocks = new Unlocks();
Inputs.useControllers(!gwt);
@@ -66,7 +65,7 @@ public class Control extends Module{
Core.atlas.setErrorRegion("error");
content.initialize(Content::load);
db.load();
unlocks.load();
Sounds.setFalloff(9000f);
Sounds.setPlayer((sound, volume) -> {
@@ -219,12 +218,8 @@ public class Control extends Module{
System.arraycopy(oldi, 0, inputs, 0, inputs.length);
}
public ContentDatabase database(){
return db;
}
public Input gdxInput(){
return Gdx.input;
public Unlocks unlocks(){
return unlocks;
}
public void setError(Throwable error){
@@ -239,10 +234,6 @@ public class Control extends Module{
return inputs[index];
}
public void triggerUpdateInput(){
//Gdx.input = proxy;
}
public void playMap(Map map){
ui.loadfrag.show();
@@ -265,10 +256,10 @@ public class Control extends Module{
if(entity == null) return;
entity.items.forEach((item, amount) -> control.database().unlockContent(item));
entity.items.forEach((item, amount) -> control.unlocks().unlockContent(item));
if(players[0].inventory.hasItem()){
control.database().unlockContent(players[0].inventory.getItem().item);
control.unlocks().unlockContent(players[0].inventory.getItem().item);
}
outer:
@@ -279,7 +270,7 @@ public class Control extends Module{
if(!entity.items.has(stack.item, Math.min((int) (stack.amount * unlockResourceScaling), 2000))) continue outer;
}
if(control.database().unlockContent(recipe)){
if(control.unlocks().unlockContent(recipe)){
ui.hudfrag.showUnlock(recipe);
}
}
@@ -349,8 +340,6 @@ public class Control extends Module{
saves.update();
triggerUpdateInput();
for(InputHandler inputHandler : inputs){
inputHandler.updateController();
}
@@ -369,9 +358,9 @@ public class Control extends Module{
if(!state.mode.infiniteResources && Timers.get("timerCheckUnlock", 120)){
checkUnlockableBlocks();
//save if the db changed
if(db.isDirty()){
db.save();
//save if the unlocks changed
if(unlocks.isDirty()){
unlocks.save();
}
}

View File

@@ -125,8 +125,6 @@ public class Logic extends Module{
if(!state.is(State.menu)){
if(control != null) control.triggerUpdateInput();
if(!state.is(State.paused) || Net.active()){
Timers.update();
}

View File

@@ -567,7 +567,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
for(Block block : Vars.content.blocks()){
TextureRegion[] regions = block.getCompactIcon();
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.database().isUnlocked(Recipe.getByResult(block))))
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.unlocks().isUnlocked(Recipe.getByResult(block))))
&& block != StorageBlocks.core){
continue;
}

View File

@@ -480,7 +480,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
return;
}else{
//unlock mech when used
control.database().unlockContent(mech);
control.unlocks().unlockContent(mech);
}
if(mobile){

View File

@@ -29,7 +29,7 @@ public class UnitDrops{
for(int i = 0; i < 3; i++){
for(Item item : dropTable){
//only drop unlocked items
if(!Vars.headless && !Vars.control.database().isUnlocked(item)){
if(!Vars.headless && !Vars.control.unlocks().isUnlocked(item)){
continue;
}

View File

@@ -41,7 +41,7 @@ public abstract class UnlockableContent extends MappableContent{
return true;
}else{
for(UnlockableContent cont : depend){
if(!control.database().isUnlocked(cont)){
if(!control.unlocks().isUnlocked(cont)){
return false;
}
}

View File

@@ -10,7 +10,8 @@ import io.anuke.ucore.core.Settings;
import static io.anuke.mindustry.Vars.*;
public class ContentDatabase{
/**Stores player unlocks. Clientside only.*/
public class Unlocks{
private ObjectMap<String, ContentUnlockSet> sets = new ObjectMap<>();
static{
@@ -40,10 +41,8 @@ public class ContentDatabase{
return getSet(Net.getLastIP());
}else if(world.getSector() != null || state.mode.infiniteResources){ //sector-sandbox have shared set
return rootSet();
}else if(control != null && control.getSaves().getCurrent() != null){ //per-save set
return getSet(String.valueOf(control.getSaves().getCurrent().index));
}else{ //dedicated server set
return rootSet();
}else{ //per-mode set
return getSet(state.mode.name());
}
}

View File

@@ -69,7 +69,7 @@ public class DesktopInput extends InputHandler{
@Override
public void drawOutlined(){
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
Tile cursor = tileAt(Gdx.input.getX(), Gdx.input.getY());
if(cursor == null) return;
@@ -170,7 +170,7 @@ public class DesktopInput extends InputHandler{
rotation = Mathf.mod(rotation + (int) Inputs.getAxisTapped(section, "rotate"), 4);
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
Tile cursor = tileAt(Gdx.input.getX(), Gdx.input.getY());
if(player.isDead()){
cursorType = normal;
@@ -200,7 +200,7 @@ public class DesktopInput extends InputHandler{
}
void pollInput(){
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
Tile cursor = tileAt(Gdx.input.getX(), Gdx.input.getY());
if(cursor == null){
mode = none;
return;
@@ -271,12 +271,12 @@ public class DesktopInput extends InputHandler{
@Override
public float getMouseX(){
return !controlling ? control.gdxInput().getX() : controlx;
return !controlling ? Gdx.input.getX() : controlx;
}
@Override
public float getMouseY(){
return !controlling ? control.gdxInput().getY() : controly;
return !controlling ? Gdx.input.getY() : controly;
}
@Override
@@ -329,8 +329,8 @@ public class DesktopInput extends InputHandler{
}
if(!controlling){
controlx = control.gdxInput().getX();
controly = control.gdxInput().getY();
controlx = Gdx.input.getX();
controly = Gdx.input.getY();
}
}

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
@@ -130,11 +131,11 @@ public abstract class InputHandler extends InputAdapter{
}
public float getMouseX(){
return control.gdxInput().getX();
return Gdx.input.getX();
}
public float getMouseY(){
return control.gdxInput().getY();
return Gdx.input.getY();
}
public void resetCursor(){

View File

@@ -338,7 +338,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//Draw lines
if(lineMode){
Tile tile = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
Tile tile = tileAt(Gdx.input.getX(), Gdx.input.getY());
if(tile != null){

View File

@@ -66,7 +66,7 @@ public class Recipe extends UnlockableContent{
arr.clear();
for(Recipe r : content.recipes()){
if(r.category == category && (control.database().isUnlocked(r)) &&
if(r.category == category && (control.unlocks().isUnlocked(r)) &&
!((r.mode != null && r.mode != state.mode) || (r.desktopOnly && mobile) || (r.isPad && !state.mode.showPads))){
arr.add(r);
}
@@ -168,7 +168,7 @@ public class Recipe extends UnlockableContent{
ContentStatValue stat = (ContentStatValue) value;
UnlockableContent[] content = stat.getValueContent();
for(UnlockableContent c : content){
control.database().unlockContent(c);
control.unlocks().unlockContent(c);
}
}
}

View File

@@ -59,11 +59,11 @@ public class UnlocksDialog extends FloatingDialog{
if(unlock.isHidden()) continue;
Image image = control.database().isUnlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked");
Image image = control.unlocks().isUnlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked");
image.addListener(new HandCursorListener());
list.add(image).size(size).pad(3);
if(control.database().isUnlocked(unlock)){
if(control.unlocks().isUnlocked(unlock)){
image.clicked(() -> Vars.ui.content.show(unlock));
image.addListener(new Tooltip<>(new Table("clear"){{
add(unlock.localizedName());

View File

@@ -219,7 +219,7 @@ public class Block extends BaseBlock {
/**Call when some content is produced. This unlocks the content if it is applicable.*/
public void useContent(UnlockableContent content){
if(!headless){
control.database().unlockContent(content);
control.unlocks().unlockContent(content);
}
}

View File

@@ -38,7 +38,7 @@ public interface SelectionTrait{
}
for(Item item : items){
if(!control.database().isUnlocked(item)) continue;
if(!control.unlocks().isUnlocked(item)) continue;
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> consumer.accept(item))
.group(group).get();