IEnumerator UploadGamePieceInServer(ListOfStringsVariable gamePiecesList, int index) { JsonGamePieceDataUpdate gamePieceData = new JsonGamePieceDataUpdate(); gamePieceData.game_meta = new JsonGamePieceData(); Debug.Log("index : " + index); gamePieceData.game_meta.model = gamePiecesList.Value[index]; string jsonData = gamePieceData.SaveToString(); var request = UnityWebRequest.Put("https://echoes.etc.cmu.edu/api/users/info/", jsonData); request.SetRequestHeader("Authorization", "Bearer " + PlayerPrefs.GetString("token")); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { Debug.Log("Request error"); Debug.Log(request.error); Debug.Log(request.downloadHandler.text); yield break; } Debug.Log("success"); }
/// <summary> /// Adds a single or list variable with the given value. /// </summary> protected static void InsertVariable(LSGlobals ls, bool isCapture, bool recursive, IEnumerable <string> values, string variableName, string prefix = "", string suffix = "", bool urlEncode = false, bool createEmpty = true) { var data = ls.BotData; var list = values.Select(v => ReplaceValues(prefix, ls) + v.Trim() + ReplaceValues(suffix, ls)).ToList(); if (urlEncode) { list = list.Select(v => Uri.EscapeDataString(v)).ToList(); } Variable variable = null; if (recursive) { if (list.Count > 0 || createEmpty) { variable = new ListOfStringsVariable(list) { Name = variableName }; } } else { if (list.Count == 0) { if (createEmpty) { variable = new StringVariable(string.Empty) { Name = variableName }; } } else { variable = new StringVariable(list.First()) { Name = variableName }; } } if (variable != null) { GetVariables(data).Set(variable); data.Logger.Log($"Parsed variable | Name: {variable.Name} | Value: {variable.AsString()}", isCapture ? LogColors.OrangeRed : LogColors.Gold); variable.MarkedForCapture = isCapture; } else { data.Logger.Log("Could not parse any data. The variable was not created.", LogColors.White); } }
public void GamepieceUpdate(ListOfStringsVariable gamePiecesList, int index) { StartCoroutine(UploadGamePieceInServer(gamePiecesList, index)); }
/// <inheritdoc /> public override async Task Process(LSGlobals ls) { var data = ls.BotData; await base.Process(ls); var replacedInput = ReplaceValues(InputString, ls); var variablesList = GetVariables(data); Variable variableToAdd = null; var logColor = IsCapture ? LogColors.Tomato : LogColors.Yellow; switch (Group) { case UtilityGroup.List: var list = variablesList.Get <ListOfStringsVariable>(ListName)?.AsListOfStrings(); var list2 = variablesList.Get <ListOfStringsVariable>(SecondListName)?.AsListOfStrings(); var item = ReplaceValues(ListItem, ls); var index = int.Parse(ReplaceValues(ListIndex, ls)); switch (ListAction) { case ListAction.Create: variableToAdd = new ListOfStringsVariable(new List <string>()); break; case ListAction.Length: variableToAdd = new StringVariable(list.Count.ToString()); break; case ListAction.Join: variableToAdd = new StringVariable(string.Join(Separator, list)); break; case ListAction.Sort: var sorted = list.Select(e => e).ToList(); // Clone the list so we don't edit the original one if (Numeric) { var nums = sorted.Select(e => double.Parse(e, CultureInfo.InvariantCulture)).ToList(); nums.Sort(); sorted = nums.Select(e => e.ToString()).ToList(); } else { sorted.Sort(); } if (!Ascending) { sorted.Reverse(); } variableToAdd = new ListOfStringsVariable(sorted); break; case ListAction.Concat: variableToAdd = new ListOfStringsVariable(list.Concat(list2).ToList()); break; case ListAction.Zip: variableToAdd = new ListOfStringsVariable(list.Zip(list2, (a, b) => a + b).ToList()); break; case ListAction.Map: variableToAdd = new DictionaryOfStringsVariable(list.Zip(list2, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v)); break; case ListAction.Add: // Handle negative indices index = index switch { 0 => 0, < 0 => index + list.Count, _ => index }; list.Insert(index, item); break; case ListAction.Remove: // Handle negative indices index = index switch { 0 => 0, < 0 => index + list.Count, _ => index }; list.RemoveAt(index); break; case ListAction.RemoveValues: variableToAdd = new ListOfStringsVariable(list.Where(l => !Condition.Verify(new KeycheckCondition { Left = ReplaceValues(l, ls), Comparer = ListElementComparer, Right = ListComparisonTerm })).ToList()); break; case ListAction.RemoveDuplicates: variableToAdd = new ListOfStringsVariable(list.Distinct().ToList()); break; case ListAction.Random: variableToAdd = new StringVariable(list[data.Random.Next(list.Count)]); break; case ListAction.Shuffle: // This makes a copy of the original list var listCopy = new List <string>(list); listCopy.Shuffle(data.Random); variableToAdd = new ListOfStringsVariable(listCopy); break; default: break; } data.Logger.Log($"Executed action {ListAction} on list {ListName}", logColor); break; case UtilityGroup.Variable: string single = variablesList.Get <StringVariable>(VarName).AsString(); switch (VarAction) { case VarAction.Split: variableToAdd = new ListOfStringsVariable(single.Split(new string[] { ReplaceValues(SplitSeparator, ls) }, StringSplitOptions.None).ToList()); break; } data.Logger.Log($"Executed action {VarAction} on variable {VarName}", logColor); break; case UtilityGroup.Conversion: var conversionInputBytes = replacedInput.ConvertFrom(ConversionFrom); var conversionResult = conversionInputBytes.ConvertTo(ConversionTo); variableToAdd = new StringVariable(conversionResult); data.Logger.Log($"Executed conversion {ConversionFrom} to {ConversionTo} on input {replacedInput} with outcome {conversionResult}", logColor); break; case UtilityGroup.File: var file = ReplaceValues(FilePath, ls); FileUtils.ThrowIfNotInCWD(file); switch (FileAction) { case FileAction.Exists: variableToAdd = new StringVariable(File.Exists(file).ToString()); break; case FileAction.Read: lock (FileLocker.GetHandle(file)) variableToAdd = new StringVariable(File.ReadAllText(file)); break; case FileAction.ReadLines: lock (FileLocker.GetHandle(file)) variableToAdd = new ListOfStringsVariable(File.ReadAllLines(file).ToList()); break; case FileAction.Write: FileUtils.CreatePath(file); lock (FileLocker.GetHandle(file)) File.WriteAllText(file, replacedInput.Unescape()); break; case FileAction.WriteLines: FileUtils.CreatePath(file); lock (FileLocker.GetHandle(file)) File.WriteAllLines(file, ReplaceValuesRecursive(InputString, ls).Select(i => i.Unescape())); break; case FileAction.Append: FileUtils.CreatePath(file); lock (FileLocker.GetHandle(file)) File.AppendAllText(file, replacedInput.Unescape()); break; case FileAction.AppendLines: FileUtils.CreatePath(file); lock (FileLocker.GetHandle(file)) File.AppendAllLines(file, ReplaceValuesRecursive(InputString, ls).Select(i => i.Unescape())); break; case FileAction.Copy: var fileCopyLocation = ReplaceValues(InputString, ls); FileUtils.ThrowIfNotInCWD(fileCopyLocation); FileUtils.CreatePath(fileCopyLocation); lock (FileLocker.GetHandle(file)) lock (FileLocker.GetHandle(fileCopyLocation)) File.Copy(file, fileCopyLocation); break; case FileAction.Move: var fileMoveLocation = ReplaceValues(InputString, ls); FileUtils.ThrowIfNotInCWD(fileMoveLocation); FileUtils.CreatePath(fileMoveLocation); lock (FileLocker.GetHandle(file)) lock (FileLocker.GetHandle(fileMoveLocation)) File.Move(file, fileMoveLocation); break; case FileAction.Delete: // No deletion if the file is in use (DB/OpenBullet.db cannot be deleted but instead DB/OpenBullet-BackupCopy.db) // If another process is just reading the file it will be deleted lock (FileLocker.GetHandle(file)) File.Delete(file); break; } data.Logger.Log($"Executed action {FileAction} on file {file}", logColor); break; case UtilityGroup.Folder: var folder = ReplaceValues(FolderPath, ls); FileUtils.ThrowIfNotInCWD(folder); switch (FolderAction) { case FolderAction.Exists: variableToAdd = new StringVariable(Directory.Exists(folder).ToString()); break; case FolderAction.Create: variableToAdd = new StringVariable(Directory.CreateDirectory(folder).ToString()); break; case FolderAction.Delete: Directory.Delete(folder, true); break; } data.Logger.Log($"Executed action {FolderAction} on folder {folder}", logColor); break; default: break; } if (variableToAdd is not null) { variableToAdd.Name = VariableName; variableToAdd.MarkedForCapture = IsCapture; variablesList.Set(variableToAdd); } }