Copy from an editable template file when making a new Lua script
This commit is contained in:
parent
02caa5fcbb
commit
380e459bec
|
@ -825,6 +825,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void NewScriptMenuItem_Click(object sender, EventArgs e)
|
private void NewScriptMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var luaDir = Config!.PathEntries.LuaAbsolutePath();
|
||||||
string initDir;
|
string initDir;
|
||||||
string ext;
|
string ext;
|
||||||
if (!string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename))
|
if (!string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename))
|
||||||
|
@ -833,7 +834,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
initDir = Config!.PathEntries.LuaAbsolutePath();
|
initDir = luaDir;
|
||||||
ext = Path.GetFileNameWithoutExtension(Game.Name);
|
ext = Path.GetFileNameWithoutExtension(Game.Name);
|
||||||
}
|
}
|
||||||
var result = this.ShowFileSaveDialog(
|
var result = this.ShowFileSaveDialog(
|
||||||
|
@ -842,8 +843,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
initDir: initDir,
|
initDir: initDir,
|
||||||
initFileName: ext);
|
initFileName: ext);
|
||||||
if (string.IsNullOrWhiteSpace(result)) return;
|
if (string.IsNullOrWhiteSpace(result)) return;
|
||||||
string defaultTemplate = "while true do\n\temu.frameadvance();\nend";
|
const string TEMPLATE_FILENAME = ".template.lua";
|
||||||
File.WriteAllText(result, defaultTemplate);
|
var templatePath = Path.Combine(luaDir, TEMPLATE_FILENAME);
|
||||||
|
const string DEF_TEMPLATE_CONTENTS = "-- This template lives at `.../Lua/.template.lua`.\nwhile true do\n\t-- Code here will run once when the script is loaded, then after each emulated frame.\n\temu.frameadvance();\nend\n";
|
||||||
|
if (!File.Exists(templatePath)) File.WriteAllText(path: templatePath, contents: DEF_TEMPLATE_CONTENTS);
|
||||||
|
File.Copy(sourceFileName: templatePath, destFileName: result);
|
||||||
LuaImp.ScriptList.Add(new LuaFile(Path.GetFileNameWithoutExtension(result), result));
|
LuaImp.ScriptList.Add(new LuaFile(Path.GetFileNameWithoutExtension(result), result));
|
||||||
Config!.RecentLua.Add(result);
|
Config!.RecentLua.Add(result);
|
||||||
UpdateDialog();
|
UpdateDialog();
|
||||||
|
|
Loading…
Reference in New Issue