-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RunRenpyViaplugin #291
RunRenpyViaplugin #291
Changes from 6 commits
73901ae
306eaee
769b63d
32d22a0
8867857
746a9b2
805c75b
4961e3a
b737f72
cf5d0fd
850dbec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,6 +258,36 @@ export async function activate(context: ExtensionContext): Promise<any> { | |
}); | ||
context.subscriptions.push(refreshDiagnosticsCommand); | ||
|
||
// custom command - call renpy to run workspace | ||
const runCommand = commands.registerCommand("renpy.runCommand", () => { | ||
const config = workspace.getConfiguration("renpy"); | ||
if (!config) { | ||
window.showErrorMessage("Ren'Py executable location not configured or is invalid."); | ||
} else { | ||
if (isValidExecutable(config.renpyExecutableLocation)) { | ||
//this is kinda a hob botched together attempt that I'm like 30% certain has a chance of working | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test if it works? If it does you should remove the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not manage to test if it works yet, will try after this commit |
||
vscode.debug.startDebugging( | ||
undefined, | ||
{ | ||
type: "cmd", | ||
name: "Run File", | ||
request: "launch", | ||
program: config.renpyExecutableLocation, | ||
}, | ||
{ noDebug: true } | ||
); | ||
//call renpy | ||
const result = RunWorkspaceFolder(); | ||
if (result) { | ||
window.showInformationMessage("Ren'Py is running successfully"); | ||
} | ||
} else { | ||
window.showErrorMessage("Ren'Py executable location not configured or is invalid."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to remove this one if you addressed my first comment :) |
||
} | ||
} | ||
}); | ||
context.subscriptions.push(runCommand); | ||
|
||
// custom command - call renpy to compile | ||
const compileCommand = commands.registerCommand("renpy.compileNavigationData", () => { | ||
// check Settings has the path to Ren'Py executable | ||
|
@@ -394,6 +424,41 @@ function isValidExecutable(renpyExecutableLocation: string): boolean { | |
} | ||
return fs.existsSync(renpyExecutableLocation); | ||
} | ||
// Attempts to run renpy executable through console commands. | ||
function RunWorkspaceFolder(): boolean { | ||
const config = workspace.getConfiguration("renpy"); | ||
const renpy = config.renpyExecutableLocation; | ||
seanj29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (isValidExecutable(renpy)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember that the config can be null, you should use the same check as above. (Even if you know you checked, if someone in the future wants to use this function, it should be safe to use on it's own) |
||
const renpyPath = cleanUpPath(Uri.file(renpy).path); | ||
const cwd = renpyPath.substring(0, renpyPath.lastIndexOf("/")); | ||
let wf = getWorkspaceFolder(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now you copied it from the function below, so no worries. But my feedback should still be applied. I think this can be const. Also please use full (short) descriptive names for variables. If I want to know what |
||
const args: string[] = [`${wf}`, "run"]; | ||
if (wf.endsWith("/game")) { | ||
try { | ||
updateStatusBar("$(sync~spin) Running Ren'Py..."); | ||
const result = cp.spawn(renpy, args, { | ||
cwd: `${cwd}`, | ||
env: { PATH: process.env.PATH }, | ||
}); | ||
if (result.error) { | ||
console.log(`renpy spawn error: ${result.error}`); | ||
return false; | ||
} | ||
if (result.stderr && result.stderr.length > 0) { | ||
console.log(`renpy spawn stderr: ${result.stderr}`); | ||
return false; | ||
} | ||
} catch (error) { | ||
console.log(`renpy spawn error: ${error}`); | ||
return false; | ||
} finally { | ||
updateStatusBar(getStatusBarText()); | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function ExecuteRenpyCompile(): boolean { | ||
const config = workspace.getConfiguration("renpy"); | ||
|
@@ -412,7 +477,12 @@ function ExecuteRenpyCompile(): boolean { | |
try { | ||
NavigationData.isCompiling = true; | ||
updateStatusBar("$(sync~spin) Compiling Ren'Py navigation data..."); | ||
const result = cp.spawnSync(renpy, args, { cwd: `${cwd}`, env: { PATH: process.env.PATH }, encoding: "utf-8", windowsHide: true }); | ||
const result = cp.spawnSync(renpy, args, { | ||
cwd: `${cwd}`, | ||
env: { PATH: process.env.PATH }, | ||
encoding: "utf-8", | ||
windowsHide: true, | ||
}); | ||
if (result.error) { | ||
console.log(`renpy spawn error: ${result.error}`); | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this check to the line above with an || or comparison. (So 'if not config or renpy executable location not set'.) That way you don't need the copy the message log code :)
(Also in case you didn't know, that works because if statements do early out. Meaning the config is checked first, and only if true will it check the remaining parts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
God it, fixed this now