summaryrefslogtreecommitdiff
path: root/StardewModdingAPI/Inheritance/SGameLocation.cs
blob: 2d9a17ecd178a3bdac4395379a783b2d0b30d9dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;

namespace StardewModdingAPI.Inheritance
{
    [Obsolete]
    public class SGameLocation : GameLocation
    {
        public GameLocation BaseGameLocation { get; private set; }

        public SerializableDictionary<Vector2, SObject> ModObjects { get; set; }

        public static SGameLocation ConstructFromBaseClass(GameLocation baseClass, bool copyAllData = false)
        {
            SGameLocation s = new SGameLocation();
            s.BaseGameLocation = baseClass;
            s.name = baseClass.name;

            Log.Debug("CONSTRUCTED: " + s.name);

            if (copyAllData)
            {
                foreach (var v in baseClass.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    try
                    {
                        var fi = s.GetType().GetField(v.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        if (fi != null && !fi.IsStatic)
                        {
                            fi.SetValue(s, v.GetValue(baseClass));
                            //Console.WriteLine("SET {0} ON {1} TO {2}", fi.Name, s.name, v.GetValue(baseClass));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                }
            }

            return s;
        }

        public static List<SGameLocation> ConstructFromBaseClasses(List<GameLocation> baseGameLocations, bool copyAllData = false)
        {
            return baseGameLocations.Select(gl => ConstructFromBaseClass(gl, copyAllData)).ToList();
        }

        public virtual void update(GameTime gameTime)
        {
        }

        public override void draw(SpriteBatch b)
        {
            foreach (var v in ModObjects)
            {
                v.Value.draw(b, (int)v.Key.X, (int)v.Key.Y, 0.999f, 1);
            }
        }

        public SGameLocation()
        {
            ModObjects = new SerializableDictionary<Vector2, SObject>();
        }
    }
}