1using Microsoft.Xna.Framework;
3using System.Collections.Generic;
5using Terraria.Localization;
11 internal static class MapLoader
13 internal static bool initialized =
false;
14 internal static readonly IDictionary<ushort, IList<MapEntry>> tileEntries =
new Dictionary<ushort, IList<MapEntry>>();
15 internal static readonly IDictionary<ushort, IList<MapEntry>> wallEntries =
new Dictionary<ushort, IList<MapEntry>>();
16 internal static readonly IDictionary<ushort, Func<string, int, int, string>> nameFuncs =
17 new Dictionary<ushort, Func<string, int, int, string>>();
18 internal static readonly IDictionary<ushort, ushort> entryToTile =
new Dictionary<ushort, ushort>();
19 internal static readonly IDictionary<ushort, ushort> entryToWall =
new Dictionary<ushort, ushort>();
21 internal static int modTileOptions(ushort type) {
22 return tileEntries[type].Count;
25 internal static int modWallOptions(ushort type) {
26 return wallEntries[type].Count;
32 internal static void SetupModMap() {
36 Array.Resize(ref MapHelper.tileLookup, TileLoader.TileCount);
37 Array.Resize(ref MapHelper.wallLookup, WallLoader.WallCount);
38 IList<Color> colors =
new List<Color>();
39 IList<LocalizedText> names =
new List<LocalizedText>();
40 foreach (ushort type
in tileEntries.Keys) {
41 MapHelper.tileLookup[type] = (ushort)(MapHelper.modPosition + colors.Count);
42 foreach (MapEntry entry
in tileEntries[type]) {
43 ushort mapType = (ushort)(MapHelper.modPosition + colors.Count);
44 entryToTile[mapType] = type;
45 nameFuncs[mapType] = entry.getName;
46 colors.Add(entry.color);
47 if (entry.name !=
null) {
48 names.Add(entry.name);
51 names.Add(Language.GetText(entry.translation.Key));
55 foreach (ushort type
in wallEntries.Keys) {
56 MapHelper.wallLookup[type] = (ushort)(MapHelper.modPosition + colors.Count);
57 foreach (MapEntry entry
in wallEntries[type]) {
58 ushort mapType = (ushort)(MapHelper.modPosition + colors.Count);
59 entryToWall[mapType] = type;
60 nameFuncs[mapType] = entry.getName;
61 colors.Add(entry.color);
62 if (entry.name !=
null) {
63 names.Add(entry.name);
66 names.Add(Language.GetText(entry.translation.Key));
70 Array.Resize(ref MapHelper.colorLookup, MapHelper.modPosition + colors.Count);
71 Lang._mapLegendCache.Resize(MapHelper.modPosition + names.Count);
72 for (
int k = 0; k < colors.Count; k++) {
73 MapHelper.colorLookup[MapHelper.modPosition + k] = colors[k];
74 Lang._mapLegendCache[MapHelper.modPosition + k] = names[k];
79 internal static void UnloadModMap() {
88 Array.Resize(ref MapHelper.tileLookup, TileID.Count);
89 Array.Resize(ref MapHelper.wallLookup, WallID.Count);
90 Array.Resize(ref MapHelper.colorLookup, MapHelper.modPosition);
91 Lang._mapLegendCache.Resize(MapHelper.modPosition);
96 internal static void ModMapOption(ref ushort mapType,
int i,
int j) {
97 if (entryToTile.ContainsKey(mapType)) {
98 ModTile tile = TileLoader.GetTile(entryToTile[mapType]);
99 ushort option = tile.GetMapOption(i, j);
100 if (option < 0 || option >= modTileOptions(tile.Type)) {
101 throw new ArgumentOutOfRangeException(
"Bad map option for tile " + tile.Name +
" from mod " + tile.mod.Name);
105 else if (entryToWall.ContainsKey(mapType)) {
106 ModWall wall = WallLoader.GetWall(entryToWall[mapType]);
107 ushort option = wall.GetMapOption(i, j);
108 if (option < 0 || option >= modWallOptions(wall.Type)) {
109 throw new ArgumentOutOfRangeException(
"Bad map option for wall " + wall.Name +
" from mod " + wall.mod.Name);