/// <summary> /// This method is used to build the sprites of the JS game. /// </summary> /// <returns>Returns them as a string.</returns> public static string BuildSprites(string TargetPath) { string _i = File.ReadAllText(LibraryPath + @"\sprites.js"); _i = PreprocessorReplacer(_i, PreprocessorTags, PreprocessorValues); string _d = _i.Substring(0, _i.IndexOf("#FOREACH Sprite")); foreach (Sprite sprite in Sprites.sprites) { if (sprite != null && sprite.path != null) { DirectoryExtension.Copy(GameConfig.path + @"\Resources\IMG\spr" + sprite.id, TargetPath + @"\IMG\spr" + sprite.id, false); int _fsi = _i.IndexOf("#FOREACH Sprite") + 15; _d += PreprocessorReplacer(_i.Substring(_fsi, _i.IndexOf("#FOREACH Frame") - _fsi), new string[] { "$spriteId" }, new string[] { sprite.id.ToString() }); for (int i = 0; i < sprite.path.Length; i++) { int _ffi = _i.IndexOf("#FOREACH Frame", _fsi) + 14; _d += PreprocessorReplacer(_i.Substring(_ffi, _i.IndexOf("#END") - _ffi), new string[] { "$spriteId", "$frameId", "$framePath" }, new string[] { sprite.id.ToString(), i.ToString(), "'IMG/spr" + sprite.id + "/" + i + Path.GetExtension(sprite.path[i]) + "'" }); } _fsi = _i.IndexOf("#END", _fsi) + 4; _d += PreprocessorReplacer(_i.Substring(_fsi, _i.IndexOf("#END", _fsi) - _fsi), new string[] { "$spriteId" }, new string[] { sprite.id.ToString() }); } } int _le = _i.LastIndexOf("#END") + 4; _d += _i.Substring(_le, _i.Length - _le); return(_d.Trim()); }
public static void Build() { Find(); if (!string.IsNullOrWhiteSpace(Path) && File.Exists(Path)) { using (LoadingForm buildForm = new LoadingForm("Build in progress: ", "%")) { Thread buildThread = new Thread(() => { int steps = 10; try { Directory.Delete(GameConfig.path + @"\Build\Win", true); } catch { } LoadingForm.ProgressStep(steps, buildForm); if (Builder.Build(true, GameConfig.path + @"\Build\Win\Resources")) { try { LoadingForm.ProgressStep(steps, buildForm); string SDKPath = Application.StartupPath + @"\SDK"; //Meta information string temp = File.ReadAllText(SDKPath + @"\JSGameIDE-Player\Properties\AssemblyInfo.cs"); temp = MetaInfoChanger(temp, "[assembly: AssemblyTitle(\"", "\")]", GameConfig.name); temp = MetaInfoChanger(temp, "[assembly: AssemblyDescription(\"", "\")]", GameConfig.name); temp = MetaInfoChanger(temp, "[assembly: AssemblyProduct(\"", "\")]", GameConfig.name); temp = MetaInfoChanger(temp, "[assembly: AssemblyCompany(\"", "\")]", GameConfig.author); temp = MetaInfoChanger(temp, "[assembly: AssemblyCopyright(\"", "\")]", GameConfig.copyright); LoadingForm.ProgressStep(steps, buildForm); //Copy the icon try { File.Copy(GameConfig.path + @"\Resources\icon.ico", SDKPath + @"\JSGameIDE-Player\icon.ico", true); } catch { } LoadingForm.ProgressStep(steps, buildForm); using (StreamWriter w = new StreamWriter(SDKPath + @"\JSGameIDE-Player\Properties\AssemblyInfo.cs")) { w.Write(temp); } LoadingForm.ProgressStep(steps, buildForm); System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(); info.FileName = Path; info.Arguments = @"/p:Platform=x86 JSGameIDE-Player.sln"; info.WorkingDirectory = SDKPath; info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); process.WaitForExit(); LoadingForm.ProgressStep(steps, buildForm); DirectoryExtension.Copy(SDKPath + @"\JSGameIDE-Player\bin\x86\Debug", GameConfig.path + @"\Build\Win", true); LoadingForm.ProgressStep(steps, buildForm); //Cleans some trash File.Delete(GameConfig.path + @"\Build\Win\JSGameIDE-Player.exe.config"); File.Delete(GameConfig.path + @"\Build\Win\JSGameIDE-Player.pdb"); File.Delete(GameConfig.path + @"\Build\Win\CefSharp.Core.xml"); File.Delete(GameConfig.path + @"\Build\Win\CefSharp.WinForms.xml"); File.Delete(GameConfig.path + @"\Build\Win\CefSharp.xml"); File.Delete(GameConfig.path + @"\Build\Win\devtools_resources.pak"); LoadingForm.ProgressStep(steps, buildForm); try { File.Move(GameConfig.path + @"\Build\Win\JSGameIDE-Player.exe", GameConfig.path + @"\Build\Win\" + GameConfig.name.Replace(' ', '-') + ".exe"); } catch { } LoadingForm.ProgressStep(steps, buildForm); Directory.Delete(SDKPath + @"\JSGameIDE-Player\bin\x86", true); LoadingForm.ProgressStep(steps, buildForm); Thread.Sleep(200); buildForm.SafeClose(); SystemSounds.Beep.Play(); MessageBox.Show("Build success", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { buildForm.SafeClose(); SystemSounds.Exclamation.Play(); MessageBox.Show("Build failure", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { buildForm.SafeClose(); SystemSounds.Exclamation.Play(); MessageBox.Show("Build failure", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); buildThread.Start(); buildForm.ShowDialog(); } } else { SystemSounds.Asterisk.Play(); MessageBox.Show("Build failure. Please ensure that the SDK is properly installed.", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error); } }