Skip to content

Commit

Permalink
Added the ability to load custom scripts generated by the script tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbrown30 committed Jun 25, 2020
1 parent 77aeb0e commit 109bb74
Show file tree
Hide file tree
Showing 177 changed files with 21,451 additions and 3,596 deletions.
15 changes: 15 additions & 0 deletions Assembly-CSharp-Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@
<Reference Include="SyntaxTree.VisualStudio.Unity.Bridge">
<HintPath>C:/Program Files (x86)/Microsoft Visual Studio Tools for Unity/15.0/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll</HintPath>
</Reference>
<Reference Include="DotNetZip">
<HintPath>C:/Projects/Grimoire/Assets/NuGet/Editor/DotNetZip.dll</HintPath>
</Reference>
<Reference Include="NugetForUnity">
<HintPath>C:/Projects/Grimoire/Assets/NuGet/Editor/NugetForUnity.dll</HintPath>
</Reference>
<Reference Include="Ookii.Dialogs">
<HintPath>C:/Projects/Grimoire/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms">
<HintPath>C:/Projects/Grimoire/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Advertisements">
<HintPath>C:/Projects/Grimoire/Library/PackageCache/[email protected]/Editor/UnityEditor.Advertisements.dll</HintPath>
</Reference>
Expand All @@ -286,6 +298,9 @@
<Reference Include="UnityEditor.Purchasing">
<HintPath>C:/Projects/Grimoire/Library/PackageCache/[email protected]/Editor/UnityEditor.Purchasing.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>C:/Projects/Grimoire/Assets/Packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>C:/Projects/Grimoire/Library/PackageCache/[email protected]/net35/unity-custom/nunit.framework.dll</HintPath>
</Reference>
Expand Down
19 changes: 18 additions & 1 deletion Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_2019_3_15;UNITY_2019_3;UNITY_2019;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2019_1_OR_NEWER;UNITY_2019_2_OR_NEWER;UNITY_2019_3_OR_NEWER;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;UNITY_ANALYTICS;ENABLE_AR;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_EVENT_QUEUE;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_TEXTURE_STREAMING;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_UNITYWEBREQUEST;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;ENABLE_MANAGED_AUDIO_JOBS;INCLUDE_DYNAMIC_GI;ENABLE_MONO_BDWGC;ENABLE_SCRIPTING_GC_WBARRIERS;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_VIDEO;PLATFORM_STANDALONE;PLATFORM_STANDALONE_WIN;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_STANDARD_2_0;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;ENABLE_VSTU;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_DIRECTOR;ENABLE_LOCALIZATION;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_TILEMAP;ENABLE_TIMELINE;ENABLE_LEGACY_INPUT_MANAGER;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_2019_3_15;UNITY_2019_3;UNITY_2019;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2019_1_OR_NEWER;UNITY_2019_2_OR_NEWER;UNITY_2019_3_OR_NEWER;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;UNITY_ANALYTICS;ENABLE_AR;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_EVENT_QUEUE;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_TEXTURE_STREAMING;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_UNITYWEBREQUEST;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;ENABLE_MANAGED_AUDIO_JOBS;INCLUDE_DYNAMIC_GI;ENABLE_MONO_BDWGC;ENABLE_SCRIPTING_GC_WBARRIERS;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_VIDEO;PLATFORM_STANDALONE;PLATFORM_STANDALONE_WIN;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;ENABLE_VSTU;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_DIRECTOR;ENABLE_LOCALIZATION;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_TILEMAP;ENABLE_TIMELINE;ENABLE_LEGACY_INPUT_MANAGER;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
Expand Down Expand Up @@ -63,6 +63,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\AlignmentToken.cs" />
<Compile Include="Assets\CustomScriptReader.cs" />
<Compile Include="Assets\GrimoireManager.cs" />
<Compile Include="Assets\GrimoireShuffle.cs" />
<Compile Include="Assets\GrimoireToken.cs" />
Expand Down Expand Up @@ -92,6 +93,12 @@
<Compile Include="Assets\RoleData.cs" />
<Compile Include="Assets\RoleEntry.cs" />
<Compile Include="Assets\RoleSelectionManager.cs" />
<Compile Include="Assets\StandaloneFileBrowser\IStandaloneFileBrowser.cs" />
<Compile Include="Assets\StandaloneFileBrowser\StandaloneFileBrowser.cs" />
<Compile Include="Assets\StandaloneFileBrowser\StandaloneFileBrowserEditor.cs" />
<Compile Include="Assets\StandaloneFileBrowser\StandaloneFileBrowserLinux.cs" />
<Compile Include="Assets\StandaloneFileBrowser\StandaloneFileBrowserMac.cs" />
<Compile Include="Assets\StandaloneFileBrowser\StandaloneFileBrowserWindows.cs" />
<Compile Include="Assets\StepManager.cs" />
<Compile Include="Assets\SwapEntry.cs" />
<Compile Include="Assets\SwapRolePanel.cs" />
Expand All @@ -108,6 +115,7 @@
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMPro_Properties.cginc" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMPro_Surface.cginc" />
<None Include="Assets\TextMesh Pro\Resources\LineBreaking Following Characters.txt" />
<None Include="Assets\Packages\Newtonsoft.Json.12.0.3\lib\netstandard2.0\Newtonsoft.Json.xml" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_SDF-Mobile Masking.shader" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_SDF Overlay.shader" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_Bitmap-Mobile.shader" />
Expand Down Expand Up @@ -297,6 +305,12 @@
<Reference Include="UnityEditor">
<HintPath>C:/Program Files/Unity/Hub/Editor/2019.3.15f1/Editor/Data/Managed/UnityEditor.dll</HintPath>
</Reference>
<Reference Include="Ookii.Dialogs">
<HintPath>C:/Projects/Grimoire/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms">
<HintPath>C:/Projects/Grimoire/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll</HintPath>
</Reference>
<Reference Include="Unity.Analytics.Editor">
<HintPath>C:/Projects/Grimoire/Library/PackageCache/[email protected]/Unity.Analytics.Editor.dll</HintPath>
</Reference>
Expand All @@ -306,6 +320,9 @@
<Reference Include="Unity.Analytics.StandardEvents">
<HintPath>C:/Projects/Grimoire/Library/PackageCache/[email protected]/AnalyticsStandardEvents/Unity.Analytics.StandardEvents.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>C:/Projects/Grimoire/Assets/Packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="mscorlib">
<HintPath>C:/Program Files/Unity/Hub/Editor/2019.3.15f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
</Reference>
Expand Down
64 changes: 64 additions & 0 deletions Assets/CustomScriptReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Newtonsoft.Json;
using SFB;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class CustomScriptReader : MonoBehaviour
{
public RoleSelectionManager RoleSelectionManager;

public void OpenCustomScript()
{
var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "json", false);
if (paths.Length > 0)
{
StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
}
}

private IEnumerator OutputRoutine(string url)
{
var loader = new UnityWebRequest(url);
loader.downloadHandler = new DownloadHandlerBuffer();
yield return loader.SendWebRequest();

ParseCustomScript(loader.downloadHandler.text);
}

[System.Serializable]
class IdWrapper
{
public string id { get; set; }
}

void ParseCustomScript(string json)
{
RoleSelectionManager.CustomScriptData.Clear();

List<string> missingIds = new List<string>();
var idList = JsonConvert.DeserializeObject<List<IdWrapper>>(json);
foreach (var id in idList)
{
RoleData roleData = Array.Find(RoleSelectionManager.RoleDataList, x => x.ScriptToolId == id.id);
if(roleData == null)
{
missingIds.Add(id.id);
continue;
}

RoleSelectionManager.CustomScriptData.Add(roleData);
}

RoleSelectionManager.OnCustomScriptLoaded();

if (missingIds.Count > 0)
{
string errorMessage = "Failed to parse the following roles from the .json file:\n";
errorMessage += string.Join(", ", missingIds);
ModalManager.Instance().MessageBox(errorMessage, null, null, null, null, "Ok");
}
}
}
11 changes: 11 additions & 0 deletions Assets/CustomScriptReader.cs.meta

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

4 changes: 2 additions & 2 deletions Assets/GrimoireManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void UpdateRoleCounts()
}
}

RoleCountText.text = string.Format("T: {0} | O: {1} | M: {2} | D: {3}", townsfolk, outsiders, minions, demons);
RoleCountText.text = string.Format("<color=#009BFF>T: {0}</color> | <color=#009BFF>O: {1}</color> | <color=\"red\">M: {2}</color> | <color=\"red\">D: {3}</color>", townsfolk, outsiders, minions, demons);
}

public int GetIndexFromPosition(Vector2 position)
Expand Down Expand Up @@ -357,7 +357,7 @@ public void OnPointerClick(PointerEventData eventData)
GrimoireContextMenu.transform.localPosition = Vector3.zero;

GrimoireContextMenu.AddMenuItem("Reset Grimoire", OnClickResetGrimoire);
GrimoireContextMenu.AddMenuItem("Reset Helper Tokens", OnClickResetHelperTokens);
GrimoireContextMenu.AddMenuItem("Reset helper tokens", OnClickResetHelperTokens);
GrimoireContextMenu.AddMenuItem("Randomize player positions", OnClickRandomize);

string namesToggleText = PlayerNamesVisible ? "Hide player names" : "Show player names";
Expand Down
6 changes: 2 additions & 4 deletions Assets/GrimoireToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ public void SetHelperTokenScale(float scaleNormalized)
{
token.transform.localScale = newScale;
}
if(AlignmentToken)
AlignmentToken.transform.localScale = newScale;
}

public void OnBeginDrag(PointerEventData eventData)
Expand Down Expand Up @@ -287,8 +285,8 @@ public void OnPointerClick(PointerEventData eventData)
TokenContextMenu.transform.localScale = Vector3.one;
TokenContextMenu.transform.localPosition = Vector3.zero;

TokenContextMenu.AddMenuItem("Change Role", ChangeRole);
TokenContextMenu.AddMenuItem("Swap Alignment", SwapAlignment);
TokenContextMenu.AddMenuItem("Change role", ChangeRole);
TokenContextMenu.AddMenuItem("Swap alignment", SwapAlignment);
TokenContextMenu.FinaliseMenu();

ContextMenu.HideAllMenus();//hide other menus
Expand Down
4 changes: 2 additions & 2 deletions Assets/K2 Games/Context Menus/Prefabs/Context Menu.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 209.7, y: 108.20001}
m_SizeDelta: {x: 375, y: 108.20001}
m_Pivot: {x: 0, y: 0}
--- !u!114 &11433316
MonoBehaviour:
Expand All @@ -266,7 +266,7 @@ MonoBehaviour:
transition: {fileID: 11436726}
menuLayout: {fileID: 11404184}
selector: {fileID: 175464}
menuItemPrefab: {fileID: 11408358, guid: a5e07b48e5be12341a7ec866614e99f1, type: 3}
menuItemPrefab: {fileID: 11408358, guid: 8ff6056155f694c44ada85827b415070, type: 3}
parentMenu: {fileID: 0}
menuItems: []
--- !u!114 &11436726
Expand Down
Loading

0 comments on commit 109bb74

Please sign in to comment.