using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using TMPro; using UnityEngine; using Random = UnityEngine.Random; // WTF, C# is awesome! Fuck Python public class CharecterCreationManager : MonoBehaviour { // Yes, I am using a vector to store RGB values. You can't stop me! public Vector3 SelectedColor; // RGB GameObjects [SerializeField] private TMP_InputField[] RGB_GOs; public SpriteRenderer charecterPreview; private void OnEnable() { SelectedColor = new Vector3(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256)); for (int i = 0; i < 3; i++) { RGB_GOs[i].text = SelectedColor[i].ToString(); } RerenderCharecterPreview(); } public void TextChange(string rawType) { Enum.TryParse(rawType, out RGBType type); // Unity events compatible FilterInputs(type); SelectedColor[(int)type] = Convert.ToByte(RGB_GOs[(int)type].text); RerenderCharecterPreview(); } void RerenderCharecterPreview() { charecterPreview.color = new Color(SelectedColor.x / 255, SelectedColor.y / 255, SelectedColor.z / 255); } // Cry about it public void FilterInputs(RGBType type) => RGB_GOs[(int)type].text = (Convert.ToInt16(RGB_GOs[(int)type].text) < 0) ? Math.Abs(Convert.ToInt16(RGB_GOs[(int)type].text)).ToString() : RGB_GOs[(int)type].text; public void SubmitAndStart() { var charecter = new Charecter(); charecter.x = (int)SelectedColor.x; charecter.y = (int)SelectedColor.y; charecter.z = (int)SelectedColor.z; if (!Directory.Exists(JsonManager.JsonDir)) { Directory.CreateDirectory(JsonManager.JsonDir); } string territoryPath = Path.Combine(JsonManager.JsonDir, $"Cry about it. Im marking this part of your computer as my territory"); if (!File.Exists(territoryPath)) { File.WriteAllText(territoryPath, "Why you traspassing on my property?!!?"); string savePath = Path.Combine(JsonManager.JsonDir, $"Save_{JsonManager.SelectedSave}.json"); string json = JsonConvert.SerializeObject(charecter); File.WriteAllText(savePath, json); AppManager.LoadScene(1); } } } public enum RGBType { R, G, B }