diff --git a/.gitignore b/.gitignore index b2b9d62..71aaab1 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,8 @@ sysinfo.txt Builds Assets/Marbles/MarbleSkins Assets/Marbles/MarbleData/*.prefab* +Assets/Marbles/MarbleData.meta +Assets/Marbles/MarbleSkins.meta # Crashlytics generated file crashlytics-build.properties diff --git a/Assets/Marbles/MarbleData.meta b/Assets/Marbles/MarbleData.meta deleted file mode 100644 index aa6e07d..0000000 --- a/Assets/Marbles/MarbleData.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3675c5d2b96ffed47b96b49d17c4f7aa -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Marbles/MarbleSkins.meta b/Assets/Marbles/MarbleSkins.meta deleted file mode 100644 index ad2b3b9..0000000 --- a/Assets/Marbles/MarbleSkins.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: afcddd465659e4445b696c17a9fc7e77 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Arrrgs.cs b/Assets/Scripts/Arrrgs.cs deleted file mode 100644 index 505aca1..0000000 --- a/Assets/Scripts/Arrrgs.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Arrrgs -{ - //These are the chat arguments that we care about - //Stores data for both whispers and chat messeges - - public string message = ""; - public string userID = ""; - public string displayName = ""; - public string commandText = ""; - public string commandArgs = ""; - public List multiCommand = null; //new List(); - -} diff --git a/Assets/Scripts/CommandEventArgs.cs b/Assets/Scripts/CommandEventArgs.cs new file mode 100644 index 0000000..5a5ebee --- /dev/null +++ b/Assets/Scripts/CommandEventArgs.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CommandEventArgs +{ + //These are the chat arguments that we care about + //Stores data for both whispers and chat messeges + + public string Message = ""; + public string UserID = ""; + public string DisplayName = ""; + public string CommandText = ""; + public string CommandArgs = ""; + public List MultiCommand = null; //new List(); + +} diff --git a/Assets/Scripts/MarbleAssigner.cs.meta b/Assets/Scripts/CommandEventArgs.cs.meta similarity index 83% rename from Assets/Scripts/MarbleAssigner.cs.meta rename to Assets/Scripts/CommandEventArgs.cs.meta index 7c3b48f..13b2137 100644 --- a/Assets/Scripts/MarbleAssigner.cs.meta +++ b/Assets/Scripts/CommandEventArgs.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f5a0e1c13febfa7499d7e8e31645cba6 +guid: bcd52ee8fb9eb954ab6902f5838dc4f1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/CommandQueue.cs b/Assets/Scripts/CommandQueue.cs index ab4be4f..0ed8797 100644 --- a/Assets/Scripts/CommandQueue.cs +++ b/Assets/Scripts/CommandQueue.cs @@ -7,24 +7,24 @@ public class CommandQueue : MonoBehaviour //Queue's store and handle messege sending so the BOT does not break Twitch Dev Guidlines //100 chat messeges per min //200 whispers per min - Queue commandQueueChat = new Queue(); - Queue commandQueueWhisper = new Queue(); - [SerializeField] Commands commands; + Queue CommandQueueChat = new Queue(); + Queue CommandQueueWhisper = new Queue(); + [SerializeField] Commands Commands; private void Start() { //commands = FindObjectOfType(); StartCoroutine(RemoveFromChatQueue()); } - public void AddToChatQueue(Arrrgs arg) + public void AddToChatQueue(CommandEventArgs arg) { - commandQueueChat.Enqueue(arg); + CommandQueueChat.Enqueue(arg); Debug.Log("Command in queue"); - Debug.Log("There are " + commandQueueChat.Count + " in the queue"); + Debug.Log("There are " + CommandQueueChat.Count + " in the queue"); } - private void AddToWhisperQueue(Arrrgs arg) + private void AddToWhisperQueue(CommandEventArgs arg) { - commandQueueWhisper.Enqueue(arg); + CommandQueueWhisper.Enqueue(arg); } //This Dequeue's from the commandChatQueue @@ -32,18 +32,18 @@ IEnumerator RemoveFromChatQueue() { while (true) { - if (commandQueueChat.Count != 0) + if (CommandQueueChat.Count != 0) { - var e = commandQueueChat.Dequeue(); - string firstCommand = e.commandText; //Command.CommandText.ToLower(); - if (firstCommand == "buy") { commands.Buy(e); } - else if (firstCommand == "join") { commands.Join(e); } - else if (firstCommand == "equip") { commands.Equip(e); } - else if (firstCommand == "money") { commands.money(e); } - else if (firstCommand == "inuse") { commands.InUse(e); } - else if (firstCommand == "help") { commands.Help(e); } - else if (firstCommand == "skins") { commands.Skins(e); } - else if (firstCommand == "give") { commands.Give(e); } + var e = CommandQueueChat.Dequeue(); + string firstCommand = e.CommandText; //Command.CommandText.ToLower(); + if (firstCommand == "buy") { Commands.Buy(e); } + else if (firstCommand == "join") { Commands.Join(e); } + else if (firstCommand == "equip") { Commands.Equip(e); } + else if (firstCommand == "money") { Commands.CheckMoney(e); } + else if (firstCommand == "inuse") { Commands.InUse(e); } + else if (firstCommand == "help") { Commands.Help(e); } + else if (firstCommand == "skins") { Commands.Skins(e); } + else if (firstCommand == "give") { Commands.Give(e); } //else if (firstCommand == "stopwhispers") { commands.StopWhispers(e); } else { Debug.LogWarning("COMMAND NOT FOUND"); } @@ -56,28 +56,28 @@ IEnumerator RemoveFromChatQueue() } } - + //This Seperates the different commands into buckets - public void FirstCommandBuckets(Arrrgs e) + public void FirstCommandBuckets(CommandEventArgs e) { - string firstCommand = e.commandText; //Command.CommandText.ToLower(); + string firstCommand = e.CommandText; //Command.CommandText.ToLower(); //These commands will provide player confirmation/Response in CHAT - if (firstCommand == "buy") { AddToChatQueue(e); } - else if (firstCommand == "join") { AddToChatQueue(e); } - else if (firstCommand == "equip") { AddToChatQueue(e); } + if (firstCommand == "buy") { AddToChatQueue(e); } + else if (firstCommand == "join") { AddToChatQueue(e); } + else if (firstCommand == "equip") { AddToChatQueue(e); } else if (firstCommand == "money") { AddToChatQueue(e); } else if (firstCommand == "inuse") { AddToChatQueue(e); } else if (firstCommand == "skins") { AddToChatQueue(e); } else if (firstCommand == "give") { AddToChatQueue(e); } //These commands will provide player with visial confirmation in overlay - else if (firstCommand == "play") { commands.Play(e); } - else if (firstCommand == "rotate") { commands.Rotate(e); } //TEMPORARY CHAT COMMAND TO ROTATE SHOP + else if (firstCommand == "play") { Commands.Play(e); } + else if (firstCommand == "rotate") { Commands.Rotate(e); } //TEMPORARY CHAT COMMAND TO ROTATE SHOP //These commands will provide player with whisper confirmation else if (firstCommand == "help") { AddToChatQueue(e); } - else if (firstCommand == "vfx") { } - else if (firstCommand == "sfx") { } + else if (firstCommand == "vfx") { } + else if (firstCommand == "sfx") { } else { return; } } diff --git a/Assets/Scripts/Commands.cs b/Assets/Scripts/Commands.cs index 6837c77..88f82cd 100644 --- a/Assets/Scripts/Commands.cs +++ b/Assets/Scripts/Commands.cs @@ -1,10 +1,10 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using UnityEngine; +using TwitchLib.Client.Events; using TwitchLib.Client.Models; using TwitchLib.Unity; -using TwitchLib.Client.Events; -using System; +using UnityEngine; public class Commands : MonoBehaviour { @@ -18,35 +18,35 @@ public class Commands : MonoBehaviour //PUNCHYPENGUIN HAS SIGNED //CODING CUBER HAS SIGNED //MOTTZYMAKES - TwitchClient twitchClient; - Client chatClient; - JoinedChannel chatJoinedChannel; - JoinedChannel botJoinedChannel; - [SerializeField] GameData gameDataScript; - [SerializeField] MarbleList marbleList; - [SerializeField] GameController gameController; - [SerializeField] JumpManager jumpManager; - [SerializeField] Shop shop; - const string secretMsg = " is hacking"; - const string help = "!join-join the game | !play-play the game when it is GAMETIME | play to earn money" + + TwitchClient TwitchClient; + Client ChatClient; + JoinedChannel ChatJoinedChannel; + JoinedChannel BotJoinedChannel; + [SerializeField] GameData GameDataScript; + [SerializeField] MarbleList MarbleList; + [SerializeField] GameController GameController; + [SerializeField] JumpManager JumpManager; + [SerializeField] Shop Shop; + const string SecretMsg = " is hacking"; + const string HelpMessage = "!join-join the game | !play-play the game when it is GAMETIME | play to earn money" + " | save money to buy and equip new marbles"; - const string playerAlreadyExists = " your user entry already exists, no need to join"; - const string noPlayerEntryExists = ", Please type '!join' to play"; - const string playerEntryAdded = " you have joined the game"; - const string noMarbleWithNameExists = ", there is no marble with that name. Please type a valid marble name."; - const string unlockedMarble1 = " has unlocked the "; - const string unlockedMarble2 = " marble. Use '!equip "; - const string unlockedMarble3 = "' to use your new marble."; - const string unlockedMarble4 = " Current Balance: "; - const string notEnoughMoney = ", you do not have enough money to unlock "; - const string skinAlreadyUnlocked1 = ", you already have the "; - const string skinAlreadyUnlocked2 = " marble unlocked."; - const string dontOwnThatSkin = ", you dont own that skin. Type !skins to see the skins you own."; - const string notSubscribed1 = ", you can not use this command unless you give Simpagamebot permission to whisper your Twitch"; - const string notSubscribed2 = "Please type !acceptwhispers you can type !stopwhispers at any time to revoke whisper permissions."; - const string marbleNotInShop = " marble is not in shop"; - const string cantGiveMoneyToPlayer1 = "Can not give money to "; - const string cantGiveMoneyToPlayer2 = " because they are not entered in the game."; + const string PlayerAlreadyExists = " your user entry already exists, no need to join"; + const string NoPlayerEntryExists = ", Please type '!join' to play"; + const string PlayerEntryAdded = " you have joined the game"; + const string NoMarbleWithNameExists = ", there is no marble with that name. Please type a valid marble name."; + const string UnlockedMarble1 = " has unlocked the "; + const string UnlockedMarble2 = " marble. Use '!equip "; + const string UnlockedMarble3 = "' to use your new marble."; + const string UnlockedMarble4 = " Current Balance: "; + const string NotEnoughMoney = ", you do not have enough money to unlock "; + const string SkinAlreadyUnlocked1 = ", you already have the "; + const string SkinAlreadyUnlocked2 = " marble unlocked."; + const string DontOwnThatSkin = ", you dont own that skin. Type !skins to see the skins you own."; + const string NotSubscribed1 = ", you can not use this command unless you give Simpagamebot permission to whisper your Twitch"; + const string NotSubscribed2 = "Please type !acceptwhispers you can type !stopwhispers at any time to revoke whisper permissions."; + const string MarbleNotInShop = " marble is not in shop"; + const string CantGiveMoneyToPlayer1 = "Can not give money to "; + const string CantGiveMoneyToPlayer2 = " because they are not entered in the game."; private void Start() { @@ -55,16 +55,16 @@ private void Start() } public void Setup() { - twitchClient = FindObjectOfType(); - chatClient = twitchClient.client; - chatJoinedChannel = twitchClient.joinedChannel; - botJoinedChannel = twitchClient.botChannel; + TwitchClient = FindObjectOfType(); + ChatClient = TwitchClient.Client; + ChatJoinedChannel = TwitchClient.JoinedChannel; + BotJoinedChannel = TwitchClient.BotChannel; } //Help - provids a list of commands - public void Help(Arrrgs e) + public void Help(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); //chatClient.SendMessage(chatJoinedChannel, help); @@ -76,15 +76,15 @@ public void Help(Arrrgs e) } } - private void AttemptToHelp(Arrrgs e) + private void AttemptToHelp(CommandEventArgs e) { - chatClient.SendMessage(chatJoinedChannel, help); + ChatClient.SendMessage(ChatJoinedChannel, HelpMessage); } //Join - check if player data exists - if not create empty player data entry - public void Join (Arrrgs e) + public void Join(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToJoin(e); @@ -94,24 +94,24 @@ public void Join (Arrrgs e) AttemptToJoin(e); } } - private void AttemptToJoin(Arrrgs e) + private void AttemptToJoin(CommandEventArgs e) { - if (gameDataScript.CheckIfPlayerExists(e.userID)) + if (GameDataScript.CheckIfPlayerExists(e.UserID)) { - chatClient.SendMessage(chatJoinedChannel, e.displayName + playerAlreadyExists); + ChatClient.SendMessage(ChatJoinedChannel, e.DisplayName + PlayerAlreadyExists); } else { - gameDataScript.CreateNewPlayerEntry(e); - chatClient.SendMessage(chatJoinedChannel, e.displayName + playerEntryAdded); + GameDataScript.CreateNewPlayerEntry(e); + ChatClient.SendMessage(ChatJoinedChannel, e.DisplayName + PlayerEntryAdded); } } //Money - checks if player data exists - if so returns how much money they have in chat - public void money(Arrrgs e) + public void CheckMoney(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToCheckMoney(e); @@ -121,26 +121,26 @@ public void money(Arrrgs e) AttemptToCheckMoney(e); } } - private void AttemptToCheckMoney(Arrrgs e) + private void AttemptToCheckMoney(CommandEventArgs e) { - string playerID = e.userID; - string userName = e.displayName; + string playerID = e.UserID; + string userName = e.DisplayName; - if (gameDataScript.CheckIfPlayerExists(playerID)) + if (GameDataScript.CheckIfPlayerExists(playerID)) { - chatClient.SendMessage(chatJoinedChannel, userName + " money: " + gameDataScript.CheckPlayerMoney(playerID)); + ChatClient.SendMessage(ChatJoinedChannel, userName + " money: " + GameDataScript.CheckPlayerMoney(playerID)); } else { - chatClient.SendMessage(chatJoinedChannel, userName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, userName + NoPlayerEntryExists); } } //Buy - checks if player data exists - if so checks if has enough money - if so then unlock skin - public void Buy(Arrrgs e) + public void Buy(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToBuy(e); @@ -150,68 +150,67 @@ public void Buy(Arrrgs e) AttemptToBuy(e); } } - public void AttemptToBuy(Arrrgs e) + public void AttemptToBuy(CommandEventArgs e) { - string commonName = ""; - string playerID = e.userID; //Command.ChatMessage.UserId; - string playerUserName = e.displayName; //Command.ChatMessage.Username; - if (gameDataScript.CheckIfPlayerExists(playerID)) + string playerID = e.UserID; //Command.ChatMessage.UserId; + string playerUserName = e.DisplayName; //Command.ChatMessage.Username; + if (GameDataScript.CheckIfPlayerExists(playerID)) { - commonName = e.commandArgs; + string commonName = e.CommandArgs; /* for (int index = 0; index < e.Command.ArgumentsAsList.Count; index++) { commonName += e.Command.ArgumentsAsList[index].ToLower(); }*/ Debug.Log(commonName); - if (marbleList.DoesMarbleCommonNameExist(commonName)) + if (MarbleList.DoesMarbleCommonNameExist(commonName)) { - if (shop.MarbleNamesInShop(commonName)) + if (Shop.MarbleNamesInShop(commonName)) { - int playerMoney = gameDataScript.CheckPlayerMoney(playerID); - int marbleCost = marbleList.GetMarbleCostFromCommonName(commonName); - int marbleCode = marbleList.GetMarbleCodeFromCommonName(commonName); - if (gameDataScript.IsSkinUnlocked(playerID, marbleCode)) + int playerMoney = GameDataScript.CheckPlayerMoney(playerID); + int marbleCost = MarbleList.GetMarbleCostFromCommonName(commonName); + int marbleCode = MarbleList.GetMarbleCodeFromCommonName(commonName); + if (GameDataScript.IsSkinUnlocked(playerID, marbleCode)) { - chatClient.SendMessage(chatJoinedChannel, playerUserName + skinAlreadyUnlocked1 + commonName + skinAlreadyUnlocked2); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + SkinAlreadyUnlocked1 + commonName + SkinAlreadyUnlocked2); } else { if (playerMoney >= marbleCost) { - gameDataScript.SubtractMoneyFromPlayerID(marbleCost, playerID); - gameDataScript.UnlockSkinForPlayer(playerID, marbleCode); - int currentMoney = gameDataScript.CheckPlayerMoney(playerID); - chatClient.SendMessage(chatJoinedChannel, playerUserName + unlockedMarble1 + - commonName + unlockedMarble2 + commonName + unlockedMarble3 + unlockedMarble4 + currentMoney); + GameDataScript.SubtractMoneyFromPlayerID(marbleCost, playerID); + GameDataScript.UnlockSkinForPlayer(playerID, marbleCode); + int currentMoney = GameDataScript.CheckPlayerMoney(playerID); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + UnlockedMarble1 + + commonName + UnlockedMarble2 + commonName + UnlockedMarble3 + UnlockedMarble4 + currentMoney); } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + notEnoughMoney + commonName); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NotEnoughMoney + commonName); } } } else { - chatClient.SendMessage(chatJoinedChannel, commonName + marbleNotInShop); + ChatClient.SendMessage(ChatJoinedChannel, commonName + MarbleNotInShop); } } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + noMarbleWithNameExists); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NoMarbleWithNameExists); } } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NoPlayerEntryExists); } } //Equip - checks if player data exists - checks if they own that skin - equips the skin - public void Equip(Arrrgs e) + public void Equip(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToEquip(e); @@ -221,50 +220,50 @@ public void Equip(Arrrgs e) AttemptToEquip(e); } } - private void AttemptToEquip(Arrrgs e) + private void AttemptToEquip(CommandEventArgs e) { string commonName = ""; - string playerID = e.userID; - string playerUserName = e.displayName; - commonName = e.commandArgs; + string playerID = e.UserID; + string playerUserName = e.DisplayName; + commonName = e.CommandArgs; /* for (int index = 0; index < e.Command.ArgumentsAsList.Count; index++) { commonName += e.Command.ArgumentsAsList[index].ToLower(); }*/ - if (gameDataScript.CheckIfPlayerExists(playerID)) + if (GameDataScript.CheckIfPlayerExists(playerID)) { - if (marbleList.DoesMarbleCommonNameExist(commonName)) + if (MarbleList.DoesMarbleCommonNameExist(commonName)) { - int marbleCode = marbleList.GetMarbleCodeFromCommonName(commonName); - if (gameDataScript.IsSkinUnlocked(playerID, marbleCode)) + int marbleCode = MarbleList.GetMarbleCodeFromCommonName(commonName); + if (GameDataScript.IsSkinUnlocked(playerID, marbleCode)) { - gameDataScript.SetPlayerEquipSkin(playerID, marbleCode); - chatClient.SendMessage(chatJoinedChannel, playerUserName + ", you now have the " + commonName +" skin in use."); - Debug.Log(playerUserName+" equipt "+commonName ); + GameDataScript.SetPlayerEquipSkin(playerID, marbleCode); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + ", you now have the " + commonName + " skin in use."); + Debug.Log(playerUserName + " equipt " + commonName); } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + dontOwnThatSkin); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + DontOwnThatSkin); } } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + noMarbleWithNameExists); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NoMarbleWithNameExists); } } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NoPlayerEntryExists); } } //Equipted - checks if player data exists - checks what skin they have equipped - tells them what skin that is - public void InUse(Arrrgs e) + public void InUse(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToInUse(e); @@ -274,26 +273,26 @@ public void InUse(Arrrgs e) AttemptToInUse(e); } } - private void AttemptToInUse(Arrrgs e) + private void AttemptToInUse(CommandEventArgs e) { - string playerID = e.userID; - string playerUserName = e.displayName; + string playerID = e.UserID; + string playerUserName = e.DisplayName; - if (gameDataScript.CheckIfPlayerExists(playerID)) + if (GameDataScript.CheckIfPlayerExists(playerID)) { - int marbleCode = gameDataScript.GetPlayerEquipSkin(playerID); - string commonName = marbleList.GetCommonNameFromMarbleCode(marbleCode); - chatClient.SendMessage(chatJoinedChannel, playerUserName + " is using the " + commonName + " skin!"); + int marbleCode = GameDataScript.GetPlayerEquipSkin(playerID); + string commonName = MarbleList.GetCommonNameFromMarbleCode(marbleCode); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + " is using the " + commonName + " skin!"); } else { - chatClient.SendMessage(chatJoinedChannel, playerUserName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, playerUserName + NoPlayerEntryExists); } } - public void Play(Arrrgs e) + public void Play(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToPlay(e); @@ -304,24 +303,24 @@ public void Play(Arrrgs e) } } - private void AttemptToPlay(Arrrgs e) + private void AttemptToPlay(CommandEventArgs e) { - string userID = e.userID; - string displayName = e.displayName; + string userID = e.UserID; + string displayName = e.DisplayName; - if (gameDataScript.CheckIfPlayerExists(userID)) + if (GameDataScript.CheckIfPlayerExists(userID)) { - if (gameController.currentState == gameState.gametime) + if (GameController.CurrentState == GameState.GameTime) { - if (gameController.currentGameMode == gameMode.longjump) + if (GameController.CurrentGameMode == GameMode.LongJump) { - jumpManager.CreateMarbleAndJump(e); + JumpManager.CreateMarbleAndJump(e); } - else if (gameController.currentGameMode == gameMode.highjump) + else if (GameController.CurrentGameMode == GameMode.HighJump) { - jumpManager.CreateMarbleAndHighJump(e); + JumpManager.CreateMarbleAndHighJump(e); } - else if (gameController.currentGameMode == gameMode.race) + else if (GameController.CurrentGameMode == GameMode.Race) { } @@ -333,7 +332,7 @@ private void AttemptToPlay(Arrrgs e) } else { - chatClient.SendMessage(chatJoinedChannel, displayName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, displayName + NoPlayerEntryExists); } } //AcceptWhispers @@ -368,9 +367,9 @@ public void AcceptWhispers(OnChatCommandReceivedArgs e) } } */ - public void Skins(Arrrgs e) + public void Skins(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToSkins(e); @@ -380,42 +379,42 @@ public void Skins(Arrrgs e) AttemptToSkins(e); } } - public void AttemptToSkins(Arrrgs e) + public void AttemptToSkins(CommandEventArgs e) { - string userID = e.userID; - string displayName = e.displayName; + string userID = e.UserID; + string displayName = e.DisplayName; - if (gameDataScript.CheckIfPlayerExists(userID)) + if (GameDataScript.CheckIfPlayerExists(userID)) { - string skinsPlayerOwns = gameDataScript.CheckSkins(e); + string skinsPlayerOwns = GameDataScript.CheckSkins(e); StartCoroutine(SkinsMessege(skinsPlayerOwns)); - chatClient.SendMessage(chatJoinedChannel, "https://www.twitch.tv/simpagamebot"); + ChatClient.SendMessage(ChatJoinedChannel, "https://www.twitch.tv/simpagamebot"); } else { - chatClient.SendMessage(chatJoinedChannel, displayName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, displayName + NoPlayerEntryExists); } } IEnumerator SkinsMessege(string skinsList) { yield return new WaitForSeconds(7); - chatClient.SendMessage(botJoinedChannel, skinsList); + ChatClient.SendMessage(BotJoinedChannel, skinsList); } public void AkaiEasterEgg(string name) { - chatClient.SendMessage(chatJoinedChannel,name + secretMsg); + ChatClient.SendMessage(ChatJoinedChannel, name + SecretMsg); } - public void Rotate(Arrrgs e) //Temporary command!!! TODO REMOVE + public void Rotate(CommandEventArgs e) //Temporary command!!! TODO REMOVE { - if (e.userID == "73184979") + if (e.UserID == "73184979") { FindObjectOfType().ResetShop(); } } - public void Give(Arrrgs e) + public void Give(CommandEventArgs e) { - if (chatClient == null) + if (ChatClient == null) { Setup(); AttemptToGive(e); @@ -425,65 +424,65 @@ public void Give(Arrrgs e) AttemptToGive(e); } } - public void AttemptToGive(Arrrgs e) + public void AttemptToGive(CommandEventArgs e) { - if (e.multiCommand != null) + if (e.MultiCommand != null) { - string userID = e.userID; - string displayName = e.displayName; - if (gameDataScript.CheckIfPlayerExists(userID)) + string userID = e.UserID; + string displayName = e.DisplayName; + if (GameDataScript.CheckIfPlayerExists(userID)) { - if (e.multiCommand.Count >= 2) + if (e.MultiCommand.Count >= 2) { - string otherPlayerDisplayName = e.multiCommand[0].TrimStart('@'); - string PersonGettingMoney = gameDataScript.ConvertCommonNameToUserID(otherPlayerDisplayName); + string otherPlayerDisplayName = e.MultiCommand[0].TrimStart('@'); + string PersonGettingMoney = GameDataScript.ConvertCommonNameToUserID(otherPlayerDisplayName); if (String.IsNullOrEmpty(PersonGettingMoney)) { - chatClient.SendMessage(chatJoinedChannel, cantGiveMoneyToPlayer1 + otherPlayerDisplayName + cantGiveMoneyToPlayer2); + ChatClient.SendMessage(ChatJoinedChannel, CantGiveMoneyToPlayer1 + otherPlayerDisplayName + CantGiveMoneyToPlayer2); } else { - if (gameDataScript.CheckIfPlayerExists(PersonGettingMoney) && - gameDataScript.CheckPlayerIDMatchesUserName(PersonGettingMoney, otherPlayerDisplayName)) + if (GameDataScript.CheckIfPlayerExists(PersonGettingMoney) && + GameDataScript.CheckPlayerIDMatchesUserName(PersonGettingMoney, otherPlayerDisplayName)) { int cost; //money = int.TryParse((e.multiCommand[1]), money); - if (int.TryParse((e.multiCommand[1]), out cost)) + if (int.TryParse((e.MultiCommand[1]), out cost)) { - int currentMoney = gameDataScript.CheckPlayerMoney(userID); + int currentMoney = GameDataScript.CheckPlayerMoney(userID); if (currentMoney >= cost) { - if (cost > 0 && cost<=10000) + if (cost > 0 && cost <= 10000) { - gameDataScript.SubtractMoneyFromPlayerID(cost, userID); - gameDataScript.AddMoneyToPlayerID(cost, PersonGettingMoney); - chatClient.SendMessage(chatJoinedChannel, displayName+ " gave " + e.multiCommand[0] +" "+cost); + GameDataScript.SubtractMoneyFromPlayerID(cost, userID); + GameDataScript.AddMoneyToPlayerID(cost, PersonGettingMoney); + ChatClient.SendMessage(ChatJoinedChannel, displayName + " gave " + e.MultiCommand[0] + " " + cost); } else { - chatClient.SendMessage(chatJoinedChannel, displayName+" you can only give give between 1 and 10000"); + ChatClient.SendMessage(ChatJoinedChannel, displayName + " you can only give give between 1 and 10000"); } } else { - chatClient.SendMessage(chatJoinedChannel, displayName + " you can't give money you dont have."); + ChatClient.SendMessage(ChatJoinedChannel, displayName + " you can't give money you dont have."); } } } else { - chatClient.SendMessage(chatJoinedChannel, cantGiveMoneyToPlayer1 + e.multiCommand[0] + cantGiveMoneyToPlayer2); + ChatClient.SendMessage(ChatJoinedChannel, CantGiveMoneyToPlayer1 + e.MultiCommand[0] + CantGiveMoneyToPlayer2); } } } else { - chatClient.SendMessage(chatJoinedChannel, displayName+ " to give use !give [PlayerName] [Amount]"); + ChatClient.SendMessage(ChatJoinedChannel, displayName + " to give use !give [PlayerName] [Amount]"); } } else { - chatClient.SendMessage(chatJoinedChannel, displayName + noPlayerEntryExists); + ChatClient.SendMessage(ChatJoinedChannel, displayName + NoPlayerEntryExists); } } } diff --git a/Assets/Scripts/DataManager.cs b/Assets/Scripts/DataManager.cs index 6f377d0..ea3182d 100644 --- a/Assets/Scripts/DataManager.cs +++ b/Assets/Scripts/DataManager.cs @@ -1,18 +1,18 @@ -using System.Collections; +using Newtonsoft.Json; +using System.Collections; using System.Collections.Generic; -using UnityEngine; using System.IO; -using Newtonsoft.Json; +using UnityEngine; -public class DataManager: MonoBehaviour +public class DataManager : MonoBehaviour { - public PlayerData data; - public string file = "GameData.txt"; + public PlayerData Data; + public string File = "GameData.txt"; public void Save() { - Debug.Log(data); - string json = JsonConvert.SerializeObject(data); + Debug.Log(Data); + string json = JsonConvert.SerializeObject(Data); //WriteToFile(file, json); System.IO.File.WriteAllText(@"D:\SimpaGameBotData\GameData.txt", json); } @@ -26,15 +26,15 @@ public void NewSave(Dictionary gameData) public void Backup(Dictionary gameData) { //Code saves at this point to our text file - Debug.Log(data); + Debug.Log(Data); string json = JsonConvert.SerializeObject(gameData, Formatting.Indented); System.IO.File.WriteAllText(@"D:\SimpaGameBotData\GameData.txt", json); } public string Load() { - data = new PlayerData(); - string json = ReadFromFile(file); + Data = new PlayerData(); + string json = ReadFromFile(File); return json; //JsonUtility.FromJsonOverwrite(json, data); } @@ -43,7 +43,7 @@ public void WriteToFile(string fileName, string json) { string path = GetFilePath(fileName); FileStream fileStream = new FileStream(path, FileMode.Create); - using(StreamWriter writer = new StreamWriter(fileStream)) + using (StreamWriter writer = new StreamWriter(fileStream)) { writer.Write(json); } @@ -58,7 +58,7 @@ private string GetFilePath(string filename) private string ReadFromFile(string fileName) { string path = GetFilePath(fileName); - if (File.Exists(path)) + if (System.IO.File.Exists(path)) { using (StreamReader reader = new StreamReader(path)) { diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 79e259f..4f78baf 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -1,47 +1,45 @@ -using System.Collections; // Don't eat TheBookSnail or you might get rat lungworm :0 +using Newtonsoft.Json; +using System.Collections; // Don't eat TheBookSnail or you might get rat lungworm :0 using System.Collections.Generic; -using UnityEngine; -using Newtonsoft.Json; using TMPro; +using UnityEngine; -public enum gameState { downtime, cutscene, gametime }; -public enum gameMode { longjump, highjump, race }; public class GameController : MonoBehaviour { - public DataManager dataManager; - public gameState currentState; - public gameMode currentGameMode; - [SerializeField] TextMeshPro gameStateText; - JumpManager jumpManager; - public Shop gameShop; - [SerializeField] Null nullCharacter; - [SerializeField] Timer timer; - [SerializeField] Shop shop; + public DataManager DataManager; + public GameState CurrentState; + public GameMode CurrentGameMode; + [SerializeField] TextMeshPro GameStateText; + JumpManager JumpManager; + public Shop GameShop; + [SerializeField] Null NullCharacter; + [SerializeField] Timer Timer; + [SerializeField] Shop Shop; //The game has states Downtime, Cutscene, Gametime //Gametime can link to different game modes longJump, highJump, race void Start() { - currentGameMode = gameMode.longjump; - currentState = gameState.downtime; - jumpManager = FindObjectOfType(); + CurrentGameMode = GameMode.LongJump; + CurrentState = GameState.DownTime; + JumpManager = FindObjectOfType(); UpdateGameStateText(); } private void UpdateGameStateText() { - Debug.Log(currentState); - switch (currentState) + Debug.Log(CurrentState); + switch (CurrentState) { - case gameState.downtime: - gameStateText.text = "Down Time"; + case GameState.DownTime: + GameStateText.text = "Down Time"; break; - case gameState.cutscene: - gameStateText.text = "Cut Scene"; + case GameState.Cutscene: + GameStateText.text = "Cut Scene"; break; - case gameState.gametime: - gameStateText.text = "Game Time"; + case GameState.GameTime: + GameStateText.text = "Game Time"; break; default: break; @@ -52,44 +50,44 @@ void Update() { if (Input.GetKeyDown("space")) { - jumpManager.DestroyMarbles(); + JumpManager.DestroyMarbles(); } } public void TriggerCutscene() { - currentState = gameState.cutscene; - gameShop.gameObject.SetActive(false); - nullCharacter.NullStartCutScene(); + CurrentState = GameState.Cutscene; + GameShop.gameObject.SetActive(false); + NullCharacter.NullStartCutScene(); UpdateGameStateText(); } public void TriggerGame() { - currentState = gameState.gametime; + CurrentState = GameState.GameTime; UpdateGameStateText(); - timer.ResetGameTimer(); + Timer.ResetGameTimer(); } public void TriggerDowntime() { - shop.ResetShop(); - currentState = gameState.downtime; + Shop.ResetShop(); + CurrentState = GameState.DownTime; UpdateGameStateText(); - timer.ResetDowntimeTimer(); - StartCoroutine(jumpManager.DestroyMarbles()); - nullCharacter.HideCharacter(); - gameShop.gameObject.SetActive(true); + Timer.ResetDowntimeTimer(); + StartCoroutine(JumpManager.DestroyMarbles()); + NullCharacter.HideCharacter(); + GameShop.gameObject.SetActive(true); } public string FindGameState() { - Debug.Log(currentGameMode); - switch (currentGameMode) + Debug.Log(CurrentGameMode); + switch (CurrentGameMode) { - case gameMode.longjump: + case GameMode.LongJump: return "Long Jump"; - case gameMode.highjump: + case GameMode.HighJump: Debug.Log("Launching High Jump"); return "High Jump"; - case gameMode.race: + case GameMode.Race: return "Race"; default: return "YOUR MOM"; diff --git a/Assets/Scripts/GameData.cs b/Assets/Scripts/GameData.cs index 353c5b5..556e2a9 100644 --- a/Assets/Scripts/GameData.cs +++ b/Assets/Scripts/GameData.cs @@ -1,28 +1,28 @@ -using System.Collections; +using Newtonsoft.Json; +using System.Collections; using System.Collections.Generic; -using UnityEngine; -using Newtonsoft.Json; +using TwitchLib.Client.Events; using TwitchLib.Client.Models; using TwitchLib.Unity; -using TwitchLib.Client.Events; +using UnityEngine; public class GameData : MonoBehaviour { //game data is in the form keys (unique ID) and data in the form of Player Data (see Player Data Script) - Dictionary gameData = new Dictionary(); - public DataManager dataManager; - MarbleList marbleList; - List playerDataList;//GameData.values() - List gameDataKeyList; + Dictionary Data = new Dictionary(); + public DataManager Manager; + MarbleList MarbleList; + List PlayerDataList;//GameData.values() + List GameDataKeyList; void Start() { //Load game data at start of game from JSON - Dictionary deserializedProduct = JsonConvert.DeserializeObject>(dataManager.Load()); - gameData = deserializedProduct; - marbleList = FindObjectOfType(); - gameData = marbleList.AddNewMarblesToGameData(gameData); - dataManager.NewSave(gameData); + Dictionary deserializedProduct = JsonConvert.DeserializeObject>(Manager.Load()); + Data = deserializedProduct; + MarbleList = FindObjectOfType(); + Data = MarbleList.AddNewMarblesToGameData(Data); + Manager.NewSave(Data); } void Update() @@ -30,9 +30,9 @@ void Update() if (Input.GetKeyDown(KeyCode.Alpha7)) { PlayerData tempData = new PlayerData(); - tempData.money = 0; - tempData.skins = FindObjectOfType().getEmptyAllMarbleDictionary(); - gameData.Add("123456", tempData); + tempData.Money = 0; + tempData.Skins = FindObjectOfType().getEmptyAllMarbleDictionary(); + Data.Add("123456", tempData); //var convertedDictionary = FindObjectOfType().getEmptyAllSpritesDictionary().ToDictionary(item => item.Key.ToString(), item => item.Value.ToString()); Debug.Log("pressing 7"); //JsonConvert.SerializeObject(dataManager); @@ -46,7 +46,7 @@ void Update() public bool CheckIfPlayerExists(string playerID) { - if (gameData.ContainsKey(playerID) ) + if (Data.ContainsKey(playerID)) { return true; } @@ -55,37 +55,37 @@ public bool CheckIfPlayerExists(string playerID) return false; } } - public void CreateNewPlayerEntry(Arrrgs e) + public void CreateNewPlayerEntry(CommandEventArgs e) { PlayerData tempData = new PlayerData(); - tempData.money = 0; - tempData.skins = FindObjectOfType().getEmptyAllMarbleDictionary(); - tempData.equiptSkin = 0; - tempData.playerName = e.displayName; - tempData.isSubscribed = false; - gameData.Add(e.userID, tempData); + tempData.Money = 0; + tempData.Skins = FindObjectOfType().getEmptyAllMarbleDictionary(); + tempData.ActiveSkin = 0; + tempData.PlayerName = e.DisplayName; + tempData.IsSubscribed = false; + Data.Add(e.UserID, tempData); SaveGameDataToTXT(); Debug.Log("GAME DATA SUCCESFULLY SAVED!!!!"); } public void AddMoneyToPlayerID(int money, string playerID) { - gameData[playerID].money += money; + Data[playerID].Money += money; SaveGameDataToTXT(); Debug.Log("GAME DATA SUCCESFULLY SAVED!!!!"); } public void SubtractMoneyFromPlayerID(int money, string playerID) { - gameData[playerID].money -= money; + Data[playerID].Money -= money; SaveGameDataToTXT(); Debug.Log("GAME DATA SUCCESFULLY SAVED!!!!"); } public int CheckPlayerMoney(string playerID) { - return gameData[playerID].money; + return Data[playerID].Money; } public bool IsSkinUnlocked(string playerID, int skinIndex) { - if (gameData[playerID].skins[skinIndex] == true) + if (Data[playerID].Skins[skinIndex] == true) { return true; } @@ -96,41 +96,41 @@ public bool IsSkinUnlocked(string playerID, int skinIndex) } public void UnlockSkinForPlayer(string playerID, int skinIndex) { - gameData[playerID].skins[skinIndex] = true; + Data[playerID].Skins[skinIndex] = true; SaveGameDataToTXT(); Debug.Log("GAME DATA SUCCESFULLY SAVED!!!!"); } public void SetPlayerEquipSkin(string playerID, int skinIndex) { - gameData[playerID].equiptSkin = skinIndex; + Data[playerID].ActiveSkin = skinIndex; SaveGameDataToTXT(); Debug.Log("GAME DATA SUCCESFULLY SAVED!!!!"); } public int GetPlayerEquipSkin(string playerID) { - return gameData[playerID].equiptSkin; + return Data[playerID].ActiveSkin; } public void SaveGameDataToTXT() { - dataManager.NewSave(gameData); + Manager.NewSave(Data); Debug.Log("GAME DATA SUCCESSFULLY SAVED!!!!"); } public bool CheckIfPlayerSubscribedToWhispers(string playerID) { - return gameData[playerID].isSubscribed; + return Data[playerID].IsSubscribed; //Returns true if player subscribed } - public string CheckSkins(Arrrgs e) + public string CheckSkins(CommandEventArgs e) { - string playerID = e.userID; - string playerName = e.displayName; - string skinList = playerName+": "; - for (int i = 0; i < gameData[playerID].skins.Count; i++) + string playerID = e.UserID; + string playerName = e.DisplayName; + string skinList = playerName + ": "; + for (int i = 0; i < Data[playerID].Skins.Count; i++) { - if (gameData[playerID].skins[i] == true) + if (Data[playerID].Skins[i] == true) { - skinList += marbleList.marbleCodeToCommonName[i] + ", "; + skinList += MarbleList.MarbleCodeToCommonName[i] + ", "; } } return skinList; @@ -138,20 +138,20 @@ public string CheckSkins(Arrrgs e) public string ConvertCommonNameToUserID(string commonName) { //var myKey = dictionary.FirstOrDefault(x => x.Value == "one").Key; - playerDataList = new List(gameData.Values); - for (int i = 0; i < playerDataList.Count; i++) + PlayerDataList = new List(Data.Values); + for (int i = 0; i < PlayerDataList.Count; i++) { - if (playerDataList[i].playerName.Equals(commonName,System.StringComparison.CurrentCultureIgnoreCase)) + if (PlayerDataList[i].PlayerName.Equals(commonName, System.StringComparison.CurrentCultureIgnoreCase)) { - gameDataKeyList = new List(gameData.Keys); - return gameDataKeyList[i]; + GameDataKeyList = new List(Data.Keys); + return GameDataKeyList[i]; } } return ""; } public bool CheckPlayerIDMatchesUserName(string userID, string name) { - if (gameData[userID].playerName == name) + if (Data[userID].PlayerName == name) { return true; } diff --git a/Assets/Scripts/GameMode.cs b/Assets/Scripts/GameMode.cs new file mode 100644 index 0000000..ab14290 --- /dev/null +++ b/Assets/Scripts/GameMode.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum GameMode +{ + LongJump, + HighJump, + Race +}; diff --git a/Assets/Scripts/Arrrgs.cs.meta b/Assets/Scripts/GameMode.cs.meta similarity index 83% rename from Assets/Scripts/Arrrgs.cs.meta rename to Assets/Scripts/GameMode.cs.meta index 94afe53..1a849a3 100644 --- a/Assets/Scripts/Arrrgs.cs.meta +++ b/Assets/Scripts/GameMode.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6fdb9ba6061a24d43b5507259151dfc9 +guid: 0fb60972b02d5d74e885aa9dbdcb08a5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/GameState.cs b/Assets/Scripts/GameState.cs new file mode 100644 index 0000000..c93e5d5 --- /dev/null +++ b/Assets/Scripts/GameState.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum GameState +{ + DownTime, + Cutscene, + GameTime +}; diff --git a/Assets/Scripts/GameState.cs.meta b/Assets/Scripts/GameState.cs.meta new file mode 100644 index 0000000..030aafa --- /dev/null +++ b/Assets/Scripts/GameState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 72cac14c2cdf27d46af513eea0789c30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/JumpManager.cs b/Assets/Scripts/JumpManager.cs index 007908b..65192e4 100644 --- a/Assets/Scripts/JumpManager.cs +++ b/Assets/Scripts/JumpManager.cs @@ -1,74 +1,74 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using UnityEngine; +using TMPro; +using TwitchLib.Client.Events; using TwitchLib.Client.Models; using TwitchLib.Unity; -using TwitchLib.Client.Events; -using System; -using TMPro; +using UnityEngine; public class JumpManager : MonoBehaviour { // I have syntactic sugar - [SerializeField] GameObject marbleObject; - [SerializeField] Transform longJumpLocation; - MarbleList marbleList; - MarbleObject playerMarble; - SpriteRenderer playerSpriteRenderer; - GameData gameData; - List longJumpedPlayers = new List(); - List highJumpedPlayers = new List(); - public int orderInLayer; - public int costToReroll = 50; + [SerializeField] GameObject MarbleObject; + [SerializeField] Transform LongJumpLocation; + MarbleList MarbleList; + MarbleObject PlayerMarble; + SpriteRenderer PlayerSpriteRenderer; + GameData GameData; + List LongJumpedPlayers = new List(); + List HighJumpedPlayers = new List(); + public int OrderInLayer; + public int CostToReroll = 50; private void Start() { - gameData = FindObjectOfType(); - marbleList = FindObjectOfType(); - orderInLayer = 0; + GameData = FindObjectOfType(); + MarbleList = FindObjectOfType(); + OrderInLayer = 0; Dictionary kvp = new Dictionary(); } public void ResetLongJumpedPlayers() { - longJumpedPlayers = new List(); + LongJumpedPlayers = new List(); } - + public void ResetHighJumpedPlayers() { - highJumpedPlayers = new List(); + HighJumpedPlayers = new List(); } - public void CreateMarbleAndJump(Arrrgs e) + public void CreateMarbleAndJump(CommandEventArgs e) { - string userID = e.userID; - string displayName = e.displayName; + string userID = e.UserID; + string displayName = e.DisplayName; //if the player has not jumped yet - if (!(longJumpedPlayers.Contains(userID))) + if (!(LongJumpedPlayers.Contains(userID))) { - longJumpedPlayers.Add(userID); - var mb = Instantiate(marbleObject, longJumpLocation.position, transform.rotation); + LongJumpedPlayers.Add(userID); + var mb = Instantiate(MarbleObject, LongJumpLocation.position, transform.rotation); mb.transform.SetParent(transform); - mb.GetComponentInChildren().sortingOrder = orderInLayer; - orderInLayer++; - playerMarble = mb.GetComponentInChildren(); - playerMarble.playerName.text = displayName; - int marbleIndex = gameData.GetPlayerEquipSkin(userID); - GameObject marbleGameObject = marbleList.GetMarbleFromMarbleCode(marbleIndex); - playerMarble.gameMarbleSprite.sprite = marbleGameObject.GetComponent().marbleSprite; - playerMarble.playerID = userID; + mb.GetComponentInChildren().sortingOrder = OrderInLayer; + OrderInLayer++; + PlayerMarble = mb.GetComponentInChildren(); + PlayerMarble.PlayerName.text = displayName; + int marbleIndex = GameData.GetPlayerEquipSkin(userID); + GameObject marbleGameObject = MarbleList.GetMarbleFromMarbleCode(marbleIndex); + PlayerMarble.GameMarbleSprite.sprite = marbleGameObject.GetComponent().MarbleSprite; + PlayerMarble.PlayerId = userID; } else //if player has already rolled { - if (gameData.CheckPlayerMoney(userID) > costToReroll) + if (GameData.CheckPlayerMoney(userID) > CostToReroll) { MarbleObject[] allMarbles = GetComponentsInChildren(); foreach (var marble in allMarbles) { - if (marble.playerID == userID && !(marble.isrolling)) + if (marble.PlayerId == userID && !(marble.IsRolling)) { Destroy(marble.transform.parent.gameObject); - gameData.SubtractMoneyFromPlayerID(costToReroll, userID); - longJumpedPlayers.Remove(userID); + GameData.SubtractMoneyFromPlayerID(CostToReroll, userID); + LongJumpedPlayers.Remove(userID); CreateMarbleAndJump(e); } } @@ -78,23 +78,23 @@ public void CreateMarbleAndJump(Arrrgs e) } } - public void CreateMarbleAndHighJump(Arrrgs e) + public void CreateMarbleAndHighJump(CommandEventArgs e) { - string userID = e.userID; - string displayName = e.displayName; - if (!(highJumpedPlayers.Contains(userID))) + string userID = e.UserID; + string displayName = e.DisplayName; + if (!(HighJumpedPlayers.Contains(userID))) { - highJumpedPlayers.Add(userID); - var mb = Instantiate(marbleObject, longJumpLocation.position, transform.rotation); + HighJumpedPlayers.Add(userID); + var mb = Instantiate(MarbleObject, LongJumpLocation.position, transform.rotation); mb.transform.SetParent(transform); - mb.GetComponentInChildren().sortingOrder = orderInLayer; - orderInLayer++; - playerMarble = mb.GetComponentInChildren(); - playerMarble.playerName.text = displayName; - int marbleIndex = gameData.GetPlayerEquipSkin(userID); - GameObject marbleGameObject = marbleList.GetMarbleFromMarbleCode(marbleIndex); - playerMarble.gameMarbleSprite.sprite = marbleGameObject.GetComponent().marbleSprite; - playerMarble.playerID = userID; + mb.GetComponentInChildren().sortingOrder = OrderInLayer; + OrderInLayer++; + PlayerMarble = mb.GetComponentInChildren(); + PlayerMarble.PlayerName.text = displayName; + int marbleIndex = GameData.GetPlayerEquipSkin(userID); + GameObject marbleGameObject = MarbleList.GetMarbleFromMarbleCode(marbleIndex); + PlayerMarble.GameMarbleSprite.sprite = marbleGameObject.GetComponent().MarbleSprite; + PlayerMarble.PlayerId = userID; } } @@ -102,27 +102,27 @@ public IEnumerator DestroyMarbles() { MarbleObject[] allMarbles = GetComponentsInChildren(); - foreach (var marble in allMarbles) + foreach (var marble in allMarbles) + { + while (marble.IsRolling == true) { - while (marble.isrolling == true) - { - yield return new WaitForSeconds(0.5f); - } + yield return new WaitForSeconds(0.5f); } + } yield return new WaitForSeconds(5f); foreach (Transform child in this.transform) { Destroy(child.gameObject); } - longJumpedPlayers = new List(); - orderInLayer = 0; + LongJumpedPlayers = new List(); + OrderInLayer = 0; } - //playerMarble.marbleSprite = - /*playerMarble = mb.GetComponent(); - playerSpriteRenderer = mb.GetComponent(); - playerMarble.playerName - e.Command.ChatMessage.Username*/ - } + //playerMarble.marbleSprite = + /*playerMarble = mb.GetComponent(); + playerSpriteRenderer = mb.GetComponent(); + playerMarble.playerName + e.Command.ChatMessage.Username*/ +} diff --git a/Assets/Scripts/Marble.cs b/Assets/Scripts/Marble.cs index 5a4021e..9f157eb 100644 --- a/Assets/Scripts/Marble.cs +++ b/Assets/Scripts/Marble.cs @@ -5,20 +5,20 @@ public class Marble : MonoBehaviour { //All the data about the ball I need to make dictionary entry - public int marbleCode; //unique to each ball, not for player to see - public string commonName; //name for player to see and call, not nessesarily unique - public int cost; - public int rarity; //use scale 1-4 inclusive, used to determine cost and chance to appear in the shop - public Sprite marbleSprite; + public int MarbleCode; //unique to each ball, not for player to see + public string CommonName; //name for player to see and call, not nessesarily unique + public int Cost; + public int Rarity; //use scale 1-4 inclusive, used to determine cost and chance to appear in the shop + public Sprite MarbleSprite; void Start() { - marbleSprite = GetComponent().sprite; + MarbleSprite = GetComponent().sprite; } void Update() { - + } } diff --git a/Assets/Scripts/MarbleAssigner.cs b/Assets/Scripts/MarbleAssigner.cs deleted file mode 100644 index 9c020b7..0000000 --- a/Assets/Scripts/MarbleAssigner.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class MarbleAssigner : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/MarbleList.cs b/Assets/Scripts/MarbleList.cs index 48ea2b1..a6a88e6 100644 --- a/Assets/Scripts/MarbleList.cs +++ b/Assets/Scripts/MarbleList.cs @@ -4,28 +4,28 @@ public class MarbleList : MonoBehaviour { - [SerializeField] int minCommon = 0; - [SerializeField] int maxCommon = 100; - [SerializeField] int maxRare = 400; - [SerializeField] int maxEpic = 1000; - [SerializeField] int maxLegendary = 2000; + [SerializeField] int MinimumCommon = 0; + [SerializeField] int MaximumCommon = 100; + [SerializeField] int MaximumRare = 400; + [SerializeField] int MaximumEpic = 1000; + [SerializeField] int MaxLegendary = 2000; - public List marbleArraySetToFalse = new List(); + public List MarbleArraySetToFalse = new List(); //Every string needs to be the unique code for the marble //The bool will be true or false depending on if the player has unlocked that marble - public Dictionary marbleCommonNameToMarbleCode = new Dictionary(); + public Dictionary MarbleCommonNameToMarbleCode = new Dictionary(); //This is a way for the game to quickly look up what the unique marble code is for a common name - public Dictionary marbleCodeToCost = new Dictionary(); + public Dictionary MarbleCodeToCost = new Dictionary(); //This lets us look up the cost of a marble if we have the keycode - public Dictionary marbleCodeToRarity = new Dictionary(); + public Dictionary MarbleCodeToRarity = new Dictionary(); //This links a marble code to its cost - public Dictionary marbleCodeToCommonName = new Dictionary(); + public Dictionary MarbleCodeToCommonName = new Dictionary(); - [SerializeField] GameObject[] marbles; + [SerializeField] GameObject[] Marbles; //This game objects stores the balls uniquecode,skin(sprite),cost and rarity private void Start() @@ -33,28 +33,28 @@ private void Start() int code = 0; //the goal here is to make a dictionary of every ball's unique code and //have it initialized to be false (not unlocked) - foreach (var item in marbles) + foreach (var item in Marbles) { //We grab the ball script at the start so we can build our dictionaries at start var marble = item.GetComponent(); - marble.marbleCode = code; + marble.MarbleCode = code; //We first need to set the code before we build the dictionaries - marbleArraySetToFalse.Add(false); - marbleCommonNameToMarbleCode.Add((marble.commonName.ToLower()), marble.marbleCode); - marbleCodeToCommonName.Add(marble.marbleCode, (marble.commonName.ToLower())); - int cost = setMarbleCostsBasedOnRarity(marble.rarity); - marbleCodeToCost.Add(marble.marbleCode, cost); - marble.cost = cost; + MarbleArraySetToFalse.Add(false); + MarbleCommonNameToMarbleCode.Add((marble.CommonName.ToLower()), marble.MarbleCode); + MarbleCodeToCommonName.Add(marble.MarbleCode, (marble.CommonName.ToLower())); + int cost = setMarbleCostsBasedOnRarity(marble.Rarity); + MarbleCodeToCost.Add(marble.MarbleCode, cost); + marble.Cost = cost; code = code + 1; } //The player always has marble 0 unlocked - marbleArraySetToFalse[0] = true; + MarbleArraySetToFalse[0] = true; } - public List getEmptyAllMarbleDictionary() + public List getEmptyAllMarbleDictionary() { - return marbleArraySetToFalse; + return MarbleArraySetToFalse; } //At the start of the game there may be new marbles that need to be added to the game data //We need to count the difference between the current # and the existing number in any game data entry @@ -62,13 +62,13 @@ public List getEmptyAllMarbleDictionary() public Dictionary AddNewMarblesToGameData(Dictionary gameData) { Debug.Log("ADD NEW MARBLES CALLED"); - int currentNumberOfMarbles = marbles.Length; + int currentNumberOfMarbles = Marbles.Length; foreach (var kvp in gameData) { - while (kvp.Value.skins.Count < currentNumberOfMarbles) + while (kvp.Value.Skins.Count < currentNumberOfMarbles) { Debug.Log("new skin added"); - kvp.Value.skins.Add(false); + kvp.Value.Skins.Add(false); } } return gameData; @@ -76,7 +76,7 @@ public Dictionary AddNewMarblesToGameData(Dictionary GetMarblesForShop(int howManyMarbles) { - int marbleLength = marbles.Length; + int marbleLength = Marbles.Length; HashSet returnedMarbles = new HashSet(); - do { + do + { int marbleCode = Random.Range(0, marbleLength); - returnedMarbles.Add(marbles[marbleCode]); - } while (returnedMarbles.Count().commonName); + Debug.Log(item.GetComponent().CommonName); } return returnedMarbles; diff --git a/Assets/Scripts/MarbleManager.cs b/Assets/Scripts/MarbleManager.cs index 54394c9..b45d50c 100644 --- a/Assets/Scripts/MarbleManager.cs +++ b/Assets/Scripts/MarbleManager.cs @@ -7,7 +7,7 @@ public class MarbleManager : MonoBehaviour private void Start() { - + } //Ball Manager make sure there is only one ball per player at any time @@ -18,6 +18,6 @@ public void SpawnMarble() public bool CanSpawn() { - return true; + return true; } } diff --git a/Assets/Scripts/MarbleObject.cs b/Assets/Scripts/MarbleObject.cs index 29cb582..a15b70a 100644 --- a/Assets/Scripts/MarbleObject.cs +++ b/Assets/Scripts/MarbleObject.cs @@ -1,8 +1,8 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using UnityEngine; using TMPro; -using System; +using UnityEngine; public class MarbleObject : MonoBehaviour { @@ -10,34 +10,34 @@ public class MarbleObject : MonoBehaviour //Ball needs to be tied to a player chat ID //Can only have one marble per player, should not instantiate if player has ball in play - //FOR EVENTS: -go to appropriate starting location - // -give instructions on where to go (should have random factor) - // -Despawn Object - float longJumpForce; - [SerializeField] float highJumpForce = 1.0f; - Rigidbody2D rb; - public string playerID; - public SpriteRenderer gameMarbleSprite; - public TextMeshPro playerName; - float speed; - GameData gameData; - private string jumpDistance; - [SerializeField] TextFollow marbleText; - public bool isrolling; - Commands commands; + //FOR EVENTS: -go to appropriate starting location + // -give instructions on where to go (should have random factor) + // -Despawn Object + float LongJumpForce; + [SerializeField] float HighJumpForce = 1.0f; + Rigidbody2D Rigidbody; + public string PlayerId; + public SpriteRenderer GameMarbleSprite; + public TextMeshPro PlayerName; + float Speed; + GameData GameData; + private string JumpDistance; + [SerializeField] TextFollow MarbleText; + public bool IsRolling; + Commands Commands; - GameController gameController; - string gameState; + GameController GameController; + string GameState; void Start() { - isrolling = true; - rb = GetComponent(); + IsRolling = true; + Rigidbody = GetComponent(); FreeRotation(); - gameData = FindObjectOfType(); - gameController = FindObjectOfType(); - gameState = gameController.FindGameState(); - ActivateGameState(gameState); + GameData = FindObjectOfType(); + GameController = FindObjectOfType(); + GameState = GameController.FindGameState(); + ActivateGameState(GameState); } private void ActivateGameState(string gameState) @@ -61,19 +61,19 @@ public void LongJump() int percentage = UnityEngine.Random.Range(0, 10001); if (percentage == 10000) { - commands = FindObjectOfType(); - commands.AkaiEasterEgg(playerName.text); + Commands = FindObjectOfType(); + Commands.AkaiEasterEgg(PlayerName.text); } //Force acting on the marble float range = 4.8f + (((7.9f / 10000f) * percentage)); Debug.Log(range); float distance = ((100f / 10000f) * percentage); - jumpDistance = System.String.Format("{0:0.00}", distance); + JumpDistance = System.String.Format("{0:0.00}", distance); int score = Mathf.RoundToInt(distance); - longJumpForce = range; + LongJumpForce = range; //transform.position = new Vector3(-13.5f, -4.828952f, 0f); - rb.AddForce(new Vector2(longJumpForce, 0), ForceMode2D.Impulse); - StartCoroutine(WaitUntilMovementStops(playerID,score)); + Rigidbody.AddForce(new Vector2(LongJumpForce, 0), ForceMode2D.Impulse); + StartCoroutine(WaitUntilMovementStops(PlayerId, score)); } public void HighJump() @@ -82,8 +82,8 @@ public void HighJump() int percentage = UnityEngine.Random.Range(0, 10000); if (percentage == 10000) { - commands = FindObjectOfType(); - commands.AkaiEasterEgg(playerName.text); + Commands = FindObjectOfType(); + Commands.AkaiEasterEgg(PlayerName.text); } //Force acting on the marble /* @@ -95,32 +95,32 @@ public void HighJump() longJumpForce = range; //transform.position = new Vector3(-13.5f, -4.828952f, 0f); */ - rb.AddForce(new Vector2(0, -1*(highJumpForce)), ForceMode2D.Impulse); + Rigidbody.AddForce(new Vector2(0, -1 * (HighJumpForce)), ForceMode2D.Impulse); //StartCoroutine(WaitUntilMovementStops(playerID, score)); - + } IEnumerator WaitUntilMovementStops(string ID, int money) { do { - speed = rb.velocity.magnitude; + Speed = Rigidbody.velocity.magnitude; yield return new WaitForSeconds(0.5f); } - while (speed > 0); + while (Speed > 0); Debug.Log("MOVEMENTSTOPPED"); - marbleText.TriggerAnimation(); - gameData.AddMoneyToPlayerID(money, ID); - isrolling = false; + MarbleText.TriggerAnimation(); + GameData.AddMoneyToPlayerID(money, ID); + IsRolling = false; } public void LockRotation() { - rb.constraints = RigidbodyConstraints2D.FreezeRotation; + Rigidbody.constraints = RigidbodyConstraints2D.FreezeRotation; } public void FreeRotation() { - rb.constraints = RigidbodyConstraints2D.None; + Rigidbody.constraints = RigidbodyConstraints2D.None; } private void OnCollisionEnter2D(Collision2D otherCollider) { @@ -128,11 +128,11 @@ private void OnCollisionEnter2D(Collision2D otherCollider) if (otherGameObject.layer == 9) { LockRotation(); - } + } } public void TransitionToScoreText() { - playerName.text += $"\n{jumpDistance}"; - //jumpDistance.ToString(); + PlayerName.text += $"\n{JumpDistance}"; + //jumpDistance.ToString(); } } diff --git a/Assets/Scripts/Null.cs b/Assets/Scripts/Null.cs index 1644a09..f0a5641 100644 --- a/Assets/Scripts/Null.cs +++ b/Assets/Scripts/Null.cs @@ -5,7 +5,7 @@ public class Null : MonoBehaviour { //NULL is a charasmatic Lady bug who is the master of ceremony for the stream marble games! - [SerializeField] GameController gameController; + [SerializeField] GameController Controller; void Start() { gameObject.SetActive(false); @@ -20,7 +20,7 @@ public void NullStartCutScene() IEnumerator StartingDialogue() { yield return new WaitForSeconds(10); - gameController.TriggerGame(); + Controller.TriggerGame(); } public void HideCharacter() { diff --git a/Assets/Scripts/PlayerData.cs b/Assets/Scripts/PlayerData.cs index 8a0850c..670e957 100644 --- a/Assets/Scripts/PlayerData.cs +++ b/Assets/Scripts/PlayerData.cs @@ -2,14 +2,14 @@ using System.Collections.Generic; using UnityEngine; -public class PlayerData - //DATA that is stored in a dictionary and can be accessed by looking at the key which will be a player chat ID +public class PlayerData +//DATA that is stored in a dictionary and can be accessed by looking at the key which will be a player chat ID { - public int money = 0; - public List skins = new List(); - public int equiptSkin = 0; - public string playerName; - public bool isSubscribed; + public int Money = 0; + public List Skins = new List(); + public int ActiveSkin = 0; + public string PlayerName; + public bool IsSubscribed; //Things I may want to add later bellow //public Dictionary sfx = new Dictionary(); //public Dictionary vfx = new Dictionary(); diff --git a/Assets/Scripts/Shop.cs b/Assets/Scripts/Shop.cs index 0314659..d3da4e2 100644 --- a/Assets/Scripts/Shop.cs +++ b/Assets/Scripts/Shop.cs @@ -5,14 +5,14 @@ public class Shop : MonoBehaviour { //It was the salmonmoose - [SerializeField] GameObject shopObject; - [SerializeField] Transform[] shopObjectLocations; - MarbleList marbleList; - HashSet shopMarbles; + [SerializeField] GameObject ShopObject; + [SerializeField] Transform[] ShopObjectLocations; + MarbleList MarbleList; + HashSet ShopMarbles; void Start() { - marbleList = FindObjectOfType(); + MarbleList = FindObjectOfType(); DisplayShopItems(); } @@ -21,23 +21,23 @@ public void DisplayShopItems() { Generate3ShopItems(); int counter = 0; - foreach (var item in shopMarbles) + foreach (var item in ShopMarbles) { - GameObject shop = Instantiate(shopObject); + GameObject shop = Instantiate(ShopObject); shop.transform.SetParent(transform); Marble marble = item.GetComponent(); - string name = marble.commonName; - string cost = marble.cost.ToString(); - Sprite sprite = marble.marbleSprite; + string name = marble.CommonName; + string cost = marble.Cost.ToString(); + Sprite sprite = marble.MarbleSprite; ShopObject newShopObject = shop.GetComponent(); - newShopObject.marbleName.text = name; - newShopObject.marbleCost.text = "$" + cost; - newShopObject.marbleSpriteRenderer.sprite = sprite; + newShopObject.Name.text = name; + newShopObject.Cost.text = "$" + cost; + newShopObject.SpriteRender.sprite = sprite; - if (counter < shopObjectLocations.Length) + if (counter < ShopObjectLocations.Length) { - shop.transform.position = shopObjectLocations[counter].position; + shop.transform.position = ShopObjectLocations[counter].position; } counter++; } @@ -45,7 +45,7 @@ public void DisplayShopItems() private void Generate3ShopItems() { - shopMarbles = marbleList.GetMarblesForShop(3); + ShopMarbles = MarbleList.GetMarblesForShop(3); } public void ResetShop() @@ -70,7 +70,7 @@ public void DestroyShopObjectChildren() public bool MarbleNamesInShop(string checkedMarble) { bool marbleInShop = false; - foreach (var marble in shopMarbles) + foreach (var marble in ShopMarbles) { Debug.Log(marble.name); Debug.Log(checkedMarble); diff --git a/Assets/Scripts/ShopObject.cs b/Assets/Scripts/ShopObject.cs index f053fb4..a2f1990 100644 --- a/Assets/Scripts/ShopObject.cs +++ b/Assets/Scripts/ShopObject.cs @@ -1,11 +1,11 @@ using System.Collections; using System.Collections.Generic; -using UnityEngine; using TMPro; +using UnityEngine; public class ShopObject : MonoBehaviour { - [SerializeField] public TMP_Text marbleName; - [SerializeField] public TextMeshPro marbleCost; - [SerializeField] public SpriteRenderer marbleSpriteRenderer; + [SerializeField] public TMP_Text Name; + [SerializeField] public TextMeshPro Cost; + [SerializeField] public SpriteRenderer SpriteRender; } diff --git a/Assets/Scripts/TextFollow.cs b/Assets/Scripts/TextFollow.cs index 1f527dc..538a9a1 100644 --- a/Assets/Scripts/TextFollow.cs +++ b/Assets/Scripts/TextFollow.cs @@ -4,28 +4,28 @@ public class TextFollow : MonoBehaviour { - [SerializeField] Transform marblePos; - Transform textPos; - Vector3 offset = new Vector3(0, .9f, 0); - [SerializeField] MarbleObject myMarbleObject; - Animator textAnimator; + [SerializeField] Transform MarblePos; + Transform TextPos; + Vector3 Offset = new Vector3(0, .9f, 0); + [SerializeField] MarbleObject MyMarbleObject; + Animator TextAnimator; private void Start() { - textPos = GetComponent(); - textAnimator = GetComponent(); + TextPos = GetComponent(); + TextAnimator = GetComponent(); } void Update() { - textPos.position = marblePos.position + offset; + TextPos.position = MarblePos.position + Offset; } public void DisplayScore() { - myMarbleObject.TransitionToScoreText(); + MyMarbleObject.TransitionToScoreText(); } public void TriggerAnimation() { - textAnimator.SetTrigger("showScore"); + TextAnimator.SetTrigger("showScore"); } } diff --git a/Assets/Scripts/Timer.cs b/Assets/Scripts/Timer.cs index 27e9fcf..77820f0 100644 --- a/Assets/Scripts/Timer.cs +++ b/Assets/Scripts/Timer.cs @@ -1,44 +1,44 @@ using System.Collections; using System.Collections.Generic; +using TMPro; using UnityEngine; using UnityEngine.UI; -using TMPro; public class Timer : MonoBehaviour { - public float timeRemaining = 65; - public bool timerIsRunning = false; - public TextMeshPro timeText; - [SerializeField] float timeBetweenGames = 600; - [SerializeField] float timeOfGame = 90; - [SerializeField] GameController gameController; + public float TimeRemaining = 65; + public bool IsTimerRunning = false; + public TextMeshPro TimeText; + [SerializeField] float TimeBetweenGames = 600; + [SerializeField] float TimeOfGame = 90; + [SerializeField] GameController GameController; bool wasGameTime; void Start() { - timerIsRunning = true; + IsTimerRunning = true; wasGameTime = true; } void Update() { - if (timerIsRunning) + if (IsTimerRunning) { - if (timeRemaining > 0) + if (TimeRemaining > 0) { - timeRemaining -= Time.deltaTime; - DisplayTime(timeRemaining); + TimeRemaining -= Time.deltaTime; + DisplayTime(TimeRemaining); } else { - timerIsRunning = false; - timeRemaining = 0; + IsTimerRunning = false; + TimeRemaining = 0; if (wasGameTime == true) { - gameController.TriggerCutscene(); + GameController.TriggerCutscene(); wasGameTime = false; } - else + else { - gameController.TriggerDowntime(); + GameController.TriggerDowntime(); wasGameTime = true; } } @@ -50,16 +50,16 @@ void DisplayTime(float timeToDisplay) float minutes = Mathf.FloorToInt(timeToDisplay / 60); float seconds = Mathf.FloorToInt(timeToDisplay % 60); - timeText.text = string.Format("{0:00}:{1:00}", minutes, seconds); + TimeText.text = string.Format("{0:00}:{1:00}", minutes, seconds); } public void ResetGameTimer() { - timeRemaining = timeOfGame; - timerIsRunning = true; + TimeRemaining = TimeOfGame; + IsTimerRunning = true; } public void ResetDowntimeTimer() { - timeRemaining = timeBetweenGames; - timerIsRunning = true; + TimeRemaining = TimeBetweenGames; + IsTimerRunning = true; } } diff --git a/Assets/Scripts/TwitchAPI.cs b/Assets/Scripts/TwitchAPI.cs index 5d413e8..3e8910a 100644 --- a/Assets/Scripts/TwitchAPI.cs +++ b/Assets/Scripts/TwitchAPI.cs @@ -1,26 +1,27 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using UnityEngine; +using TwitchLib.Api.Models.Undocumented.Chatters; using TwitchLib.Client.Models; using TwitchLib.Unity; -using TwitchLib.Api.Models.Undocumented.Chatters; -using System; +using UnityEngine; public class TwitchAPI : MonoBehaviour { - public Api api; - Client getClient; - TwitchClient twitchClient; + public Api API; + Client GetClient; + TwitchClient TwitchClient; + // Start is called before the first frame update void Start() { Application.runInBackground = true; - api = new Api(); - api.Settings.AccessToken = Secrets.bot_access_token; - api.Settings.ClientId = Secrets.client_id; + API = new Api(); + API.Settings.AccessToken = Secrets.BotAccessToken; + API.Settings.ClientId = Secrets.ClientID; GameObject client = GameObject.Find("Client"); - twitchClient = client.GetComponent(); + TwitchClient = client.GetComponent(); } // Update is called once per frame @@ -40,7 +41,7 @@ private void GetChattersListCallBack(List listOfChatters) Debug.Log("List of " + listOfChatters.Count + "Viewers: "); foreach (var chatterObject in listOfChatters) { - // Debug.Log(chatterObject.Username); + // Debug.Log(chatterObject.Username); } } } diff --git a/Assets/Scripts/TwitchClient.cs b/Assets/Scripts/TwitchClient.cs index 619502f..e66e57b 100644 --- a/Assets/Scripts/TwitchClient.cs +++ b/Assets/Scripts/TwitchClient.cs @@ -1,50 +1,45 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using UnityEngine; -using TwitchLib.Client.Models; -using TwitchLib.Unity; using TwitchLib.Client.Events; -using System; +using TwitchLib.Client.Models; using TwitchLib.PubSub.Events; +using TwitchLib.Unity; +using UnityEngine; using UnityEngine.UI; public class TwitchClient : MonoBehaviour { // Client Object is defined in Twitch Lib - public Client client; - public JoinedChannel joinedChannel; - public JoinedChannel botChannel; - CommandQueue commandQueue; - private PubSub pubSub; - [SerializeField] Text debug; - private string channel_name = "simpathey"; - private string bot_name = "simpagamebot"; - - private void Awake() - { - Secrets.EnvironmentVariables(); - } + public Client Client; + public JoinedChannel JoinedChannel; + public JoinedChannel BotChannel; + CommandQueue CommandQueue; + private PubSub PubSub; + [SerializeField] Text Debug; + private string ChannelName = "simpathey"; + private string BotName = "simpagamebot"; void Start() { - commandQueue = FindObjectOfType(); + CommandQueue = FindObjectOfType(); //This script should always run in background if game application is running Application.runInBackground = true; //set up bot and tell what channel to join - ConnectionCredentials credentials = new ConnectionCredentials("simpagamebot", Secrets.bot_access_token); - client = new Client(); - client.Initialize(credentials, channel_name); + ConnectionCredentials credentials = new ConnectionCredentials(BotName, Secrets.BotAccessToken); + Client = new Client(); + Client.Initialize(credentials, ChannelName); //pubSub = new PubSub(); //connect bot to channel - client.Connect(); - client.OnJoinedChannel += ClientOnJoinedChannel; - client.OnMessageReceived += MyMessageReceivedFunction; - client.OnChatCommandReceived += MyCommandReceivedFunction; - client.OnWhisperSent += Client_OnWhisperSent; - client.OnWhisperReceived += Client_OnWhisperReceived; - + Client.Connect(); + Client.OnJoinedChannel += ClientOnJoinedChannel; + Client.OnMessageReceived += MyMessageReceivedFunction; + Client.OnChatCommandReceived += MyCommandReceivedFunction; + Client.OnWhisperSent += Client_OnWhisperSent; + Client.OnWhisperReceived += Client_OnWhisperReceived; + //pubSub.OnChannelCommerceReceived += Pubsub_OnCommerceReceived; //client.On will fill in with telesence @@ -53,49 +48,49 @@ void Start() private void Client_OnWhisperSent(object sender, OnWhisperSentArgs e) { - Debug.Log(sender.ToString()); - Debug.Log(e.Receiver); + UnityEngine.Debug.Log(sender.ToString()); + UnityEngine.Debug.Log(e.Receiver); } private void ClientOnJoinedChannel(object sender, OnJoinedChannelArgs e) { - joinedChannel = new JoinedChannel(channel_name); - botChannel = new JoinedChannel(bot_name); + JoinedChannel = new JoinedChannel(ChannelName); + BotChannel = new JoinedChannel(BotName); //client.SendMessage(joinedChannel, "SimpaGameBotConnected"); } private void MyCommandReceivedFunction(object sender, OnChatCommandReceivedArgs e) { - Arrrgs chatArgs = new Arrrgs(); - chatArgs.message = e.Command.ChatMessage.Message; - chatArgs.userID = e.Command.ChatMessage.UserId; - chatArgs.displayName = e.Command.ChatMessage.DisplayName; - chatArgs.commandText = e.Command.CommandText.ToLower(); - chatArgs.multiCommand = e.Command.ArgumentsAsList; - + CommandEventArgs chatArgs = new CommandEventArgs(); + chatArgs.Message = e.Command.ChatMessage.Message; + chatArgs.UserID = e.Command.ChatMessage.UserId; + chatArgs.DisplayName = e.Command.ChatMessage.DisplayName; + chatArgs.CommandText = e.Command.CommandText.ToLower(); + chatArgs.MultiCommand = e.Command.ArgumentsAsList; + for (int index = 0; index < e.Command.ArgumentsAsList.Count; index++) { - chatArgs.commandArgs += e.Command.ArgumentsAsList[index].ToLower(); + chatArgs.CommandArgs += e.Command.ArgumentsAsList[index].ToLower(); } - commandQueue.FirstCommandBuckets(chatArgs); //e - debug.text = (e.Command.ChatMessage.Username); + CommandQueue.FirstCommandBuckets(chatArgs); //e + Debug.text = (e.Command.ChatMessage.Username); } private void MyMessageReceivedFunction(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e) { - Debug.Log(e.ChatMessage.UserId); + UnityEngine.Debug.Log(e.ChatMessage.UserId); } private void Client_OnWhisperReceived(object sender, OnWhisperReceivedArgs e) { - Arrrgs chatArgs = new Arrrgs(); - chatArgs.message = e.WhisperMessage.Message; - chatArgs.userID = e.WhisperMessage.UserId; - chatArgs.displayName = e.WhisperMessage.DisplayName; - chatArgs.commandText = ConvertWhisperToCommand(e.WhisperMessage.Message); - chatArgs.commandArgs = ConvertWhisperToArguments(e.WhisperMessage.Message); - commandQueue.FirstCommandBuckets(chatArgs); + CommandEventArgs chatArgs = new CommandEventArgs(); + chatArgs.Message = e.WhisperMessage.Message; + chatArgs.UserID = e.WhisperMessage.UserId; + chatArgs.DisplayName = e.WhisperMessage.DisplayName; + chatArgs.CommandText = ConvertWhisperToCommand(e.WhisperMessage.Message); + chatArgs.CommandArgs = ConvertWhisperToArguments(e.WhisperMessage.Message); + CommandQueue.FirstCommandBuckets(chatArgs); } private string ConvertWhisperToCommand(string whisper) { @@ -106,16 +101,16 @@ private string ConvertWhisperToCommand(string whisper) else { - whisper = whisper.Substring(1); - string[] commandArray = whisper.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - return (commandArray[0].ToLower()); + whisper = whisper.Substring(1); + string[] commandArray = whisper.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + return (commandArray[0].ToLower()); } } - + private string ConvertWhisperToArguments(string whisper) { - string commands = ""; + string commands = ""; if (string.IsNullOrEmpty(whisper)) { return whisper; @@ -123,19 +118,19 @@ private string ConvertWhisperToArguments(string whisper) else { - whisper = whisper.Substring(1); - string[] commandArray = whisper.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - Debug.Log(commandArray[0]); - if (commandArray.Length > 1) + whisper = whisper.Substring(1); + string[] commandArray = whisper.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + UnityEngine.Debug.Log(commandArray[0]); + if (commandArray.Length > 1) + { + for (int i = 1; i < commandArray.Length; i++) { - for (int i = 1; i < commandArray.Length; i++) - { - commands += commandArray[i]; - } + commands += commandArray[i]; } - commands = commands.ToLower(); - return (commands); - + } + commands = commands.ToLower(); + return (commands); + } } private List ParseCommand(string command) @@ -148,8 +143,8 @@ private List ParseCommand(string command) } for (int i = 0; i < commandArray.Length; i++) { - Debug.Log(commandArray.Length + " : this is command Array Length"); - Debug.Log(commandArray[i] + " : this is command Array"); + UnityEngine.Debug.Log(commandArray.Length + " : this is command Array Length"); + UnityEngine.Debug.Log(commandArray[i] + " : this is command Array"); } return null; } diff --git a/Assets/Secrets/Secrets.cs b/Assets/Secrets/Secrets.cs index c6d9656..c8e996e 100644 --- a/Assets/Secrets/Secrets.cs +++ b/Assets/Secrets/Secrets.cs @@ -5,36 +5,20 @@ public static class Secrets { - public static string client_id; - public static string client_secret; - public static string bot_access_token; - public static string bot_refresh_token; //hai - public static void EnvironmentVariables() - { - client_id = Environment.GetEnvironmentVariable("client_id"); - client_secret = Environment.GetEnvironmentVariable("client_secret"); - bot_access_token = Environment.GetEnvironmentVariable("bot_access_token"); - bot_refresh_token = Environment.GetEnvironmentVariable("bot_refresh_token"); - /* - string value; - bool toDelete = false; - - // Check whether the environment variable exists. - value = Environment.GetEnvironmentVariable("client_id"); - // If necessary, create it. - if (value == null) - { - Environment.SetEnvironmentVariable("client_id", ""); - Environment.SetEnvironmentVariable("client_secret", ""); - Environment.SetEnvironmentVariable("bot_access_token", ""); - Environment.SetEnvironmentVariable("bot_refresh_token", ""); - toDelete = true; + public static string ClientID { get; } = GetVariable("client_id"); + public static string ClientSecret { get; } = GetVariable("client_secret"); + public static string BotAccessToken { get; } = GetVariable("bot_access_token"); + public static string BotRefreshToken { get; } = GetVariable("bot_refresh_token"); //hai - // Now retrieve it. - client_id = Environment.GetEnvironmentVariable("client_id"); - client_secret = Environment.GetEnvironmentVariable("client_secret"); - bot_access_token = Environment.GetEnvironmentVariable("bot_access_token"); - bot_refresh_token = Environment.GetEnvironmentVariable("bot_refresh_token"); - */ + /// Gets the environment variable at any target level. + /// Attempts to get the environment variable in the order process-wide, user-wide, and finally machine-wide. + /// The name of the environment variable + /// Returns the value of environment variable or null if not found at any level + public static string GetVariable(string name) + { + return Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process) ?? + Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.User) ?? + Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Machine); } + }