Launchpad block
This commit is contained in:
@@ -14,12 +14,18 @@ import io.anuke.mindustry.type.Item;
|
||||
public class GlobalData{
|
||||
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
|
||||
private ObjectIntMap<Item> items = new ObjectIntMap<>();
|
||||
private boolean modified;
|
||||
|
||||
public GlobalData(){
|
||||
Core.settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]);
|
||||
Core.settings.setSerializer(Item.class, (stream, t) -> stream.writeUTF(t.name), stream -> Vars.content.getByName(ContentType.item, stream.readUTF()));
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
modified = true;
|
||||
items.getAndIncrement(item, 0, amount);
|
||||
}
|
||||
|
||||
public ObjectIntMap<Item> items(){
|
||||
return items;
|
||||
}
|
||||
@@ -43,6 +49,7 @@ public class GlobalData{
|
||||
|
||||
//fire unlock event so other classes can use it
|
||||
if(ret){
|
||||
modified = true;
|
||||
content.onUnlock();
|
||||
Events.fire(new UnlockEvent(content));
|
||||
save();
|
||||
@@ -56,6 +63,13 @@ public class GlobalData{
|
||||
save();
|
||||
}
|
||||
|
||||
public void checkSave(){
|
||||
if(modified){
|
||||
save();
|
||||
modified = false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load(){
|
||||
unlocked = Core.settings.getObject("unlocks", ObjectMap.class, ObjectMap::new);
|
||||
|
||||
Reference in New Issue
Block a user