[Solved] Adding Custom Item Problem, ItemTemplates.txt Not Being Read

Discuss modding questions and implementation details.
Post Reply
User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

[Solved] Adding Custom Item Problem, ItemTemplates.txt Not Being Read

Post by Magicono43 »

Short of it, i'm adding some custom items, they seem to be getting registered properly on launch, but when the items appear in a shop they are broken and don't have any of the info that the ItemTemplate should hold, nor do they even have any Index value.
Capture11111.JPG
Capture11111.JPG (79.93 KiB) Viewed 891 times
Capture111112.JPG
Capture111112.JPG (14.47 KiB) Viewed 891 times
Capture111113.JPG
Capture111113.JPG (91.7 KiB) Viewed 891 times
The only thing I can think of that is going wrong is that maybe i'm not adding the ItemTemplates.txt "asset" properly in the building process? I'm just adding it into the build just like the rest of the scripts used, so i'm not sure what else to do with it.
Last edited by Magicono43 on Sat Jun 27, 2020 7:44 pm, edited 1 time in total.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Adding Custom Item Problem, ItemTemplates.txt Not Being Read

Post by Magicono43 »

Here are all of the assets and scripts that are currently having this problem, as well as the .dfmod file itself.

Here is the Github Repo as well: https://github.com/magicono43/DFU-Mod_M ... pair-Items

To reproduce just go into any general store and scroll down in the item list and you will see the broken items.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: [Solved] Adding Custom Item Problem, ItemTemplates.txt Not Being Read

Post by Magicono43 »

Alright, so I was able to figure out the issue myself, and it was a stupid reason, as they usually are. The short of it, the ItemTemplates file needs to be a ".json" file, NOT a ".txt" file. The reason I made this assumption that .txt was correct was because in the DFU files, the "ItemTemplates" file in there has the .txt extension, as well as any mods that added or changed items from the ItemTemplates file I had examined their code with the "ExtractToText" function, and this would turn all of the readable assets in said mod into .txt files, but would leave the extension for some of them in the name such as ".cs.txt" or ".dfmod.txt" so I had assumed it would be the same for .json if it was built originally with that extension, but apparently not, .json is translated seamlessly to a .txt file in this case.

Here is the block of code that hinted me to this fact from the "ItemHelper.cs" script:

Code: Select all

/// <summary>
        /// Loads item templates from JSON file.
        /// This data was exported from Daggerfall's FALL.EXE file.
        /// </summary>
        void LoadItemTemplates()
        {
            try
            {
                TextAsset templates = Resources.Load<TextAsset>(itemTemplatesFilename);
                itemTemplates = SaveLoadManager.Deserialize(typeof(List<ItemTemplate>), templates.text) as List<ItemTemplate>;
                TextAssetReader.Merge(itemTemplates, "ItemTemplates.json", (item, data) => item.index == (int)data["index"].AsInt64);
            }
            catch
            {
                Debug.LogError("Could not load ItemTemplates database from Resources. Check file exists and is in correct format.");
            }
        }
While I am slightly annoyed that I was fooled by this assumption which lead to an error, I am glad it was a simple fix, and maybe if somebody searches for the same problem later on this might help them as well.

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [Solved] Adding Custom Item Problem, ItemTemplates.txt Not Being Read

Post by Hazelnut »

Great, well spotted. In future if you're doing something one of my mods have done you can look at exactly what files, how they are organised, and what extensions they have in my mods repo on github. The mod packages are build directly from these files.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply