private void SerializeControllerChip(IControllerChip controllerChip) { if (controllerChip.export == false) { return; } JsonUtil.GetLineBreak(sb); sb.Append("\"ControllerChip\":"); JsonUtil.GetLineBreak(sb); sb.Append("{"); JsonUtil.GetLineBreak(sb); sb.Append("}"); sb.Append(","); currentStep++; }
/// <summary> /// This mthod manually loads the game file's binary data then configures the engine and processes the files. /// </summary> private void LoadDefaultGame() { // Create a list of valid files we want to load from the game directory string[] fileExtensions = { "lua", "png", "json" }; // Create a new list to store the file paths var gameFiles = new List <string>(); // Get only the files we need from the directory base on their extension above. var files = from p in Directory.EnumerateFiles(gamePath) where fileExtensions.Any(val => p.EndsWith(val)) select p; // Loop through each file in the list foreach (var file in files) { // Read the binary data and save it along with the file name to the dictionary. gameFiles.Add(file); } // Configure a new PV8 engine to play the game ConfigureEngine(); // Manually activate the custom game chip tmpEngine.ActivateChip("GameChip", new LuaGameChip { DefaultScriptPath = "Content/code.lua" }); // Process the files ProcessFiles(tmpEngine, gameFiles.ToArray()); controllerChip = ActiveEngine.ControllerChip; }
public override void ActivateEngine(IEngine engine) { // Get a reference to the Lua game var game = engine.gameChip as LuaGameChip; // Get the script var luaScript = game.luaScript; luaScript.Globals["StartNextPreload"] = new Action(StartNextPreload); luaScript.Globals["PreloaderComplete"] = new Action(RunGame); luaScript.Globals["EnableCRT"] = (EnableCRTDelegator)EnableCRT; luaScript.Globals["Brightness"] = (BrightnessDelegator)Brightness; luaScript.Globals["Sharpness"] = (SharpnessDelegator)Sharpness; luaScript.Globals["BootDone"] = new Action <bool>(BootDone); luaScript.Globals["ReadPreloaderPercent"] = new Func <int>(() => (int)(loadService.percent * 100)); luaScript.Globals["LoadGame"] = new Func <string, Dictionary <string, string>, bool>((path, metadata) => Load(path, RunnerMode.Loading, metadata)); luaScript.Globals["SystemVersion"] = new Func <string>(() => systemVersion); luaScript.Globals["SystemName"] = new Func <string>(() => systemName); luaScript.Globals["SessionID"] = new Func <string>(() => sessionID); // Expose Bios APIs luaScript.Globals["ReadBiosData"] = new Func <string, string, string>((key, defaultValue) => bios.ReadBiosData(key, defaultValue)); luaScript.Globals["WriteBiosData"] = new Action <string, string>(bios.UpdateBiosData); // luaScript.Globals["NewWorkspacePath"] = new Func<string, WorkspacePath>(WorkspacePath.Parse); // UserData.RegisterType<WorkspacePath>(); // Save a reference to the controller chip so we can listen for special key events controllerChip = engine.controllerChip; // Activate the game base.ActivateEngine(engine); }
/// <summary> /// This mthod manually loads the game file's binary data then configures the engine and processes the files. /// </summary> private void LoadDefaultGame() { // Create a list of valid files we want to load from the game directory var fileExtensions = new[] { "lua", "png", "json" }; // Create a new dictionary to store the file binary data var gameFiles = new Dictionary <string, byte[]>(); // Get only the files we need from the directory base on their extension above. var files = from p in Directory.EnumerateFiles(gamePath) where fileExtensions.Any(val => p.EndsWith(val)) select p; // Loop through each file in the list foreach (var file in files) { // Read the binary data and save it along with the file name to the dictionary. gameFiles.Add(Path.GetFileName(file), File.ReadAllBytes(file)); } // Configure a new PV8 engine to play the game ConfigureEngine(); // Manually activate the custom game chip tmpEngine.ActivateChip("GameChip", new LuaGameChip()); // Process the files ProcessFiles(tmpEngine, gameFiles); controllerChip = activeEngine.controllerChip; }
public override void ActivateEngine(IEngine engine) { // At this point this game is fully configured so all chips are accessible for extra configuring // Save a reference to the controller chip so we can listen for special key events controllerChip = engine.controllerChip; // Get a reference to the Lua game var game = engine.gameChip as LuaGameChip; // Get the script var luaScript = game.luaScript; // Inject the PV8 runner special global function luaScript.Globals["IsExporting"] = new Func <bool>(ExportService.IsExporting); luaScript.Globals["ReadExportPercent"] = new Func <int>(ExportService.ReadExportPercent); luaScript.Globals["ReadExportMessage"] = new Func <string>(ExportService.ReadExportMessage); luaScript.Globals["ShutdownSystem"] = new Action(ShutdownSystem); luaScript.Globals["QuitCurrentTool"] = (QuitCurrentToolDelagator)QuitCurrentTool; luaScript.Globals["RefreshActionKeys"] = new Action(RefreshActionKeys); luaScript.Globals["DocumentPath"] = new Func <string>(() => documentsPath); luaScript.Globals["TmpPath"] = new Func <string>(() => tmpPath); luaScript.Globals["DiskPaths"] = new Func <WorkspacePath[]>(() => workspaceServicePlus.Disks); luaScript.Globals["SaveActiveDisks"] = new Action(() => { var disks = workspaceServicePlus.Disks; foreach (var disk in disks) { workspaceServicePlus.SaveDisk(disk); } }); luaScript.Globals["EjectDisk"] = new Action <string>(EjectDisk); luaScript.Globals["EnableAutoRun"] = new Action <bool>(EnableAutoRun); luaScript.Globals["EnableBackKey"] = new Action <bool>(EnableBackKey); luaScript.Globals["RebuildWorkspace"] = new Action(workspaceServicePlus.RebuildWorkspace); luaScript.Globals["MountDisk"] = new Action <WorkspacePath>(path => { var segments = path.GetDirectorySegments(); var systemPath = Path.PathSeparator.ToString(); if (segments[0] == "Disk") { } else if (segments[0] == "Workspace") { // TODO the workspace could have a different name so we should check the bios systemPath = Path.Combine(documentsPath, segments[0]); } for (var i = 1; i < segments.Length; i++) { systemPath = Path.Combine(systemPath, segments[i]); } systemPath = Path.Combine(systemPath, path.IsDirectory ? Path.PathSeparator.ToString() : path.EntityName); // Console.WriteLine("Mount Disk From " + systemPath); MountDisk(systemPath); }); // Activate the game base.ActivateEngine(engine); // Force the lua script to use this boot done logic instead luaScript.Globals["BootDone"] = new Action <bool>(BootDone); }