Skip to content

Commit

Permalink
Merge pull request #30 from ashblue/feature/fix-add-without-display-name
Browse files Browse the repository at this point in the history
fix(item creation): no longer crashes when `_displayName` field is mi…
  • Loading branch information
ashblue authored Jan 11, 2025
2 parents 1bc6125 + 672c064 commit 0846d36
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions Assets/Examples/Resources/ItemDatabase.asset
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
_autoLoad: 1
_definitions:
- {fileID: 11400000, guid: 80d3b6ab2a78e6b418da8aed88e32926, type: 2}
- {fileID: 11400000, guid: d3988ba3f8a2c44e6a1b98201ce75ee2, type: 2}
- {fileID: 11400000, guid: 4e2438a1b36c043e587e88575d07b5ff, type: 2}
- {fileID: 11400000, guid: 5e7593ddbeb614a3984bd7fcc9251406, type: 2}
Expand Down
15 changes: 15 additions & 0 deletions Assets/Examples/Shop/Definitions/CustomItem.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e149b91f3de145dc9820a3c795b7b05a, type: 3}
m_Name: CustomItem
m_EditorClassIdentifier:
_id: fe563339-c771-4245-9db6-3b38dccf7426
8 changes: 8 additions & 0 deletions Assets/Examples/Shop/Definitions/CustomItem.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CleverCrow.Fluid.ElasticInventory;

namespace CleverCrow.Fluid.Examples {
/// <summary>
/// Simulates creating a custom display name and category for an item definition
/// </summary>
[ItemDefinitionDetails("Custom Display Details")]
public class ItemDefinitionCustomDisplayName : ItemDefinitionBase {
public override string DisplayName => "Custom Display Name";
public override string Category => "Custom Category";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ void CreateItemDefinition (ItemDatabase database, Type type) {

var serializedObject = new SerializedObject(itemDefinition);
var fileName = System.IO.Path.GetFileNameWithoutExtension(path);
serializedObject.FindProperty("_displayName").stringValue = MakeSpacedWord(fileName);

// Set the display name to be the spaced version of the file name (if it exists)
var displayName = serializedObject.FindProperty("_displayName");
if (displayName != null) {
displayName.stringValue = MakeSpacedWord(fileName);
}

// @TODO Duplicate IDs are inevitable due to object cloning, repair them automatically when refreshing asset references
serializedObject.FindProperty("_id").stringValue = Guid.NewGuid().ToString();
serializedObject.ApplyModifiedPropertiesWithoutUndo();
Expand Down

0 comments on commit 0846d36

Please sign in to comment.