-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathAssetModifier.cs
132 lines (115 loc) · 5.48 KB
/
AssetModifier.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using xTile.Dimensions;
using xTile.Layers;
using xTile.Tiles;
namespace DesertObelisk
{
public class AssetModifier : IAssetLoader, IAssetEditor
{
private readonly int desertWarpX;
private readonly IModHelper helper;
private readonly Texture2D obeliskTexture;
public AssetModifier(IModHelper helper, IMonitor monitor, int desertWarpX)
{
this.helper = helper;
this.desertWarpX = desertWarpX;
IManifest loadedManifest = null;
foreach (var contentPack in helper.ContentPacks.GetOwned())
{
if (loadedManifest != null)
{
monitor.Log(
$"Could not load obelisk texture from {contentPack.Manifest.Name} ({contentPack.Manifest.UniqueID}) because {loadedManifest.Name} ({loadedManifest.UniqueID}) is already loaded.",
LogLevel.Warn);
continue;
}
try
{
this.obeliskTexture = contentPack.LoadAsset<Texture2D>("assets/Desert Obelisk.png");
loadedManifest = contentPack.Manifest;
monitor.Log($"Loaded obelisk texture from {loadedManifest.Name} ({loadedManifest.UniqueID}).",
LogLevel.Debug);
}
catch
{
monitor.Log(
$"Could not load obelisk texture from {contentPack.Manifest.Name} ({contentPack.Manifest.UniqueID}) because no valid texture was found.",
LogLevel.Warn);
monitor.Log(
"The accepted format is an image named 'Desert Obelisk.png' inside a folder named 'assets' in the root content pack folder.",
LogLevel.Warn);
}
}
if (this.obeliskTexture == null)
{
if (helper.ModRegistry.IsLoaded("Lita.StarblueValley"))
{
monitor.Log(
"No valid content pack was found but Starblue Valley is installed, using Starblue obelisk texture.",
LogLevel.Trace);
this.obeliskTexture = helper.Content.Load<Texture2D>("assets/Desert Obelisk Starblue.png");
}
else
{
monitor.Log(
"Loaded default obelisk texture because no content packs or Starblue Valley were found/valid.",
LogLevel.Trace);
this.obeliskTexture = helper.Content.Load<Texture2D>("assets/Desert Obelisk.png");
}
}
helper.Content.AssetLoaders.Add(this);
helper.Content.AssetEditors.Add(this);
this.ModifyMap();
}
public bool CanEdit<T>(IAssetInfo asset)
{
return asset.AssetNameEquals(@"Data\Blueprints");
}
public void Edit<T>(IAssetData asset)
{
if (asset.AssetNameEquals(@"Data\Blueprints"))
asset.AsDictionary<string, string>().Data.Add("Desert Obelisk",
"337 10 768 10/3/3/-1/-1/-2/-1/null/Desert Obelisk/Warps you to the desert./Buildings/none/48/128/-1/null/Farm/1000000/true");
}
public bool CanLoad<T>(IAssetInfo asset)
{
return asset.AssetNameEquals(@"Buildings\Desert Obelisk");
}
public T Load<T>(IAssetInfo asset)
{
return (T)(object)this.obeliskTexture;
}
public void ModifyMap()
{
this.helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
}
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (!Context.IsWorldReady || !e.IsOneSecond)
return;
GameLocation desert = Game1.getLocationFromName("Desert");
TileSheet markerTileSheet = new TileSheet("zDesertObeliskTileSheet", desert.map,
this.helper.Content.GetActualAssetKey("assets/markerTiles"), new Size(2, 3), new Size(16, 16));
desert.map.AddTileSheet(markerTileSheet);
Layer frontLayer = desert.map.GetLayer("Front");
Layer buildingsLayer = desert.map.GetLayer("Buildings");
frontLayer.Tiles[this.desertWarpX, 40] = new StaticTile(frontLayer, markerTileSheet, BlendMode.Alpha, 0);
frontLayer.Tiles[this.desertWarpX + 1, 40] =
new StaticTile(frontLayer, markerTileSheet, BlendMode.Alpha, 1);
frontLayer.Tiles[this.desertWarpX, 41] = new StaticTile(frontLayer, markerTileSheet, BlendMode.Alpha, 2);
frontLayer.Tiles[this.desertWarpX + 1, 41] =
new StaticTile(frontLayer, markerTileSheet, BlendMode.Alpha, 3);
buildingsLayer.Tiles[this.desertWarpX, 42] =
new StaticTile(buildingsLayer, markerTileSheet, BlendMode.Alpha, 4);
buildingsLayer.Tiles[this.desertWarpX + 1, 42] =
new StaticTile(buildingsLayer, markerTileSheet, BlendMode.Alpha, 5);
this.helper.Events.GameLoop.UpdateTicked -= this.OnUpdateTicked;
}
}
}