Removed CampaignData.java/GlobalData.java

This commit is contained in:
Anuken 2020-06-20 12:28:24 -04:00
parent ec4a5880b7
commit 25338ff1cf
13 changed files with 66 additions and 80 deletions

View File

@ -170,7 +170,6 @@ public class Vars implements Loadable{
public static Net net;
public static ContentLoader content;
public static GameState state;
public static CampaignData data;
public static EntityCollisions collisions;
public static DefaultWaves defaultWaves;
public static mindustry.audio.LoopControl loops;
@ -256,7 +255,6 @@ public class Vars implements Loadable{
bases = new BaseRegistry();
state = new GameState();
data = new CampaignData();
mobile = Core.app.isMobile() || testMobile;
ios = Core.app.isIOS();

View File

@ -22,6 +22,7 @@ public class Items implements ContentList{
type = ItemType.material;
hardness = 1;
cost = 0.7f;
alwaysUnlocked = true;
}};
metaglass = new Item("metaglass", Color.valueOf("ebeef5")){{

View File

@ -133,9 +133,20 @@ public class Weathers implements ContentList{
if(Tmp.r3.setCentered(x, y, life * 4f).overlaps(Tmp.r2)){
Tile tile = world.tileWorld(x, y);
if(tile != null && tile.floor().liquidDrop == Liquids.water){
Draw.tint(Tmp.c1.set(tile.floor().mapColor).mul(1.5f));
Draw.color(Tmp.c1.set(tile.floor().mapColor).mul(1.5f).a(state.opacity()));
Draw.rect(splashes[(int)(life * (splashes.length - 1))], x, y);
}else{
Draw.color(Color.royal, Color.white, 0.3f);
Draw.alpha(Mathf.slope(life) * state.opacity());
Lines.stroke(1f);
float space = 45f;
for(int j : new int[]{-1, 1}){
Tmp.v1.trns(90f + j*space, 1f + 5f * life);
Lines.lineAngle(x + Tmp.v1.x, y + Tmp.v1.y, 90f + j*space, 3f * (1f - life));
}
}
}
}

View File

@ -200,6 +200,12 @@ public class ContentLoader{
return contentMap;
}
public void each(Cons<Content> cons){
for(Seq<Content> seq : contentMap){
seq.each(cons);
}
}
public <T extends MappableContent> T getByName(ContentType type, String name){
if(contentNameMap[type.ordinal()] == null){
return null;

View File

@ -183,8 +183,6 @@ public class Control implements ApplicationListener, Loadable{
Core.input.setCatch(KeyCode.back, true);
data.load();
Core.settings.defaults(
"ip", "localhost",
"color-0", playerColors[8].rgba(),
@ -480,7 +478,7 @@ public class Control implements ApplicationListener, Loadable{
for(Tilec tile : state.teams.cores(player.team())){
for(Item item : content.items()){
if(tile.items().has(item)){
data.unlockContent(item);
item.unlock();
}
}
}

View File

@ -5,6 +5,7 @@ import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import mindustry.annotations.Annotations.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
import mindustry.ui.*;
@ -20,12 +21,15 @@ public abstract class UnlockableContent extends MappableContent{
public boolean alwaysUnlocked = false;
/** Icons by Cicon ID.*/
protected TextureRegion[] cicons = new TextureRegion[mindustry.ui.Cicon.all.length];
/** Unlock state. Loaded from settings. Do not modify outside of the constructor. */
protected boolean unlocked;
public UnlockableContent(String name){
super(name);
this.localizedName = Core.bundle.get(getContentType() + "." + this.name + ".name", this.name);
this.description = Core.bundle.getOrNull(getContentType() + "." + this.name + ".description");
this.unlocked = Core.settings.getBool(name + "-unlocked", false);
}
public String displayDescription(){
@ -63,13 +67,24 @@ public abstract class UnlockableContent extends MappableContent{
return false;
}
/** Makes this piece of content unlocked; if it already unlocked, nothing happens. */
public void unlock(){
if(!unlocked()){
unlocked = true;
Core.settings.put(name + "-unlocked", true);
onUnlock();
Events.fire(new UnlockEvent(this));
}
}
public final boolean unlocked(){
return data.isUnlocked(this);
return unlocked || alwaysUnlocked;
}
/** @return whether this content is unlocked, or the player is in a custom (non-campaign) game. */
public final boolean unlockedNow(){
return data.isUnlocked(this) || !state.isCampaign();
return unlocked || alwaysUnlocked || !state.isCampaign();
}
public final boolean locked(){

View File

@ -108,7 +108,7 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
public void intersect(float x, float y, float width, float height, Cons<? super T> out){
//don't waste time for empty groups
if(isEmpty()) return;
tree.intersect(height, x, y, width, out);
tree.intersect(x, y, width, height, out);
}
public Seq<T> intersect(float x, float y, float width, float height){

View File

@ -201,7 +201,7 @@ public class Units{
/** Iterates over all units in a rectangle. */
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
teamIndex.tree(team).intersect(height, x, y, width, cons);
teamIndex.tree(team).intersect(x, y, width, height, cons);
}
/** Iterates over all units in a circle around this position. */

View File

@ -1,47 +0,0 @@
package mindustry.game;
import arc.*;
import arc.struct.*;
import mindustry.ctype.*;
import mindustry.game.EventType.*;
/** Stores unlocks and tech tree state. */
public class CampaignData{
private ObjectSet<String> unlocked = new ObjectSet<>();
/** @return whether or not this piece of content is unlocked yet. */
public boolean isUnlocked(UnlockableContent content){
return content.alwaysUnlocked || unlocked.contains(content.name);
}
/**
* Makes this piece of content 'unlocked', if possible.
* If this piece of content is already unlocked, nothing changes.
*/
public void unlockContent(UnlockableContent content){
if(content.alwaysUnlocked) return;
//fire unlock event so other classes can use it
if(unlocked.add(content.name)){
content.onUnlock();
Events.fire(new UnlockEvent(content));
save();
}
}
/** Clears all unlocked content. Automatically saves. */
public void reset(){
save();
}
@SuppressWarnings("unchecked")
public void load(){
unlocked = Core.settings.getJson("unlocked-content", ObjectSet.class, ObjectSet::new);
}
public void save(){
Core.settings.putJson("unlocked-content", String.class, unlocked);
}
}

View File

@ -13,7 +13,7 @@ import mindustry.type.*;
import static mindustry.Vars.*;
/** Updates the campaign universe. Has no relevance to other gamemodes. */
/** Updates and handles state of the campaign universe. Has no relevance to other gamemodes. */
public class Universe{
private long seconds;
private float secondCounter;

View File

@ -452,7 +452,6 @@ public class Mods implements Loadable{
content.init();
content.load();
content.loadColors();
data.load();
Core.atlas.getTextures().each(t -> t.setFilter(Core.settings.getBool("linear") ? TextureFilter.Linear : TextureFilter.Nearest));
requiresReload = false;

View File

@ -61,27 +61,32 @@ public class ResearchBlock extends Block{
@Override
public void updateTile(){
if(researching != null){
double totalTicks = researching.time * 60.0;
double amount = researchSpeed * edelta() / totalTicks;
double maxProgress = checkRequired(amount, false);
for(int i = 0; i < researching.requirements.length; i++){
int reqamount = Math.round(state.rules.buildCostMultiplier * researching.requirements[i].amount);
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001); //add min amount progressed to the accumulator
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
}
maxProgress = checkRequired(maxProgress, true);
float increment = (float)(maxProgress * researching.time);
researching.progress += increment;
//check if it has been researched
if(researching.progress >= researching.time){
data.unlockContent(researching.content);
//don't research something that is already researched
if(researching.content.unlocked()){
setTo(null);
}else{
double totalTicks = researching.time * 60.0;
double amount = researchSpeed * edelta() / totalTicks;
double maxProgress = checkRequired(amount, false);
for(int i = 0; i < researching.requirements.length; i++){
int reqamount = Math.round(state.rules.buildCostMultiplier * researching.requirements[i].amount);
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001); //add min amount progressed to the accumulator
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
}
maxProgress = checkRequired(maxProgress, true);
float increment = (float)(maxProgress * researching.time);
researching.progress += increment;
//check if it has been researched
if(researching.progress >= researching.time){
researching.content.unlocked();
setTo(null);
}
}
}
}

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=ddf6e39554c0a824eccaec083ab5224ac6827cef
archash=8769550b776b108b7d9ff148cce0b6fca1f06ef7