private static int getBuilding(ISaveObject obj) { if (!obj.Environment.isStructure) { return(-1); } return(Game1.getFarm().buildings.FindIndex(x => x.indoors == obj.Environment)); }
private static ISaveObject loadObject(string type, dynamic additionalSaveData) { Type T = Type.GetType(type); ISaveObject newObject = (ISaveObject)Activator.CreateInstance(T); newObject.rebuildFromSave(additionalSaveData); return(newObject); }
private static int inInventory(ISaveObject obj) { if (!obj.InStorage) { return(-1); } return(Game1.player.items.FindIndex(x => x == obj)); }
private static int inFridge(ISaveObject obj) { if (!obj.InStorage) { return(-1); } return((Game1.getLocationFromName("FarmHouse") as FarmHouse).fridge.items.FindIndex(x => x == obj)); }
public DataSaver(ISaveObject data, int saveInterval) { Contract.Requires(data != null); this.userData = data; this.changeObserver = new DataChangeObserver(data); this.SaveInterval = saveInterval; this.timer = new Timer(obj => Save()); SetTimer(); }
private static Vector3 inChest(ISaveObject obj) { if (!obj.InStorage) { return(new Vector3(-1)); } foreach (Vector2 keyV in obj.Environment.objects.Keys) { if ((obj.Environment.objects[keyV] is Chest) && (obj.Environment.objects[keyV] as Chest).items.Contains((Item)obj)) { return(new Vector3((obj.Environment.objects[keyV] as Chest).items.FindIndex(x => x == obj), keyV.X, keyV.Y)); } } return(new Vector3(-1));; }
public static void OnObjectLoad <C, S> (C loadedObject, ISaveObject <S> loadedObjectAsSaveableObject, S savedObject) where C : Poolable <C> where S : SaveObjectState { loadedObject.transform.WarpTo(savedObject.position, savedObject.rotation); loadedObjectAsSaveableObject.LoadFromSavedObject(savedObject); // load all saveable information to attached scripts, // maybe a scene item has an inventory or otehr ocmponents thhat need to save their states ISaveAttachment[] saveables = loadedObject.GetComponents <ISaveAttachment>(); for (int i = 0; i < saveables.Length; i++) { Type saveableType = saveables[i].AttachmentType(); for (int x = 0; x < savedObject.attachmentStates.Length; x++) { if (saveableType == savedObject.attachmentStates[x].type) { saveables[i].OnLoaded(savedObject.attachmentStates[x].state); break; } } } }
public static void LoadAndReplace() { if (saveString == "") { return; } JArray loadJson = JArray.Parse(saveString); foreach (dynamic obj in loadJson) { string type = (string)obj.type; dynamic data = (dynamic)obj.data; string location = (string)obj.placement.location; Vector2 position = (Vector2)obj.placement.position; int index = (int)obj.placement.index; int building = (int)obj.placement.building; ISaveObject next = loadObject(type, data); if (location.Contains("Barn") || location.Contains("Coop") || location.Contains("Shed") || location.Equals("House")) { location = "Farm"; } if (location == "Inventory") { Game1.player.items[index] = (Item)next; continue; } if (location == "Fridge") { (Game1.getLocationFromName("FarmHouse") as FarmHouse).fridge.items[index] = (Item)next; continue; } GameLocation g = Game1.getLocationFromName(location); GameLocation place; if (building >= 0) { place = (g as BuildableGameLocation).buildings[building].indoors; } else { place = g; } if (index >= 0) { (place.objects[position] as Chest).items[index] = (Item)next; continue; } place.objects[position] = (StardewValley.Object)next; } }
public static void drawInMenu(ISaveObject obj) { obj.Environment = Game1.currentLocation; obj.InStorage = true; }
public static void draw(ISaveObject obj, Vector2 tilelocation) { obj.Environment = Game1.currentLocation; obj.InStorage = false; obj.Position = tilelocation; }
public static void register(ISaveObject obj) { registry.Add(obj); obj.Environment = Game1.currentLocation; obj.InStorage = true; }
public static void AddObj(ISaveObject <SaveObject> saveObject) { listObj.Add(saveObject); }