Skip to content

Commit 6d7f278

Browse files
Merge pull request #12 from CoderGamester/develop
Release 0.6.0
2 parents fccafa8 + ea285d7 commit 6d7f278

9 files changed

+161
-12
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ 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.5.3] - 2020-03-07
7+
## [0.6.0] - 2020-07-28
8+
9+
- Added *ConfigsProvider* to provide the loaded google sheet configs
10+
- Added *IConfigsContainer* to provide the interface to maintain the loaded google sheet configs
11+
12+
**Changed**:
13+
- Removed the dependency to the *com.gamelovers.configscontainer* & *com.gamelovers.asyncawait* package
14+
15+
## [0.5.3] - 2020-04-25
816

917
- Updated the package *com.gamelovers.configscontainer* to version 0.7.0
1018
- Updated *GoogleSheetImporter* documentation
@@ -35,7 +43,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3543
- Improved the parsing performance
3644

3745
**Changed**:
38-
3946
- Now generic types have their values properly parsed to their value instead of paring always to string. This will allow to avoid unnecessary later conversion on the importers.
4047

4148
## [0.3.0] - 2020-01-20

Editor/GameLovers.GoogleSheetImporter.Editor.asmdef

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"references": [
44
"GUID:9e24947de15b9834991c9d8411ea37cf",
55
"GUID:69448af7b92c7f342b298e06a37122aa",
6-
"GUID:1b354f7d3d1d147e9b3ba2ee219c0839",
7-
"GUID:22c6cdfa54ae844a9a9eda2f0014b020",
86
"GUID:97e8c5e426b7946028b98691397a84d4"
97
],
108
"includePlatforms": [

Editor/GoogleSheetConfigsImporter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Runtime.Remoting.Messaging;
3-
using GameLovers.ConfigsContainer;
42
using GameLovers.GoogleSheetImporter;
53
using UnityEditor;
64
using UnityEngine;

Editor/GoogleSheetToolImporter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using System.Threading.Tasks;
45
using GameLovers.GoogleSheetImporter;
56
using UnityEditor;
67
using UnityEditor.Callbacks;
78
using UnityEngine;
89
using UnityEngine.Networking;
9-
using GameLovers.AsyncAwait;
1010
using Debug = UnityEngine.Debug;
1111

1212
// ReSharper disable once CheckNamespace
@@ -148,7 +148,7 @@ private static async void ImportSheetAsync(ImportData data, string spreadsheetId
148148
var finalUrl = string.IsNullOrWhiteSpace(spreadsheetId) ? url : url.Remove(indexStart, indexCount).Insert(indexStart, spreadsheetId);
149149
var request = UnityWebRequest.Get(finalUrl);
150150

151-
await request.SendWebRequest();
151+
await AsyncOperation(request.SendWebRequest());
152152

153153
if (request.isHttpError || request.isNetworkError)
154154
{
@@ -169,6 +169,14 @@ private static async void ImportSheetAsync(ImportData data, string spreadsheetId
169169
Debug.Log($"Finished importing google sheet data from {data.Type.Name}");
170170
}
171171

172+
private static async Task AsyncOperation(AsyncOperation operation)
173+
{
174+
while (!operation.isDone)
175+
{
176+
await Task.Delay(100);
177+
}
178+
}
179+
172180
private struct ImportData
173181
{
174182
public Type Type;

Runtime/ConfigsProvider.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
6+
// ReSharper disable once CheckNamespace
7+
8+
namespace GameLovers.GoogleSheetImporter
9+
{
10+
/// <summary>
11+
/// Provides all the Game's config static data, including the game design data
12+
/// Has the imported data from the Universal Google Sheet file on the web
13+
/// </summary>
14+
public interface IConfigsProvider
15+
{
16+
/// <summary>
17+
/// Requests the single unique Config of <typeparamref name="T"/> type
18+
/// </summary>
19+
T GetSingleConfig<T>();
20+
21+
/// <summary>
22+
/// Requests the Config of <typeparamref name="T"/> type and with the given <paramref name="id"/>
23+
/// </summary>
24+
T GetConfig<T>(int id);
25+
26+
/// <summary>
27+
/// Requests the Config List of <typeparamref name="T"/> type
28+
/// </summary>
29+
IReadOnlyList<T> GetConfigsList<T>();
30+
31+
/// <summary>
32+
/// Requests the Config Dictionary of <typeparamref name="T"/> type
33+
/// </summary>
34+
IReadOnlyDictionary<int, T> GetConfigsDictionary<T>();
35+
}
36+
37+
/// <inheritdoc />
38+
public class ConfigsProvider : IConfigsProvider
39+
{
40+
private const int _singleConfigId = 0;
41+
42+
private readonly IDictionary<Type, IEnumerable> _configs = new Dictionary<Type, IEnumerable>();
43+
44+
/// <inheritdoc />
45+
public T GetSingleConfig<T>()
46+
{
47+
return GetConfigsDictionary<T>()[_singleConfigId];
48+
}
49+
50+
/// <inheritdoc />
51+
public T GetConfig<T>(int id)
52+
{
53+
return GetConfigsDictionary<T>()[id];
54+
}
55+
56+
/// <inheritdoc />
57+
public IReadOnlyList<T> GetConfigsList<T>()
58+
{
59+
return new List<T>(GetConfigsDictionary<T>().Values);
60+
}
61+
62+
/// <inheritdoc />
63+
public IReadOnlyDictionary<int, T> GetConfigsDictionary<T>()
64+
{
65+
return _configs[typeof(T)] as IReadOnlyDictionary<int, T>;
66+
}
67+
68+
/// <summary>
69+
/// Adds the given unique single <paramref name="config"/> to the container.
70+
/// Use the <seealso cref="GetSingletonConfig{T}"/> to retrieve it.
71+
/// </summary>
72+
public void AddSingletonConfig<T>(T config)
73+
{
74+
_configs.Add(typeof(T), new ReadOnlyDictionary<int, T>(new Dictionary<int, T> {{ _singleConfigId, config }}));
75+
}
76+
77+
/// <summary>
78+
/// Adds the given <paramref name="configList"/> to the container.
79+
/// The configuration will use the given <paramref name="referenceIdResolver"/> to map each config to it's defined id.
80+
/// Use the <seealso cref="GetConfig{T}"/> to retrieve it.
81+
/// </summary>
82+
public void AddConfigs<T>(Func<T, int> referenceIdResolver, IList<T> configList) where T : struct
83+
{
84+
var dictionary = new Dictionary<int, T>();
85+
86+
for (int i = 0; i < configList.Count; i++)
87+
{
88+
dictionary.Add(referenceIdResolver(configList[i]), configList[i]);
89+
}
90+
91+
_configs.Add(typeof(T), new ReadOnlyDictionary<int, T>(dictionary));
92+
}
93+
}
94+
}

Runtime/ConfigsProvider.cs.meta

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

Runtime/IConfigsContainer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
3+
// ReSharper disable once CheckNamespace
4+
5+
namespace GameLovers.GoogleSheetImporter
6+
{
7+
/// <summary>
8+
/// Generic container of the configs imported with a ConfigsImporter script
9+
/// The given <typeparamref name="T"/> type is the same of the config struct defined to be serialized in the scriptable object
10+
/// </summary>
11+
public interface IConfigsContainer<T> where T : struct
12+
{
13+
List<T> Configs { get; }
14+
}
15+
16+
/// <summary>
17+
/// Generic container of the unique single config imported with a ConfigsImporter script
18+
/// The given <typeparamref name="T"/> type is the same of the config struct defined to be serialized in the scriptable object
19+
/// </summary>
20+
public interface ISingleConfigContainer<T> where T : struct
21+
{
22+
T Config { get; set; }
23+
}
24+
}

Runtime/IConfigsContainer.cs.meta

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

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"name": "com.gamelovers.googlesheetimporter",
33
"displayName": "GoogleSheet Importer",
4-
"version": "0.5.3",
4+
"version": "0.6.0",
55
"unity": "2019.3",
66
"description": "This package provides a tool to import GoogleSheet data into ScriptableObject persistent config data.\n\nTo help configure the GoogleSheet Import data you need to create a configuration ScriptableObject by:\n- Right Click on the Project View > Create > ScriptableObjects > Editor > GoogleSheetImporter.\n- You can import all the GoogleSheet data without a ScriptableObject by clicking in Tools > Import Google Sheet Data",
77
"type": "tool",
88
"dependencies": {
9-
"com.gamelovers.configscontainer": "0.7.0",
10-
"com.unity.nuget.newtonsoft-json": "2.0.0-preview",
11-
"com.gamelovers.asyncawait": "0.2.0"
9+
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
1210
}
1311
}

0 commit comments

Comments
 (0)