-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomObjects.cs
69 lines (58 loc) · 2.1 KB
/
CustomObjects.cs
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
using Microsoft.Xna.Framework;
using StardewValley;
using System.Collections.Generic;
namespace StardewCustoms
{
public static class CustomObjectHandler
{
public static int BaseItemId
{
get { return 921; }
}
private static Dictionary<string, CustomObject> CustomObjects = new Dictionary<string, CustomObject>();
internal static void Setup()
{
//first, create our base object data
Game1.objectInformation.Add(BaseItemId, "CustomItem / 375 / -300 / Basic - 26 / CustomItem / A custom item that isn't loaded properly.");
}
//this is a public API method
public static void RegisterCustomObject(CustomObject customObject)
{
if(customObject != null) {
if (string.IsNullOrWhiteSpace(customObject.ObjectId)) customObject.ObjectId = "?";
if (string.IsNullOrWhiteSpace(customObject.ModId)) customObject.ModId = "?";
CustomObjects[customObject.GlobalId] = customObject;
}
}
}
//this is a class designed to be implemented by other mods
//nearly everything here should be virtual/overrideable
//our base class, handed to the game, will forward most calls to this instance
//(to avoid having people mess with a class that does internal stuff for us)
public class CustomObject
{
public string ObjectId;
public string ModId;
public string GlobalId
{
get { return ModId + ":" + ObjectId; }
}
public CustomObject(string modId, string objectId)
{
ModId = modId;
ObjectId = objectId; //can be anything really, long as its unique. CamelCase recommended.
}
}
public class CustomObjectInstance : Object
{
private CustomObject CustomObjectData;
//deserialization constructor
public CustomObjectInstance()
{
}
//item creation constructor
public CustomObjectInstance(Vector2 location) : base(location, CustomObjectHandler.BaseItemId)
{
}
}
}