Skip to content

Commit

Permalink
Seek NameGen.txt from StreamingAssets.txt
Browse files Browse the repository at this point in the history
Default NameGen is loaded from Resources as always, and will now seek a replacement NameGen.txt in StreamingAssets/Text.
The master NameGen.txt file is supplied along with CSV files. However, this is a JSON file not a CSV file.
  • Loading branch information
Interkarma committed Oct 11, 2023
1 parent aa996c3 commit 80f8857
Show file tree
Hide file tree
Showing 3 changed files with 1,146 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Assets/Scripts/Game/Utility/NameHelper.cs
@@ -1,4 +1,4 @@
// Project: Daggerfall Unity
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2022 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand All @@ -10,6 +10,7 @@
//

using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using DaggerfallWorkshop.Game.Entity;
Expand All @@ -25,6 +26,8 @@ public class NameHelper
#region Fields

const string nameGenFilename = "NameGen";
const string textString = "Text";
const string txtExt = ".txt";

Dictionary<BankTypes, NameBank> bankDict = null;

Expand Down Expand Up @@ -370,12 +373,21 @@ void LoadNameGenData()
{
try
{
TextAsset nameGenText = Resources.Load<TextAsset>(nameGenFilename) as TextAsset;
bankDict = SaveLoadManager.Deserialize(typeof(Dictionary<BankTypes, NameBank>), nameGenText.text) as Dictionary<BankTypes, NameBank>;
// Load default NameGen asset from Resources
TextAsset nameGenAsset = Resources.Load<TextAsset>(nameGenFilename) as TextAsset;
string nameGenText = nameGenAsset.text;

// Look for a replacement NameGen file from StreamingAssets/Text
string streamingPath = Path.Combine(Application.streamingAssetsPath, textString, nameGenFilename + txtExt);
if (File.Exists(streamingPath))
nameGenText = File.ReadAllText(streamingPath);

// Deserialize into namebank dictionary
bankDict = SaveLoadManager.Deserialize(typeof(Dictionary<BankTypes, NameBank>), nameGenText) as Dictionary<BankTypes, NameBank>;
}
catch
{
Debug.Log("Could not load NameGen database from Resources. Check file exists and is in correct format.");
Debug.Log("Could not load or deserialize NameGen.txt database from StreamingAssets/Text or internal Resources. Check file exists and is in correct format.");
}
}

Expand Down

0 comments on commit 80f8857

Please sign in to comment.