From 25338ff1cf6c9a131b5e8da2adfad5c0909425e8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 20 Jun 2020 12:28:24 -0400 Subject: [PATCH] Removed CampaignData.java/GlobalData.java --- core/src/mindustry/Vars.java | 2 - core/src/mindustry/content/Items.java | 1 + core/src/mindustry/content/Weathers.java | 13 ++++- core/src/mindustry/core/ContentLoader.java | 6 +++ core/src/mindustry/core/Control.java | 4 +- .../mindustry/ctype/UnlockableContent.java | 19 +++++++- core/src/mindustry/entities/EntityGroup.java | 2 +- core/src/mindustry/entities/Units.java | 2 +- core/src/mindustry/game/CampaignData.java | 47 ------------------- core/src/mindustry/game/Universe.java | 2 +- core/src/mindustry/mod/Mods.java | 1 - .../world/blocks/campaign/ResearchBlock.java | 45 ++++++++++-------- gradle.properties | 2 +- 13 files changed, 66 insertions(+), 80 deletions(-) delete mode 100644 core/src/mindustry/game/CampaignData.java diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 3ab9fb3f87..1587c69460 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -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(); diff --git a/core/src/mindustry/content/Items.java b/core/src/mindustry/content/Items.java index 6269044786..1aea6e89c1 100644 --- a/core/src/mindustry/content/Items.java +++ b/core/src/mindustry/content/Items.java @@ -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")){{ diff --git a/core/src/mindustry/content/Weathers.java b/core/src/mindustry/content/Weathers.java index 86f121f81b..2ae8270521 100644 --- a/core/src/mindustry/content/Weathers.java +++ b/core/src/mindustry/content/Weathers.java @@ -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)); + } } } } diff --git a/core/src/mindustry/core/ContentLoader.java b/core/src/mindustry/core/ContentLoader.java index 91286834e2..16897778c1 100644 --- a/core/src/mindustry/core/ContentLoader.java +++ b/core/src/mindustry/core/ContentLoader.java @@ -200,6 +200,12 @@ public class ContentLoader{ return contentMap; } + public void each(Cons cons){ + for(Seq seq : contentMap){ + seq.each(cons); + } + } + public T getByName(ContentType type, String name){ if(contentNameMap[type.ordinal()] == null){ return null; diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 6fb4701eb5..47241fc418 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -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(); } } } diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index 9e91023172..d18920a6ed 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -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(){ diff --git a/core/src/mindustry/entities/EntityGroup.java b/core/src/mindustry/entities/EntityGroup.java index 423fad05f0..80d01ea9cd 100644 --- a/core/src/mindustry/entities/EntityGroup.java +++ b/core/src/mindustry/entities/EntityGroup.java @@ -108,7 +108,7 @@ public class EntityGroup implements Iterable{ public void intersect(float x, float y, float width, float height, Cons 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 intersect(float x, float y, float width, float height){ diff --git a/core/src/mindustry/entities/Units.java b/core/src/mindustry/entities/Units.java index ed42bff2a7..07a31a4368 100644 --- a/core/src/mindustry/entities/Units.java +++ b/core/src/mindustry/entities/Units.java @@ -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 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. */ diff --git a/core/src/mindustry/game/CampaignData.java b/core/src/mindustry/game/CampaignData.java deleted file mode 100644 index 2620fe8117..0000000000 --- a/core/src/mindustry/game/CampaignData.java +++ /dev/null @@ -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 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); - } - -} diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index cc80129b5e..7cf7786382 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -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; diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 651d435bf8..6bdfae1905 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -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; diff --git a/core/src/mindustry/world/blocks/campaign/ResearchBlock.java b/core/src/mindustry/world/blocks/campaign/ResearchBlock.java index f5332c1d71..d1344c2f7f 100644 --- a/core/src/mindustry/world/blocks/campaign/ResearchBlock.java +++ b/core/src/mindustry/world/blocks/campaign/ResearchBlock.java @@ -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); + } } } } diff --git a/gradle.properties b/gradle.properties index 01d7afbafe..95a2dd70f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=ddf6e39554c0a824eccaec083ab5224ac6827cef +archash=8769550b776b108b7d9ff148cce0b6fca1f06ef7