Skip to content

Commit

Permalink
Assetdex and Browser
Browse files Browse the repository at this point in the history
- Ported "Assetdex and Browser" PR
  • Loading branch information
vawser committed Jan 7, 2024
1 parent 33974db commit 4b3ae50
Show file tree
Hide file tree
Showing 51 changed files with 312,030 additions and 258 deletions.
6 changes: 6 additions & 0 deletions src/Studio.App/DSMapStudio/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ Pos=397,61
Size=410,270
Collapsed=0

[Window][Asset Browser##MsbAssetBrowser]
Pos=225,870
Size=1051,490
Collapsed=0
DockId=0x00000006,3

[Docking][Data]
DockSpace ID=0xA747ECD2 Window=0xEAABAB29 Pos=0,40 Size=1920,987 Split=X
DockNode ID=0x00000007 Parent=0xA747ECD2 SizeRef=1531,987 Split=X
Expand Down
2 changes: 1 addition & 1 deletion src/StudioCore/AssetLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public AssetDescription GetMsgbnd(string msgBndType, string langFolder, bool wri
return ad;
}

private string GetGameIDForDir()
public string GetGameIDForDir()
{
switch (Type)
{
Expand Down
65 changes: 65 additions & 0 deletions src/StudioCore/Assetdex/AssetContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Org.BouncyCastle.Pqc.Crypto.Lms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
using static SoulsFormats.HKXPWV;

namespace StudioCore.Assetdex
{
public class AssetContainer
{
private AssetResource chrEntries = new AssetResource();
private AssetResource objEntries = new AssetResource();
private AssetResource partEntries = new AssetResource();
private AssetResource mapPieceEntries = new AssetResource();

public AssetContainer(string gametype)
{
chrEntries = LoadJSON(gametype, "Chr");
objEntries = LoadJSON(gametype, "Obj");
partEntries = LoadJSON(gametype, "Part");
mapPieceEntries = LoadJSON(gametype, "MapPiece");
}

private AssetResource LoadJSON(string gametype, string type)
{
AssetResource resource = new AssetResource();

string json_filepath = AppContext.BaseDirectory + $"\\Assets\\Assetdex\\{gametype}\\{type}.json";

if (File.Exists(json_filepath))
{
var options = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Skip,
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};
resource = JsonSerializer.Deserialize<AssetResource>(File.OpenRead(json_filepath), options);
}

return resource;
}

public List<AssetReference> GetChrEntries()
{
return chrEntries.list;
}
public List<AssetReference> GetObjEntries()
{
return objEntries.list;
}
public List<AssetReference> GetPartEntries()
{
return partEntries.list;
}
public List<AssetReference> GetMapPieceEntries()
{
return mapPieceEntries.list;
}
}
}
18 changes: 18 additions & 0 deletions src/StudioCore/Assetdex/AssetReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudioCore.Assetdex
{
/// <summary>
/// Class <c>AssetReference</c> is an entry contained within a <c>AssetReference</c> list within a <c>GameReference</c>.
/// </summary>
public class AssetReference
{
public string id { get; set; }
public string name { get; set; }
public List<string> tags { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/StudioCore/Assetdex/AssetResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace StudioCore.Assetdex
{
/// <summary>
/// Class <c>AssetdexResource</c> is the root object filled by the JSON deserialization.
/// </summary>
public class AssetResource
{
public List<AssetReference> list { get; set; }
}
}
91 changes: 91 additions & 0 deletions src/StudioCore/Assetdex/AssetdexCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace StudioCore.Assetdex
{
/// <summary>
/// Class <c>AssetdexCore</c> contains the <c>AssetReference</c> dictionaries that host the documentation for each asset.
/// </summary>
public class AssetdexCore
{
private Dictionary<GameType, AssetContainer> assetContainers = new Dictionary<GameType, AssetContainer>();

public AssetdexCore()
{
assetContainers.Add(GameType.Undefined, BuildAssetContainer("DS1")); // Fallback for Undefined project
assetContainers.Add(GameType.DemonsSouls, BuildAssetContainer("DES"));
assetContainers.Add(GameType.DarkSoulsPTDE, BuildAssetContainer("DS1"));
assetContainers.Add(GameType.DarkSoulsRemastered, BuildAssetContainer("DS1R"));
assetContainers.Add(GameType.DarkSoulsIISOTFS, BuildAssetContainer("DS2S"));
assetContainers.Add(GameType.Bloodborne, BuildAssetContainer("BB"));
assetContainers.Add(GameType.DarkSoulsIII, BuildAssetContainer("DS3"));
assetContainers.Add(GameType.Sekiro, BuildAssetContainer("SDT"));
assetContainers.Add(GameType.EldenRing, BuildAssetContainer("ER"));
assetContainers.Add(GameType.ArmoredCoreVI, BuildAssetContainer("AC6"));
}

private AssetContainer BuildAssetContainer(string gametype)
{
AssetContainer container = new AssetContainer(gametype);

return container;
}

public Dictionary<string, AssetReference> GetChrEntriesForGametype(GameType gametype)
{
Dictionary<string, AssetReference> dict = new Dictionary<string, AssetReference>();

foreach(AssetReference entry in assetContainers[gametype].GetChrEntries())
{
if(!dict.ContainsKey(entry.id.ToLower()))
dict.Add(entry.id.ToLower(), entry);
}

return dict;
}

public Dictionary<string, AssetReference> GetObjEntriesForGametype(GameType gametype)
{
Dictionary<string, AssetReference> dict = new Dictionary<string, AssetReference>();

foreach (AssetReference entry in assetContainers[gametype].GetObjEntries())
{
if (!dict.ContainsKey(entry.id.ToLower()))
dict.Add(entry.id.ToLower(), entry);
}

return dict;
}

public Dictionary<string, AssetReference> GetPartEntriesForGametype(GameType gametype)
{
Dictionary<string, AssetReference> dict = new Dictionary<string, AssetReference>();

foreach (AssetReference entry in assetContainers[gametype].GetPartEntries())
{
if (!dict.ContainsKey(entry.id.ToLower()))
dict.Add(entry.id.ToLower(), entry);
}

return dict;
}

public Dictionary<string, AssetReference> GetMapPieceEntriesForGametype(GameType gametype)
{
Dictionary<string, AssetReference> dict = new Dictionary<string, AssetReference>();

foreach (AssetReference entry in assetContainers[gametype].GetMapPieceEntries())
{
if (!dict.ContainsKey(entry.id.ToLower()))
dict.Add(entry.id.ToLower(), entry);
}

return dict;
}
}
}
Loading

0 comments on commit 4b3ae50

Please sign in to comment.