Esempio n. 1
0
        public virtual void SavePresets(SaveType saveType)
        {
            if (presets == null || presets.Count <= 0)
            {
                Debug.LogError(
                    "presets cannot be null or empty: " + (presets == null ? "NULL" : "EMPTY"));
                return;
            }

            var jsonColor = new JsonColor();

            jsonColor.SetColors(presets.ToArray());


            string jsonData = JsonUtility.ToJson(jsonColor);

            switch (saveType)
            {
            case SaveType.None:
                Debug.LogWarning("Called SavePresets with SaveType = None...");
                break;

            case SaveType.PlayerPrefs:
                PlayerPrefs.SetString(playerPrefsKey, jsonData);
                break;

            case SaveType.JsonFile:
                System.IO.File.WriteAllText(JsonFilePath, jsonData);
                //Application.OpenURL(JsonFilePath);
                break;

            default:
                throw new System.NotImplementedException(saveType.ToString());
            }
        }
        private void LoadData()
        {
            data = Json.GetOrCreate(file, new Data());

            Mod.Instance.Logger.Info("Loading data");
            splineColors = new Dictionary <string, Color>();
            keyRegexList = new Dictionary <Regex, Color>();

            // Making sure colors that copy from other are set properly
            HashSet <string> toRemove = new HashSet <string>();
            Dictionary <string, JsonColor> rewrite = new Dictionary <string, JsonColor>();

            foreach (var item in data.spline_colors)
            {
                JsonColor color = item.Value;

                if (string.Equals(color.type, JsonColor.TYPE_COPY, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (data.spline_colors.ContainsKey(color.from))
                    {
                        rewrite.Add(item.Key, data.spline_colors[color.from]);
                    }
                    else
                    {
                        toRemove.Add(item.Key);
                    }
                }
            }

            toRemove.Do(key => data.spline_colors.Remove(key));

            foreach (var item in rewrite)
            {
                data.spline_colors.Remove(item.Key);
                data.spline_colors.Add(item.Key, item.Value);
            }

            foreach (var item in data.spline_colors)
            {
                try
                {
                    string[] subSplines = item.Key.Split(ITEM_DELIMITER);
                    Array.Sort(subSplines);

                    string lcaseKey = string.Join(string.Empty, subSplines).ToLower();

                    Color color = item.Value;
                    splineColors.Add(lcaseKey, color);
                    keyRegexList.Add(new Regex(item.Key), color);

                    Mod.Instance.Logger.Info($"{item.Key} ({ColorEx.ColorToHexUnity(color)})");
                }
                catch (Exception e)
                {
                    Mod.Instance.Logger.Exception(e);
                    Mod.Instance.Logger.Error($"Could not read color data for spline_color \"{item.Key}\"");
                }
            }
        }
 // GET api/Color
 public IQueryable<JsonColor> GetColors()
 {
     IQueryable<Color> colors = ent.Colors.AsQueryable();
     List<JsonColor> jsonColors = new List<JsonColor>();
     foreach (var color in colors)
     {
         JsonColor jsonColor = new JsonColor();
         jsonColor.color = ent.Colors.FirstOrDefault(p => p.Id == color.Id).Name;
         jsonColor.id = color.Id;
         jsonColors.Add(jsonColor);
     }
     return jsonColors.AsQueryable();
 }
Esempio n. 4
0
        // GET api/Color
        public IQueryable <JsonColor> GetColors()
        {
            IQueryable <Color> colors     = ent.Colors.AsQueryable();
            List <JsonColor>   jsonColors = new List <JsonColor>();

            foreach (var color in colors)
            {
                JsonColor jsonColor = new JsonColor();
                jsonColor.color = ent.Colors.FirstOrDefault(p => p.Id == color.Id).Name;
                jsonColor.id    = color.Id;
                jsonColors.Add(jsonColor);
            }
            return(jsonColors.AsQueryable());
        }