From a9321110406d9a0952dc0e3b25dc939f4f74daa4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 19 Nov 2018 14:38:46 -0500 Subject: [PATCH] Removed ContentUnlockSet --- build.gradle | 2 +- .../mindustry/game/ContentUnlockSet.java | 51 ----------------- core/src/io/anuke/mindustry/game/Unlocks.java | 55 +++++++++++-------- 3 files changed, 32 insertions(+), 76 deletions(-) delete mode 100644 core/src/io/anuke/mindustry/game/ContentUnlockSet.java diff --git a/build.gradle b/build.gradle index 92579ba541..10d8492d99 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.9' roboVMVersion = '2.3.0' - uCoreVersion = 'c93c55179ec05b44926d59c5878534a3177d804f' + uCoreVersion = 'c9aadd4d0b5848dbc4dbbd0fcd701b11c30c02bb' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/game/ContentUnlockSet.java b/core/src/io/anuke/mindustry/game/ContentUnlockSet.java deleted file mode 100644 index a779c52509..0000000000 --- a/core/src/io/anuke/mindustry/game/ContentUnlockSet.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.anuke.mindustry.game; - -import com.badlogic.gdx.utils.ObjectMap; -import com.badlogic.gdx.utils.ObjectSet; -import io.anuke.mindustry.game.EventType.UnlockEvent; -import io.anuke.mindustry.type.ContentType; -import io.anuke.ucore.core.Events; - -public class ContentUnlockSet { - private ObjectMap> unlocked = new ObjectMap<>(); - private boolean dirty; - - public boolean isUnlocked(UnlockableContent content){ - if(content.alwaysUnlocked()) return true; - - if(!unlocked.containsKey(content.getContentType())){ - unlocked.put(content.getContentType(), new ObjectSet<>()); - } - - ObjectSet set = unlocked.get(content.getContentType()); - - return set.contains(content.getContentName()); - } - - public boolean unlockContent(UnlockableContent content){ - if(!content.canBeUnlocked() || content.alwaysUnlocked()) return false; - - if(!unlocked.containsKey(content.getContentType())){ - unlocked.put(content.getContentType(), new ObjectSet<>()); - } - - boolean ret = unlocked.get(content.getContentType()).add(content.getContentName()); - - //fire unlock event so other classes can use it - if(ret){ - content.onUnlock(); - Events.fire(new UnlockEvent(content)); - dirty = true; - } - - return ret; - } - - public boolean isDirty() { - return dirty; - } - - public ObjectMap> getUnlocked() { - return unlocked; - } -} diff --git a/core/src/io/anuke/mindustry/game/Unlocks.java b/core/src/io/anuke/mindustry/game/Unlocks.java index bb2e384f68..7b624263b9 100644 --- a/core/src/io/anuke/mindustry/game/Unlocks.java +++ b/core/src/io/anuke/mindustry/game/Unlocks.java @@ -1,15 +1,16 @@ package io.anuke.mindustry.game; -import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; -import com.badlogic.gdx.utils.ObjectMap.Entry; import com.badlogic.gdx.utils.ObjectSet; +import io.anuke.mindustry.game.EventType.UnlockEvent; import io.anuke.mindustry.type.ContentType; +import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Settings; /**Stores player unlocks. Clientside only.*/ public class Unlocks{ - ContentUnlockSet set = new ContentUnlockSet(); + private ObjectMap> unlocked = new ObjectMap<>(); + private boolean dirty; static{ Settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]); @@ -17,7 +18,15 @@ public class Unlocks{ /** Returns whether or not this piece of content is unlocked yet.*/ public boolean isUnlocked(UnlockableContent content){ - return set.isUnlocked(content); + if(content.alwaysUnlocked()) return true; + + if(!unlocked.containsKey(content.getContentType())){ + unlocked.put(content.getContentType(), new ObjectSet<>()); + } + + ObjectSet set = unlocked.get(content.getContentType()); + + return set.contains(content.getContentName()); } /** @@ -28,16 +37,27 @@ public class Unlocks{ * @return whether or not this content was newly unlocked. */ public boolean unlockContent(UnlockableContent content){ - return !set.isUnlocked(content) && currentSet().unlockContent(content); - } + if(!content.canBeUnlocked() || content.alwaysUnlocked()) return false; - private ContentUnlockSet currentSet(){ - return set; + if(!unlocked.containsKey(content.getContentType())){ + unlocked.put(content.getContentType(), new ObjectSet<>()); + } + + boolean ret = unlocked.get(content.getContentType()).add(content.getContentName()); + + //fire unlock event so other classes can use it + if(ret){ + content.onUnlock(); + Events.fire(new UnlockEvent(content)); + dirty = true; + } + + return ret; } /** Returns whether unlockables have changed since the last save.*/ public boolean isDirty(){ - return set.isDirty(); + return dirty; } /** Clears all unlocked content. Automatically saves.*/ @@ -46,24 +66,11 @@ public class Unlocks{ } public void load(){ - ObjectMap> outer = Settings.getObject("unlocks", ObjectMap.class, ObjectMap::new); - ContentUnlockSet cset = new ContentUnlockSet(); - - for (Entry> entry : outer.entries()){ - ObjectSet set = new ObjectSet<>(); - set.addAll(entry.value); - cset.getUnlocked().put(entry.key, set); - } + unlocked = Settings.getObject("unlockset", ObjectMap.class, ObjectMap::new); } public void save(){ - ObjectMap> write = new ObjectMap<>(); - - for(Entry> entry : set.getUnlocked().entries()){ - write.put(entry.key, entry.value.iterator().toArray()); - } - - Settings.putObject("unlocks", write); + Settings.putObject("unlockset", unlocked); Settings.save(); }