Beispiel #1
0
 public void Merge(ModdingData mod, string dirName)
 {
     if (mod == null)
     {
         return;
     }
     if (mod.imageData != null)
     {
         mod.imageData.ForEach(id =>
         {
             if (!id.imageLink.ToLower().StartsWith("http"))
             {
                 id.imageLink = dirName + "/" + id.imageLink;
             }
         });
         if (imageData == null)
         {
             imageData = mod.imageData;
         }
         else
         {
             imageData.AddRange(mod.imageData);
         }
     }
     imageOrder  = mod.imageOrder;
     imageFilter = mod.imageFilter;
 }
Beispiel #2
0
        public static void CreateImageList()
        {
            string path = EditorUtility.OpenFolderPanel("Select Image Folder", "", "");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            // read existing mod file if existent
            ModdingData md      = new ModdingData();
            string      modFile = path + "/" + SDKUtil.MODFILE_NAME;

            if (File.Exists(modFile))
            {
                md = SDKUtil.ReadJSONFileDirect <ModdingData>(modFile);
            }
            if (md.imageData == null)
            {
                md.imageData = new List <ImageData>();
            }

            // gather images
            IEnumerable <string> files = DirectoryUtil.GetFiles(path, new[] { "*.png", "*.jpg" });

            foreach (string file in files)
            {
                string fileName = Path.GetFileName(file);
                if (md.imageData.Any(id => id.imageLink == fileName))
                {
                    continue;
                }

                string name = Path.GetFileNameWithoutExtension(fileName);
                if (DateTime.TryParseExact(SDKUtil.MaxLength(name, 19), "yyyy-MM-dd HH.mm.ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime))
                {
                    name = dateTime.ToLongDateString() + " " + dateTime.ToShortTimeString();
                }
                md.imageData.Add(new ImageData(fileName, name));
            }

            File.WriteAllText(modFile, SDKUtil.SerializeObject(md));

            EditorUtility.DisplayDialog("Done", $"Found {md.imageData.Count} images. Check modding.json in target folder.", "OK");
        }