Skip to content

Commit

Permalink
RunRenpyViaplugin (#291)
Browse files Browse the repository at this point in the history
* Edited extensions method to add way to run renpy

* Added the command to the pallete via json

* Adding debug config to allow renpy to be played from play button

* changed type to cmd

* reformatted with prettier

* This format might work?

* Refactored if statement to make it more readable

* Refactoring of folder names and chaning if statements

* This commit fixed the issues in comment https://github.com/LuqueDaniel/vscode-language-renpy/pull/291#discussion_r1170180867, , refactoring if statement

* reformated through magical means... God I hate switching computers

* Reformated with the correct file, please ignore previous one
  • Loading branch information
seanj29 authored and duckdoom4 committed May 12, 2023
1 parent f1da4e1 commit c433666
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
{
"command": "renpy.toggleTokenDebugView",
"title": "Renpy: Toggle token debug visualization"
},
{
"command": "renpy.runCommand",
"title": "Renpy: Run Project",
"category": "Run",
"icon": "$(play)"
}
],
"configuration": [
Expand Down
71 changes: 70 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
DefinitionProvider,
DocumentSemanticTokensProvider,
DocumentSymbol,
debug,
DocumentSymbolProvider,
Hover,
HoverProvider,
Expand Down Expand Up @@ -263,6 +264,31 @@ export async function activate(context: ExtensionContext): Promise<void> {
});
context.subscriptions.push(toggleTokenDebugViewCommand);

// custom command - call renpy to run workspace
const runCommand = commands.registerCommand("renpy.runCommand", () => {
if (!config || !isValidExecutable(config.renpyExecutableLocation)) {
window.showErrorMessage("Ren'Py executable location not configured or is invalid.");
} else {
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");
}
}
});
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 @@ -399,6 +425,44 @@ 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");

if (config && isValidExecutable(config.renpyExecutableLocation)) {
const renpy = config.renpyExecutableLocation;
const renpyPath = cleanUpPath(Uri.file(renpy).path);
const cwd = renpyPath.substring(0, renpyPath.lastIndexOf("/"));
const workfolder = getWorkspaceFolder();
const args: string[] = [`${workfolder}`, "run"];
if (workfolder.endsWith("/game")) {
try {
updateStatusBar("$(sync~spin) Running Ren'Py...");
const result = cp.spawnSync(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;
}
} else {
console.log("config for rennpy does not exist");
return false;
}
}

function ExecuteRenpyCompile(): boolean {
const config = workspace.getConfiguration("renpy");
Expand All @@ -417,7 +481,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

0 comments on commit c433666

Please sign in to comment.