-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
title: ExampleItems_Steve_Root | ||
--- | ||
<<AddMapMarker exampleitems.mapmarker false>> | ||
=== | ||
title: ExampleItems_Steve_Chat | ||
--- | ||
exampleitems.steve: Test #line:ex78383 | ||
=== |
4 changes: 4 additions & 0 deletions
4
Winch.Examples/ExampleItems/Assets/MapMarkers/exampleitems.mapmarker.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"x": 366.0, | ||
"z": -344.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using HarmonyLib; | ||
using Winch.Util; | ||
|
||
namespace Winch.Patches.API | ||
{ | ||
[HarmonyPatch(typeof(DataLoader))] | ||
[HarmonyPatch(nameof(DataLoader.OnGameEnded))] | ||
internal static class MapMarkerClearPatcher | ||
{ | ||
public static void Postfix(DataLoader __instance) | ||
{ | ||
MapMarkerUtil.ClearMapMarkerData(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Winch.Util; | ||
|
||
namespace Winch.Serialization.MapMarker; | ||
|
||
public class MapMarkerDataConverter : DredgeTypeConverter<MapMarkerData> | ||
{ | ||
private readonly Dictionary<string, FieldDefinition> _definitions = new() | ||
{ | ||
{ "x", new(0f, o => float.Parse(o.ToString())) }, | ||
{ "z", new(0f, o => float.Parse(o.ToString())) }, | ||
{ "mapMarkerType", new(MapMarkerType.SIDE, o=> DredgeTypeHelpers.GetEnumValue<MapMarkerType>(o) )}, | ||
}; | ||
|
||
public MapMarkerDataConverter() | ||
{ | ||
AddDefinitions(_definitions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Winch.Core; | ||
using Winch.Serialization.MapMarker; | ||
|
||
namespace Winch.Util; | ||
|
||
public static class MapMarkerUtil | ||
{ | ||
private static MapMarkerDataConverter MapMarkerDataConverter = new MapMarkerDataConverter(); | ||
|
||
internal static bool PopulateMapMarkerDataFromMetaWithConverter(MapMarkerData data, Dictionary<string, object> meta) | ||
{ | ||
return UtilHelpers.PopulateObjectFromMeta(data, meta, MapMarkerDataConverter); | ||
} | ||
|
||
internal static Dictionary<string, MapMarkerData> ModdedMapMarkerDataDict = new(); | ||
internal static Dictionary<string, MapMarkerData> AllMapMarkerDataDict = new(); | ||
|
||
public static MapMarkerData GetModdedMapMarkerData(string id) | ||
{ | ||
if (string.IsNullOrWhiteSpace(id)) | ||
return null; | ||
|
||
if (ModdedMapMarkerDataDict.TryGetValue(id, out MapMarkerData mapMarkerData)) | ||
return mapMarkerData; | ||
else | ||
return null; | ||
} | ||
|
||
public static MapMarkerData GetMapMarkerData(string id) | ||
{ | ||
if (string.IsNullOrWhiteSpace(id)) | ||
return null; | ||
|
||
if (AllMapMarkerDataDict.TryGetValue(id, out var mapMarker)) | ||
return mapMarker; | ||
|
||
if (ModdedMapMarkerDataDict.TryGetValue(id, out var moddedMapMarker)) | ||
return moddedMapMarker; | ||
|
||
return null; | ||
} | ||
|
||
internal static void AddModdedMapMarkerData(IList<MapMarkerData> list) | ||
{ | ||
foreach (var mapMarkerData in ModdedMapMarkerDataDict.Values) | ||
{ | ||
list.SafeAdd(mapMarkerData); | ||
} | ||
} | ||
|
||
internal static void PopulateMapMarkerData(IList<MapMarkerData> result) | ||
{ | ||
foreach (var mapMarkerData in result) | ||
{ | ||
AllMapMarkerDataDict.SafeAdd(mapMarkerData.name, mapMarkerData); | ||
WinchCore.Log.Debug($"Added map marker data {mapMarkerData.name} to AllMapMarkerDataDict"); | ||
} | ||
} | ||
|
||
internal static void ClearMapMarkerData() | ||
{ | ||
AllMapMarkerDataDict.Clear(); | ||
} | ||
|
||
internal static void AddMapMarkerDataFromMeta(string metaPath) | ||
{ | ||
var meta = UtilHelpers.ParseMeta(metaPath); | ||
if (meta == null) | ||
{ | ||
WinchCore.Log.Error($"Meta file {metaPath} is empty"); | ||
return; | ||
} | ||
var mapMarkerData = UtilHelpers.GetScriptableObjectFromMeta<MapMarkerData>(meta, metaPath); | ||
if (mapMarkerData == null) | ||
{ | ||
WinchCore.Log.Error($"Couldn't create MapMarkerData"); | ||
return; | ||
} | ||
var id = (string)meta["id"]; | ||
if (ModdedMapMarkerDataDict.ContainsKey(id)) | ||
{ | ||
WinchCore.Log.Error($"Duplicate map marker data {id} at {metaPath} failed to load"); | ||
return; | ||
} | ||
if (PopulateMapMarkerDataFromMetaWithConverter(mapMarkerData, meta)) | ||
{ | ||
ModdedMapMarkerDataDict.Add(id, mapMarkerData); | ||
} | ||
else | ||
{ | ||
WinchCore.Log.Error($"No map marker data converter found"); | ||
} | ||
} | ||
|
||
public static MapMarkerData[] GetAllMapMarkerData() | ||
{ | ||
return AllMapMarkerDataDict.Values.ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters