Skip to content

Commit 87fa75d

Browse files
Merge pull request #4 from CoderGamester/develop
0.2.0
2 parents 737e1b2 + 5e0ba6a commit 87fa75d

14 files changed

+94
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.0] - 2020-01-15
8+
9+
- Added ParseIgnoreAttribute to allow fields to be ignored during deserialization
10+
- Improved tests with [ParseIgnore] attribute test
11+
12+
**Changed**:
13+
- Moved CsvParser to the runtime assembly to be able to use during a project runtime
14+
715
## [0.1.2] - 2020-01-08
816

917
- Added missing meta files

Editor/GameLovers.GoogleSheetImporter.Editor.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"GUID:9e24947de15b9834991c9d8411ea37cf",
55
"GUID:69448af7b92c7f342b298e06a37122aa",
66
"GUID:1b354f7d3d1d147e9b3ba2ee219c0839",
7-
"GUID:22c6cdfa54ae844a9a9eda2f0014b020"
7+
"GUID:22c6cdfa54ae844a9a9eda2f0014b020",
8+
"GUID:97e8c5e426b7946028b98691397a84d4"
89
],
910
"includePlatforms": [
1011
"Editor"

Editor/GoogleSheetConfigsImporter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Runtime.Remoting.Messaging;
23
using GameLovers.ConfigsContainer;
4+
using GameLovers.GoogleSheetImporter;
35
using UnityEditor;
46
using UnityEngine;
57

@@ -37,10 +39,18 @@ public void Import(List<Dictionary<string, string>> data)
3739

3840
foreach (var pair in data)
3941
{
40-
scriptableObject.Configs.Add(CsvParser.DeserializeTo<TConfig>(pair));
42+
scriptableObject.Configs.Add(Deserialize(pair));
4143
}
4244

4345
EditorUtility.SetDirty(scriptableObject);
4446
}
47+
48+
/// <summary>
49+
/// Override this method to have your own deserialization of the given <paramref name="data"/>
50+
/// </summary>
51+
protected virtual TConfig Deserialize(Dictionary<string, string> data)
52+
{
53+
return CsvParser.DeserializeTo<TConfig>(data);
54+
}
4555
}
4656
}

Editor/GoogleSheetToolImporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using GameLovers.GoogleSheetImporter;
45
using UnityEditor;
56
using UnityEditor.Callbacks;
67
using UnityEngine;

Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/CsvParser.cs renamed to Runtime/CsvParser.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// ReSharper disable once CheckNamespace
1010

11-
namespace GameLoversEditor.GoogleSheetImporter
11+
namespace GameLovers.GoogleSheetImporter
1212
{
1313
/// <summary>
1414
/// Helper class to parse CSV text
@@ -24,6 +24,7 @@ public static T DeserializeTo<T>(Dictionary<string, string> data)
2424
var dictionaryType = typeof(IDictionary);
2525
var listType = typeof(IList);
2626
var keyValueType = typeof(KeyValuePair<,>);
27+
var ignoreType = typeof(ParseIgnoreAttribute);
2728
var instance = Activator.CreateInstance(type);
2829

2930
foreach (var field in type.GetFields())
@@ -33,6 +34,13 @@ public static T DeserializeTo<T>(Dictionary<string, string> data)
3334
Debug.LogWarning($"The data does not contain the field {field.Name} data for the object of {type} type");
3435
continue;
3536
}
37+
38+
if (field.GetCustomAttributes(ignoreType, false).Length == 1)
39+
{
40+
continue;
41+
}
42+
43+
Debug.Log(field.Name + " " + field.GetCustomAttributes(ignoreType, false).Length);
3644

3745
var stringSerialized = "";
3846

File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "GameLovers.GoogleSheetImporter",
3+
"references": [],
4+
"includePlatforms": [],
5+
"excludePlatforms": [],
6+
"allowUnsafeCode": false,
7+
"overrideReferences": false,
8+
"precompiledReferences": [],
9+
"autoReferenced": true,
10+
"defineConstraints": [],
11+
"versionDefines": [],
12+
"noEngineReferences": false
13+
}

Runtime/GameLovers.GoogleSheetImporter.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/ParseIgnoreAttribute.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
// ReSharper disable once CheckNamespace
4+
5+
namespace GameLovers.GoogleSheetImporter
6+
{
7+
/// <summary>
8+
/// Attribute to ignore the parsing of a field in <seealso cref="CsvParse"/>
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Field)]
11+
public class ParseIgnoreAttribute : Attribute
12+
{
13+
}
14+
}

0 commit comments

Comments
 (0)