Skip to content
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

Merged
merged 11 commits into from
May 7, 2023
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
{
"command": "renpy.refreshDiagnostics",
"title": "Refresh Ren'Py diagnostics for the active editor window"
},
{
"command": "renpy.runCommand",
"title": "Run Project",
"category": "Run",
"icon": "$(play)"
}
],
"configuration": [
Expand Down
72 changes: 71 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Collaborator

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)

Copy link
Contributor Author

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

//this is kinda a hob botched together attempt that I'm like 30% certain has a chance of working
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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();
Copy link
Collaborator

@duckdoom4 duckdoom4 Apr 18, 2023

Choose a reason for hiding this comment

The 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 wf means, I now have to look at the definition.

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");
Expand All @@ -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;
Expand Down