コード例 #1
0
        public static void RunPVRTexTool(Bitmap bitmap, AssetBundle bundle, string path, AssetAttributes attributes, bool mipMaps, bool highQualityCompression,
                                         PVRFormat pvrFormat, byte[] CookingRulesSHA1, DateTime time)
        {
            int  width     = bitmap.Width;
            int  height    = bitmap.Height;
            bool hasAlpha  = bitmap.HasAlpha;
            int  potWidth  = TextureConverterUtils.GetNearestPowerOf2(width, 8, 2048);
            int  potHeight = TextureConverterUtils.GetNearestPowerOf2(height, 8, 2048);
            var  args      = new StringBuilder();

            switch (pvrFormat)
            {
            case PVRFormat.PVRTC4:
                if (!hasAlpha)
                {
                    args.Append(" -f PVRTC1_2");
                }
                else
                {
                    args.Append(" -f PVRTC1_4");
                }
                width = height = Math.Max(potWidth, potHeight);
                break;

            case PVRFormat.PVRTC4_Forced:
                args.Append(" -f PVRTC1_4");
                width = height = Math.Max(potWidth, potHeight);
                break;

            case PVRFormat.PVRTC2:
                args.Append(" -f PVRTC1_2");
                width = height = Math.Max(potWidth, potHeight);
                break;

            case PVRFormat.ETC2:
                args.Append(" -f ETC1 -q etcfast");
                break;

            case PVRFormat.RGB565:
                if (hasAlpha)
                {
                    Console.WriteLine("WARNING: texture has alpha channel. " +
                                      "Used 'RGBA4444' format instead of 'RGB565'.");
                    args.Append(" -f r4g4b4a4 -dither");
                }
                else
                {
                    args.Append(" -f r5g6b5");
                }
                break;

            case PVRFormat.RGBA4:
                args.Append(" -f r4g4b4a4 -dither");
                break;

            case PVRFormat.ARGB8:
                args.Append(" -f r8g8b8a8");
                break;
            }
            if (highQualityCompression && (new[] { PVRFormat.PVRTC2, PVRFormat.PVRTC4, PVRFormat.PVRTC4_Forced }.Contains(pvrFormat)))
            {
                args.Append(" -q pvrtcbest");
            }
            Bitmap bledBitmap = null;

            if (bitmap.HasAlpha)
            {
                bledBitmap = TextureConverterUtils.BleedAlpha(bitmap);
            }
            if (mipMaps)
            {
                args.Append(" -m");
            }
            args.AppendFormat(" -r {0},{1} -shh", width, height);
            var hashString = GetTextureHashString(bledBitmap ?? bitmap, ".pvr", args.ToString());
            var cachePath  = AssetCache.Instance.Load(hashString);

            if (cachePath != null)
            {
                bundle.ImportFile(cachePath, path, 0, "", attributes, time, CookingRulesSHA1);
                return;
            }
            var pvrPath = Toolbox.GetTempFilePathWithExtension(".pvr");
            var tgaPath = Path.ChangeExtension(pvrPath, ".tga");

            try {
                TextureConverterUtils.SaveToTGA(bledBitmap ?? bitmap, tgaPath, swapRedAndBlue: true);
                if (bledBitmap != null && bledBitmap != bitmap)
                {
                    bledBitmap.Dispose();
                }
                args.AppendFormat(" -i \"{0}\" -o \"{1}\"", tgaPath, pvrPath);
#if MAC
                var pvrTexTool = GetToolPath("PVRTexTool");
#else
                var pvrTexTool = GetToolPath("PVRTexToolCli");
#endif
                if (Process.Start(pvrTexTool, args.ToString()) != 0)
                {
                    throw new Lime.Exception($"PVRTextTool error\nCommand line: {pvrTexTool} {args}\"");
                }
                bundle.ImportFile(pvrPath, path, 0, "", attributes, time, CookingRulesSHA1);
                AssetCache.Instance.Save(pvrPath, hashString);
            } finally {
                DeletePossibleLockedFile(tgaPath);
                DeletePossibleLockedFile(pvrPath);
            }
        }
コード例 #2
0
 public static void Save(CitrusVersion citrusVersion)
 {
     using (var stream = File.Open(Path.Combine(Toolbox.FindCitrusDirectory(), Filename), FileMode.Open)) {
         Save(citrusVersion, stream);
     }
 }
コード例 #3
0
ファイル: NewProject.cs プロジェクト: aologos/Citrus
        public static void NewProjectAction(Func <string, bool> projectOpened)
        {
            Application.InvokeOnMainThread(() => {
                var citrusPath = Toolbox.CalcCitrusDirectory();
                var dlg        = new FileDialog {
                    AllowedFileTypes = new string[] { "" },
                    Mode             = FileDialogMode.SelectFolder
                };
                if (dlg.RunModal())
                {
                    targetDirectory    = dlg.FileName;
                    newCitrusDirectory = Path.Combine(dlg.FileName, "Citrus");
                    var projectName    = Path.GetFileName(dlg.FileName);
                    if (char.IsDigit(projectName[0]))
                    {
                        throw new System.Exception($"Project name '{projectName}' cannot start with a digit");
                    }
                    foreach (char c in projectName)
                    {
                        if (!ValidChars.Contains(c))
                        {
                            throw new System.Exception($"Project name '{projectName}' must contain only latin letters and digits");
                        }
                    }
                    var newProjectApplicationName = String.Join(" ", Regex.Split(projectName, @"(?<!^)(?=[A-Z])"));
                    Console.WriteLine($"New project name is \"{projectName}\"");
                    HashSet <string> textfileExtensions = new HashSet <string> {
                        ".cs", ".xml", ".csproj", ".sln", ".citproj", ".projitems", ".shproj", ".txt", ".plist", ".strings", ".gitignore",
                    };
                    using (var dc = new DirectoryChanger($"{citrusPath}/Samples/EmptyProject/")) {
                        var fe = new FileEnumerator(".");
                        foreach (var f in fe.Enumerate())
                        {
                            var targetPath = Path.Combine(dlg.FileName, f.Path.Replace("EmptyProject", projectName));
                            Console.WriteLine($"Copying: {f.Path} => {targetPath}");
                            Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                            System.IO.File.Copy(f.Path, targetPath);
                            if (textfileExtensions.Contains(Path.GetExtension(targetPath).ToLower(CultureInfo.InvariantCulture)))
                            {
                                string text     = File.ReadAllText(targetPath);
                                text            = text.Replace("EmptyProject", projectName);
                                text            = text.Replace("Empty Project", newProjectApplicationName);
                                text            = text.Replace("emptyproject", projectName.ToLower());
                                var citrusUri   = new Uri(newCitrusDirectory);
                                var fileUri     = new Uri(targetPath);
                                var relativeUri = fileUri.MakeRelativeUri(citrusUri);
                                // TODO: apply only to .sln and .csproj file
                                text = text.Replace("..\\..\\..", relativeUri.ToString());
                                if (targetPath.EndsWith(".citproj", StringComparison.OrdinalIgnoreCase))
                                {
                                    text = text.Replace("CitrusLocation: \"..\",", $"CitrusLocation: \"{relativeUri}\",");
                                    newProjectCitprojPath = targetPath;
                                }
                                File.WriteAllText(targetPath, text);
                            }
                        }
                    }
#if WIN
// TODO: fix unresponsiveness on mac
                    Git("init");
                    Git("add -A");
                    Git("submodule add https://gitlab.game-forest.com:8888/Common/Citrus.git Citrus");
                    Git("submodule update --init --recursive");
                    Git("commit -m\"Initial commit.\"");
#endif // WIN
                }
            });
            if (projectOpened != null)
            {
                projectOpened?.Invoke(newProjectCitprojPath);
            }
        }
コード例 #4
0
 public static CitrusVersion Load()
 {
     using (var stream = File.Open(Path.Combine(Toolbox.FindCitrusDirectory(), Filename), FileMode.Open)) {
         return(Load(stream));
     }
 }
コード例 #5
0
ファイル: ConsoleUI.cs プロジェクト: klenin/Citrus
 public override bool DoesNeedSvnUpdate()
 {
     return(Toolbox.GetCommandLineFlag("--autoupdate"));
 }