diff --git a/SwitchMaster/Assets/KMColorblindMode.cs b/SwitchMaster/Assets/KMColorblindMode.cs new file mode 100644 index 0000000..23f7e62 --- /dev/null +++ b/SwitchMaster/Assets/KMColorblindMode.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using UnityEngine; + +public class KMColorblindMode : MonoBehaviour +{ + [SerializeField] + private bool _colorblindMode = false; + + public bool ColorblindModeActive + { + get + { + if (Application.isEditor) + return _colorblindMode; + + string key = null; + + KMBombModule bombModule = GetComponent(); + KMNeedyModule needyModule = GetComponent(); + + if (bombModule != null) + key = bombModule.ModuleType; + else if (needyModule != null) + key = needyModule.ModuleType; + else + key = Regex.Replace(gameObject.name, @"\(Clone\)$", ""); + + try + { + var settingsPath = Path.Combine(Path.Combine(Application.persistentDataPath, "Modsettings"), "ColorblindMode.json"); + + ColorblindModeSettings settings = new ColorblindModeSettings(); + if (File.Exists(settingsPath)) + settings = JsonConvert.DeserializeObject(File.ReadAllText(settingsPath)); + + bool? isEnabled = null; + if (!string.IsNullOrEmpty(key) && !settings.EnabledModules.TryGetValue(key, out isEnabled)) + settings.EnabledModules[key] = null; + + File.WriteAllText(settingsPath, JsonConvert.SerializeObject(settings, Formatting.Indented)); + return isEnabled ?? settings.Enabled; + } + catch (Exception e) + { + Debug.LogFormat(@"[Colorblind Mode] Error in ""{0}"": {1} ({2})\n{3}", key ?? "", e.Message, e.GetType().FullName, e.StackTrace); + return false; + } + } + } +} + +internal class ColorblindModeSettings +{ + public bool Enabled = false; + public Dictionary EnabledModules = new Dictionary(); +} \ No newline at end of file diff --git a/SwitchMaster/Assets/KMColorblindMode.cs.meta b/SwitchMaster/Assets/KMColorblindMode.cs.meta new file mode 100644 index 0000000..1d72def --- /dev/null +++ b/SwitchMaster/Assets/KMColorblindMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d3efc04ccca332b4eaf7ddb423000fab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SwitchMaster/Assets/The Switch/CBTextMat.mat b/SwitchMaster/Assets/The Switch/CBTextMat.mat new file mode 100644 index 0000000..f76ff11 --- /dev/null +++ b/SwitchMaster/Assets/The Switch/CBTextMat.mat @@ -0,0 +1,76 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: CBTextMat + m_Shader: {fileID: 4800000, guid: 306ffc165961a2c40806bad3bb861c43, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: b56500c841d890348ad8a3a72d2e7588, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/SwitchMaster/Assets/The Switch/CBTextMat.mat.meta b/SwitchMaster/Assets/The Switch/CBTextMat.mat.meta new file mode 100644 index 0000000..45927a6 --- /dev/null +++ b/SwitchMaster/Assets/The Switch/CBTextMat.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7f55d16a97b4a944692068ea587fe6f9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf b/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf new file mode 100644 index 0000000..e93aed3 Binary files /dev/null and b/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf differ diff --git a/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf.meta b/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf.meta new file mode 100644 index 0000000..0c6292c --- /dev/null +++ b/SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: b56500c841d890348ad8a3a72d2e7588 +TrueTypeFontImporter: + externalObjects: {} + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontName: Ostrich Sans + fontNames: + - Ostrich Sans + fallbackFontReferences: + - {fileID: 12800000, guid: 1ebe1d96973a920409b439b3a0e2bb63, type: 3} + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + useLegacyBoundsCalculation: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/SwitchMaster/Assets/The Switch/Switch.cs b/SwitchMaster/Assets/The Switch/Switch.cs index 7c00c27..b5e3c62 100644 --- a/SwitchMaster/Assets/The Switch/Switch.cs +++ b/SwitchMaster/Assets/The Switch/Switch.cs @@ -12,23 +12,29 @@ public class Switch : MonoBehaviour public KMBombInfo BombInfo; public KMBombModule BombModule; public KMAudio KMAudio; + public KMColorblindMode CBMode; public KMSelectable FlipperSelectable; public Transform FlipperPosition; public MeshRenderer TopLED; public MeshRenderer BottomLED; + public TextMesh TopCBText; + public TextMesh BottomCBText; + protected string TopName = "none"; + protected string BottomName = "none"; protected bool SOLVED = false; protected bool FlipperDown = false; protected bool FirstSuccess = false; protected bool InitMove = true; protected bool FlipperMoving = false; + protected bool CBEnabled = false; protected int BottomColor; protected int TopColor; protected int TimerSeconds1; protected int TimerSeconds2; protected int NeededNumber; - private string TwitchHelpMessage = "Use !{0} flip 5 to flip when the seconds digits of the timer contains 5"; + private string TwitchHelpMessage = "Use !{0} flip 5 to flip when the seconds digits of the timer contains 5. Use !{0} colorblind to toggle colorblind mode."; System.Collections.IEnumerator ProcessTwitchCommand(string command) { @@ -41,7 +47,7 @@ System.Collections.IEnumerator ProcessTwitchCommand(string command) { while (TimerSeconds1 != PressOn && TimerSeconds2 != PressOn) { - yield return null; + yield return "trycancel"; } yield return FlipperSelectable; yield return null; @@ -49,6 +55,21 @@ System.Collections.IEnumerator ProcessTwitchCommand(string command) yield break; } } + else if (Regex.IsMatch(LowerCommand, @"\s*colorblind|colourblind|cb\s*$")) + { + yield return null; + CBEnabled = !CBEnabled; + if (CBEnabled) + { + TopCBText.text = TopName[0].ToString(); + BottomCBText.text = BottomName[0].ToString(); + } + else + { + TopCBText.text = ""; + BottomCBText.text = ""; + } + } yield break; } @@ -95,8 +116,6 @@ protected void ModuleInit() TopColor = UnityEngine.Random.Range(1, 7); BottomColor = UnityEngine.Random.Range(1, 7); - string TopName = "none"; - string BottomName = "none"; Color Orange = new Color(1f, 0.5f, 0f); Color Purple = new Color(0.75f, 0f, 0.75f); int RuleNumber; @@ -222,11 +241,21 @@ protected void ModuleInit() if (SOLVED) { + if (CBEnabled) + { + TopCBText.text = ""; + BottomCBText.text = ""; + } BottomLED.material.color = Color.black; TopLED.material.color = Color.black; } else { + if (CBEnabled) + { + TopCBText.text = TopName[0].ToString(); + BottomCBText.text = BottomName[0].ToString(); + } DebugLog("Switch is {0}. Top LED is {1}, bottom LED is {2}", FlipperDown ? "down" : "up", TopName, BottomName); DebugLog("Rule is {0}, number needed is {1}", RuleNumber.ToString(), NeededNumber.ToString()); } @@ -235,6 +264,7 @@ protected void ModuleInit() protected void Start() { + CBEnabled = CBMode.ColorblindModeActive; int FlipInt = UnityEngine.Random.Range(0, 2); if (FlipInt == 1) { diff --git a/SwitchMaster/Assets/The Switch/The Switch.prefab b/SwitchMaster/Assets/The Switch/The Switch.prefab index f7f1c38..6ab92e4 100644 --- a/SwitchMaster/Assets/The Switch/The Switch.prefab +++ b/SwitchMaster/Assets/The Switch/The Switch.prefab @@ -120,6 +120,23 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!1 &1424354748170160 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4613063074232406} + - component: {fileID: 23029687085995278} + - component: {fileID: 102908484714182132} + m_Layer: 0 + m_Name: TopCBText + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 --- !u!1 &1494846074259474 GameObject: m_ObjectHideFlags: 0 @@ -184,6 +201,7 @@ GameObject: - component: {fileID: 114159303222499148} - component: {fileID: 114889227088249520} - component: {fileID: 114454629999367408} + - component: {fileID: 114145027412564752} m_Layer: 0 m_Name: The Switch m_TagString: Untagged @@ -191,6 +209,23 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!1 &1802202461019642 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4629966895430878} + - component: {fileID: 23438912626704454} + - component: {fileID: 102856773154126928} + m_Layer: 0 + m_Name: BottomCBText + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 --- !u!1 &1869614188672166 GameObject: m_ObjectHideFlags: 0 @@ -319,6 +354,32 @@ Transform: m_Father: {fileID: 4990965746289326} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0} +--- !u!4 &4613063074232406 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1424354748170160} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: -0.025, y: 0.015, z: 0.065} + m_LocalScale: {x: 0.00003, y: 0.00003, z: 1} + m_Children: [] + m_Father: {fileID: 4990965746289326} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!4 &4629966895430878 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1802202461019642} + m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} + m_LocalPosition: {x: -0.025, y: 0.015, z: -0.065} + m_LocalScale: {x: 0.00003, y: 0.00003, z: 1.0000005} + m_Children: [] + m_Father: {fileID: 4990965746289326} + m_RootOrder: 11 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} --- !u!4 &4737257309781920 Transform: m_ObjectHideFlags: 1 @@ -378,6 +439,8 @@ Transform: - {fileID: 4466331683818338} - {fileID: 4940621572987764} - {fileID: 4545611946892814} + - {fileID: 4613063074232406} + - {fileID: 4629966895430878} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -394,6 +457,40 @@ Transform: m_Father: {fileID: 4990965746289326} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: -90, y: -360, z: 0} +--- !u!23 &23029687085995278 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1424354748170160} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 2100000, guid: 7f55d16a97b4a944692068ea587fe6f9, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 --- !u!23 &23047865183116114 MeshRenderer: m_ObjectHideFlags: 1 @@ -496,6 +593,40 @@ MeshRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 +--- !u!23 &23438912626704454 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1802202461019642} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 2100000, guid: 7f55d16a97b4a944692068ea587fe6f9, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 --- !u!23 &23470467025201882 MeshRenderer: m_ObjectHideFlags: 1 @@ -753,6 +884,48 @@ Animator: m_WarningMessage: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 +--- !u!102 &102856773154126928 +TextMesh: + serializedVersion: 3 + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1802202461019642} + m_Text: + m_OffsetZ: 0 + m_CharacterSize: 80 + m_LineSpacing: 1 + m_Anchor: 4 + m_Alignment: 1 + m_TabSize: 4 + m_FontSize: 80 + m_FontStyle: 0 + m_RichText: 1 + m_Font: {fileID: 12800000, guid: b56500c841d890348ad8a3a72d2e7588, type: 3} + m_Color: + serializedVersion: 2 + rgba: 4278190080 +--- !u!102 &102908484714182132 +TextMesh: + serializedVersion: 3 + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1424354748170160} + m_Text: + m_OffsetZ: 0 + m_CharacterSize: 80 + m_LineSpacing: 1 + m_Anchor: 4 + m_Alignment: 1 + m_TabSize: 4 + m_FontSize: 80 + m_FontStyle: 0 + m_RichText: 1 + m_Font: {fileID: 12800000, guid: b56500c841d890348ad8a3a72d2e7588, type: 3} + m_Color: + serializedVersion: 2 + rgba: 4278190080 --- !u!114 &114126900135219626 MonoBehaviour: m_ObjectHideFlags: 1 @@ -776,6 +949,18 @@ MonoBehaviour: AllowSelectionWrapY: 0 ForceSelectionHighlight: 0 ForceInteractionHighlight: 0 +--- !u!114 &114145027412564752 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1780099383599810} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d3efc04ccca332b4eaf7ddb423000fab, type: 3} + m_Name: + m_EditorClassIdentifier: + _colorblindMode: 0 --- !u!114 &114159303222499148 MonoBehaviour: m_ObjectHideFlags: 1 @@ -863,10 +1048,13 @@ MonoBehaviour: BombInfo: {fileID: 114159303222499148} BombModule: {fileID: 114279505997974386} KMAudio: {fileID: 114889227088249520} + CBMode: {fileID: 114145027412564752} FlipperSelectable: {fileID: 114368012262432062} FlipperPosition: {fileID: 4229934886158470} TopLED: {fileID: 23181056485762454} BottomLED: {fileID: 23758146782885120} + TopCBText: {fileID: 102908484714182132} + BottomCBText: {fileID: 102856773154126928} --- !u!114 &114522352902968950 MonoBehaviour: m_ObjectHideFlags: 1