Ejemplo n.º 1
0
 private static int getBuilding(ISaveObject obj)
 {
     if (!obj.Environment.isStructure)
     {
         return(-1);
     }
     return(Game1.getFarm().buildings.FindIndex(x => x.indoors == obj.Environment));
 }
Ejemplo n.º 2
0
        private static ISaveObject loadObject(string type, dynamic additionalSaveData)
        {
            Type        T         = Type.GetType(type);
            ISaveObject newObject = (ISaveObject)Activator.CreateInstance(T);

            newObject.rebuildFromSave(additionalSaveData);

            return(newObject);
        }
Ejemplo n.º 3
0
        private static int inInventory(ISaveObject obj)
        {
            if (!obj.InStorage)
            {
                return(-1);
            }

            return(Game1.player.items.FindIndex(x => x == obj));
        }
Ejemplo n.º 4
0
        private static int inFridge(ISaveObject obj)
        {
            if (!obj.InStorage)
            {
                return(-1);
            }

            return((Game1.getLocationFromName("FarmHouse") as FarmHouse).fridge.items.FindIndex(x => x == obj));
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        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;
            }
        }
Ejemplo n.º 9
0
 public static void drawInMenu(ISaveObject obj)
 {
     obj.Environment = Game1.currentLocation;
     obj.InStorage   = true;
 }
Ejemplo n.º 10
0
 public static void draw(ISaveObject obj, Vector2 tilelocation)
 {
     obj.Environment = Game1.currentLocation;
     obj.InStorage   = false;
     obj.Position    = tilelocation;
 }
Ejemplo n.º 11
0
 public static void register(ISaveObject obj)
 {
     registry.Add(obj);
     obj.Environment = Game1.currentLocation;
     obj.InStorage   = true;
 }
Ejemplo n.º 12
0
 public static void AddObj(ISaveObject <SaveObject> saveObject)
 {
     listObj.Add(saveObject);
 }