Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'v2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
modio-jackson committed Feb 15, 2021
2 parents b4b4e5a + 43efb70 commit 058bd8f
Show file tree
Hide file tree
Showing 114 changed files with 5,224 additions and 3,453 deletions.
46 changes: 13 additions & 33 deletions Editor/EditorMenuItems.cs
@@ -1,10 +1,14 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using File = System.IO.File;
using Directory = System.IO.Directory;

using UnityEngine;
using UnityEditor;

using ModIO.UI;


namespace ModIO.EditorCode
{
public static class EditorMenuItems
Expand All @@ -19,14 +23,8 @@ static EditorMenuItems()
[MenuItem("Tools/mod.io/Debugging/Clear All Cached Data", false)]
public static void ClearCache()
{
if(LocalDataStorage.DeleteDirectory(PluginSettings.CACHE_DIRECTORY))
{
Debug.Log("[mod.io] Cache Cleared.");
}
else
{
Debug.Log("[mod.io] Failed to clear cache.");
}
Directory.Delete(DataStorage.CACHE_DIRECTORY);
Debug.Log("[mod.io] Cache Cleared.");
}

[MenuItem("Tools/mod.io/Debugging/Clear All User Data", false)]
Expand All @@ -51,42 +49,24 @@ public static void ClearAllUserData()
[MenuItem("Tools/mod.io/Debugging/Clear Game Data", false)]
public static void ClearCachedGameProfile()
{
if(LocalDataStorage.DeleteFile(CacheClient.gameProfileFilePath))
{
Debug.Log("[mod.io] Cached Game Data Deleted.");
}
else
{
Debug.Log("[mod.io] Failed to delete Cached Game Data.");
}
File.Delete(CacheClient.gameProfileFilePath);
Debug.Log("[mod.io] Cached Game Data Deleted.");
}

[MenuItem("Tools/mod.io/Debugging/Clear Mod Data", false)]
public static void ClearCachedModData()
{
string modDir = IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY, "mods");
string modDir = IOUtilities.CombinePath(DataStorage.CACHE_DIRECTORY, "mods");

if(LocalDataStorage.DeleteDirectory(modDir))
{
Debug.Log("[mod.io] Cached Mod Data Deleted.");
}
else
{
Debug.Log("[mod.io] Failed to clear cached Mod Data.");
}
Directory.Delete(modDir);
Debug.Log("[mod.io] Cached Mod Data Deleted.");
}

[MenuItem("Tools/mod.io/Debugging/Delete Installed Mods", false)]
public static void RemoveAllInstalledMods()
{
if(LocalDataStorage.DeleteDirectory(PluginSettings.INSTALLATION_DIRECTORY))
{
Debug.Log("[mod.io] Mod Installation Data removed.");
}
else
{
Debug.Log("[mod.io] Failed to removed installed mods.");
}
Directory.Delete(DataStorage.INSTALLATION_DIRECTORY);
Debug.Log("[mod.io] Mod Installation Data removed.");
}

[MenuItem("Tools/mod.io/Update ALL Color Scheme Applicators", false)]
Expand Down
7 changes: 4 additions & 3 deletions Editor/VariableDirectoryDrawer.cs
Expand Up @@ -2,6 +2,7 @@

using System;
using Path = System.IO.Path;
using Directory = System.IO.Directory;

using UnityEngine;
using UnityEditor;
Expand Down Expand Up @@ -50,7 +51,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
while(!directoryIsValid && !string.IsNullOrEmpty(testDir))
{
testDir = Path.GetDirectoryName(testDir);
directoryIsValid = LocalDataStorage.GetDirectoryExists(testDir);
directoryIsValid = Directory.Exists(testDir);
}
}
catch
Expand All @@ -72,9 +73,9 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

if(GUI.Button(buttonRect, new GUIContent("...", toolTip)))
{
if(!LocalDataStorage.GetDirectoryExists(dir))
if(!Directory.Exists(dir))
{
LocalDataStorage.CreateDirectory(dir);
System.IO.Directory.CreateDirectory(dir);
}

if(dir.StartsWith(Application.dataPath))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -32,12 +32,12 @@ Alternatively, you can download an archive of the code using GitHub's download f
1. Implement support for user-generated content in your project. Maps, skins, or game modes are often a good place to start.
1. Set up your [game profile on mod.io](https://mod.io/games/add) (or our [private test environment](https://test.mod.io/games/add)) to get your game ID and API key.
1. Add the plugin to your game using the installation instructions above.
1. Drop the _ModBrowser prefab into your menu scene, or adapt the Example Scene for your purposes.
1. Drop the ModBrowser prefab into your menu scene, or adapt the Example Scene for your purposes.
1. Input your ID and API key by selecting "Plugin Settings" on the ModBrowser component inspector, or under the Tools/mod.io/Edit Settings menu item
1. In your code, make a call to `ModManager.GetInstalledModDirectories()` to get a list of mod data your player has installed (read our wiki for [detailed instructions](https://github.com/modio/modio-unity/wiki))
1. In your code, make a call to `ModManager.QueryInstalledModDirectories()` to get a list of mod data your player has installed (read our wiki for [detailed instructions](https://github.com/modio/modio-unity/wiki))
1. Setup complete! Join us [on Discord](https://discord.mod.io) if you have questions or need help.

All mods [submitted to mod.io](https://mod.io/mods/add) will be automatically fetched and managed by the plugin, and are instantly downloadable and testable.
All mods [submitted to mod.io](https://mod.io/mods/add) will be automatically fetched and managed by the plugin, and are instantly downloadable and testable.

## Usage
### Browse Mods
Expand Down
2 changes: 0 additions & 2 deletions Runtime/API Objects/GameProfile.cs
@@ -1,5 +1,3 @@
using System;

using Newtonsoft.Json;

namespace ModIO
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModComment.cs
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModEvent.cs
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModRating.cs
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
1 change: 0 additions & 1 deletion Runtime/API Objects/ModTagCategory.cs
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
81 changes: 81 additions & 0 deletions Runtime/API Objects/TermsOfUseInfo.cs
@@ -0,0 +1,81 @@
using System.Runtime.Serialization;
using System.Collections.Generic;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
/// <summary>Terms of Use Object returned by the API.</summary>
[System.Serializable]
public class TermsOfUseInfo
{
// ---------[ NESTED DATA-TYPES ]---------
/// <summary>Link data for further information.</summary>
[System.Serializable]
public struct LinkData
{
/// <summary>Text to display on a button for the link.</summary>
[JsonProperty("text")]
public string buttonText;

/// <summary>URL to the full information.</summary>
[JsonProperty("url")]
public string URL;

/// <summary>Whether our terms require the URL to be made available to a user.</summary>
[JsonProperty("required")]
public bool required;
}

// ---------[ FIELDS ]---------
/// <summary>Terms of use the user needs to agree to in order to authenticate.</summary>
[JsonProperty("plaintext")]
public string terms;

/// <summary>Terms of use the user needs to agree to in order to authenticate. (HTML)</summary>
[JsonProperty("html")]
public string terms_HTML;

/// <summary>UI Text for the "agree" button.</summary>
[JsonProperty("buttons.agree.text")]
public string buttonText_agree;

/// <summary>UI Text for the "disagree" button.</summary>
[JsonProperty("buttons.disagree.text")]
public string buttonText_disagree;

/// <summary>Additional information URLs to be provided to the user.</summary>
[JsonProperty("links")]
public Dictionary<string, LinkData> links;

// ---------[ API DESERIALIZATION ]---------
private const string APIOBJECT_LINKKEY_WEBSITE = "website";
private const string APIOBJECT_LINKKEY_TERMS = "terms";
private const string APIOBJECT_LINKKEY_PRIVACY = "privacy";
private const string APIOBJECT_LINKKEY_ACCOUNT = "manage";

private struct ButtonInfo
{
public string text;
}

[JsonExtensionData]
private IDictionary<string, JToken> m_extensionData;

[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
if(this.m_extensionData != null
&& this.m_extensionData.Count > 0)
{
JToken infoToken;
if(this.m_extensionData.TryGetValue("buttons", out infoToken))
{
this.buttonText_agree = (string)infoToken["agree"]["text"];
this.buttonText_disagree = (string)infoToken["disagree"]["text"];
}
}
}
}
}
13 changes: 13 additions & 0 deletions Runtime/API Objects/TermsOfUseInfo.cs.meta

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

1 change: 0 additions & 1 deletion Runtime/API Objects/UserEvent.cs
@@ -1,7 +1,6 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ModIO
{
Expand Down
4 changes: 4 additions & 0 deletions Runtime/API Objects/UserProfile.cs
Expand Up @@ -44,5 +44,9 @@ public class UserProfile
/// <summary>URL to the user's mod.io profile.</summary>
[JsonProperty("profile_url")]
public string profileURL;

/// <summary>Display name of the user for the provided platform.</summary>
[JsonProperty("username_platform")]
public string usernamePlatform;
}
}
16 changes: 15 additions & 1 deletion Runtime/API Objects/WebRequestError.cs
Expand Up @@ -10,6 +10,9 @@ namespace ModIO
{
public class WebRequestError
{
// ---------[ CONSTANTS ]---------
public const int MODIOERROR_USERNOTAGREED = 11051;

// ---------[ NESTED CLASSES ]---------
[System.Serializable]
private class APIWrapper
Expand Down Expand Up @@ -50,6 +53,9 @@ public class APIError
/// <summary>Indicates whether the provided authentication data was rejected.</summary>
public bool isAuthenticationInvalid;

/// <summary>Indicates that the user attempts to authenticate has not yet accepted the mod.io terms.</summary>
public bool isUserTermsAgreementRequired;

/// <summary>Indicates whether the mod.io servers a unreachable (for whatever reason).</summary>
public bool isServerUnreachable;

Expand Down Expand Up @@ -90,6 +96,7 @@ public static WebRequestError GenerateLocal(string errorMessage)
displayMessage = errorMessage,

isAuthenticationInvalid = false,
isUserTermsAgreementRequired = false,
isServerUnreachable = false,
isRequestUnresolvable = false,
limitedUntilTimeStamp = -1,
Expand Down Expand Up @@ -170,6 +177,7 @@ private void ApplyAPIErrorValues()
private void ApplyInterpretedValues()
{
this.isAuthenticationInvalid = false;
this.isUserTermsAgreementRequired = false;
this.isServerUnreachable = false;
this.isRequestUnresolvable = false;
this.limitedUntilTimeStamp = -1;
Expand Down Expand Up @@ -217,7 +225,13 @@ private void ApplyInterpretedValues()
// Forbidden
case 403:
{
if(string.IsNullOrEmpty(this.errorMessage))
if(this.errorReference == WebRequestError.MODIOERROR_USERNOTAGREED)
{
this.isUserTermsAgreementRequired = true;

this.displayMessage = ("You have not yet agreed to the mod.io terms of service.");
}
else if(string.IsNullOrEmpty(this.errorMessage))
{
this.displayMessage = ("Your account does not have the required permissions.");
}
Expand Down

0 comments on commit 058bd8f

Please sign in to comment.