Skip to content

Commit

Permalink
onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
furudean committed Jul 14, 2024
1 parent 46f2f62 commit 0695679
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 146 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@
"scope": "machine-overridable"
},
"renpyWarp.renpyExtensionsEnabled": {
"type": "boolean",
"default": true,
"type": "string",
"enum": [
"Not set",
"Enabled",
"Disabled"
],
"default": "Not set",
"markdownDescription": "Enable Ren'Py Extension (.rpe) support."
}
}
Expand Down
35 changes: 1 addition & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ export function activate(context: vscode.ExtensionContext) {
return
}

await vscode.workspace
.getConfiguration('renpyWarp')
.update('renpyExtensionsEnabled', true, true)

const sdk_path = await get_sdk_path()
if (!sdk_path) return

const executable = (await get_executable(sdk_path))?.join(' ')
const executable = await get_executable(sdk_path)
if (!executable) {
vscode.window
.showErrorMessage(
Expand Down Expand Up @@ -199,35 +195,6 @@ export function activate(context: vscode.ExtensionContext) {
return input_path
})
)

if (!get_config('sdkPath')) {
vscode.window
.showInformationMessage(
"Please take a moment to set up Ren'Py Launch and Sync",
'OK',
'Not now'
)
.then(async (selection) => {
if (selection === 'OK') {
const selection = await vscode.commands.executeCommand(
'renpyWarp.setSdkPath'
)

if (!selection) return

await vscode.window.showInformationMessage(
"Ren'Py Launch and Sync is now set up. You can review additional settings in the extension settings.",
'Show settings',
'OK'
)
if (selection === 'Show settings')
await vscode.commands.executeCommand(
'workbench.action.openSettings',
'@ext:PaisleySoftworks.renpyWarp'
)
}
})
}
}

export function deactivate() {
Expand Down
154 changes: 76 additions & 78 deletions src/lib/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { sh } from 'puka'

import { focus_window, ProcessManager, RenpyProcess } from './process'
import { FollowCursor, sync_editor_with_renpy } from './follow_cursor'
import { get_config } from './util'
import { get_config, get_extensions_enabled } from './util'

Check failure on line 7 in src/lib/launch.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Module '"./util"' has no exported member 'get_extensions_enabled'.

Check failure on line 7 in src/lib/launch.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest)

Module '"./util"' has no exported member 'get_extensions_enabled'.
import { get_logger } from './logger'
import { find_game_root, get_editor_path, get_renpy_sh } from './sh'
import { find_game_root, get_editor_path, get_executable, set_env } from './sh'
import { has_any_rpe, has_current_rpe, install_rpe } from './rpe'
import { start_websocket_server, get_open_port } from './socket'
import { StatusBar } from './status_bar'
import { get_sdk_path } from './path'
import { prompt_configure_extensions } from './onboard'

const logger = get_logger()

Expand Down Expand Up @@ -123,93 +124,71 @@ export async function launch_renpy({
}))

try {
const socket_port = await get_open_port()
const sdk_path = await get_sdk_path()
if (!sdk_path) throw new Error('no sdk path')
if (!sdk_path) return

const renpy_sh = await get_renpy_sh(sdk_path, {
WARP_ENABLED: extensions_enabled ? '1' : undefined,
WARP_WS_PORT: socket_port.toString(),
RENPY_EDIT_PY: await get_editor_path(sdk_path),
})
if (!renpy_sh) throw new Error('no renpy.sh found')

let cmd: string

if (line === undefined) {
cmd = renpy_sh + ' ' + sh`${game_root}`
} else {
cmd =
renpy_sh +
' ' +
sh`${game_root} --warp ${filename_relative}:${line + 1}`
}
const executable = await get_executable(sdk_path)

if (extensions_enabled) {
if (!(await has_any_rpe(sdk_path))) {
const selection = await vscode.window.showQuickPick(
[
'Yes, install (recommended)',
'No, never install',
'Cancel',
],
{
ignoreFocusOut: true,
title: "Before we start: Ren'Py Launch and Sync can install a script to synchronize the game and editor. Would you like to install it?",
placeHolder: 'Choose an option',
}
if (!executable) {
vscode.window
.showErrorMessage(
"Ren'Py SDK path is invalid. Update it in the extension settings.",
'Open settings'
)

if (selection === 'Yes, install (recommended)') {
const installed_path = await install_rpe({
sdk_path,
executable: renpy_sh,
game_root,
context,
})

vscode.window.showInformationMessage(
`Ren'Py Extensions were installed at ${installed_path}`,
'OK'
)
} else if (selection === 'No, never install') {
extensions_enabled = false
await vscode.workspace
.getConfiguration('renpyWarp')
.update('renpyExtensionsEnabled', false, true)

vscode.window.showInformationMessage(
'No RPE script will be installed. Keep in mind that some features are disabled without it.',
'OK'
)
} else {
throw new Error('user cancelled')
}
} else if (
!(await has_current_rpe({
executable: renpy_sh,
sdk_path,
}))
) {
await install_rpe({
sdk_path,
game_root,
context,
executable: renpy_sh,
.then((selection) => {
if (selection === 'Open settings') {
vscode.commands.executeCommand(
'workbench.action.openSettings',
'@ext:PaisleySoftworks.renpyWarp'
)
}
})
vscode.window.showInformationMessage(
"Ren'Py extensions in project/SDK have been updated.",
'OK'
)
} else if (is_development_mode) {
await install_rpe({
return
}

if (extensions_enabled === 'Not set') {
extensions_enabled = await prompt_configure_extensions({
executable,
sdk_path,
game_root,
context,
})
} else if (extensions_enabled === 'Enabled') {
if (!(await has_current_rpe({ executable, sdk_path }))) {
const installed_path = await install_rpe({
sdk_path,
game_root,
context,
executable: renpy_sh,
executable,
})
vscode.window
.showInformationMessage(
"Ren'Py extensions have been updated",
'OK',
'Show'
)
.then((selection) => {
if (selection === 'Show') {
vscode.commands.executeCommand(
'workbench.action.openFolder',
vscode.Uri.file(installed_path)
)
}
})
}
} else if (is_development_mode) {
await install_rpe({
sdk_path,
game_root,
context,
executable,
})
}

let socket_port: number | undefined

if (extensions_enabled) {
socket_port = await get_open_port()
await start_websocket_server({
pm,
port: socket_port,
Expand All @@ -218,6 +197,25 @@ export async function launch_renpy({

if (strategy === 'Replace Window') pm.kill_all()

const renpy_sh = await set_env(executable, {
WARP_ENABLED:
extensions_enabled !== 'Disabled' ? '1' : undefined,
WARP_WS_PORT: socket_port?.toString(),
RENPY_EDIT_PY: await get_editor_path(sdk_path),
})
if (!renpy_sh) throw new Error('no renpy.sh found')

let cmd: string

if (line === undefined) {
cmd = renpy_sh + ' ' + sh`${game_root}`
} else {
cmd =
renpy_sh +
' ' +
sh`${game_root} --warp ${filename_relative}:${line + 1}`
}

return await vscode.window.withProgress(
{
title: "Starting Ren'Py" + (intent ? ' ' + intent : ''),
Expand Down
87 changes: 87 additions & 0 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as vscode from 'vscode'
import semver from 'semver'
import { get_version } from './sh'
import { install_rpe } from './rpe'
import { set_config } from './util'

export async function prompt_configure_extensions({
executable,
sdk_path,
game_root,
context,
}: {
executable: string
sdk_path: string
game_root: string
context: vscode.ExtensionContext
}): Promise<string> {
const renpy_version = get_version(executable)
const supports_rpe_py = semver.gte(renpy_version.semver, '8.3.0')
const desination = supports_rpe_py ? 'SDK' : 'project'

const selection = await vscode.window.showQuickPick(
[
'Always install extensions (recommended)',
'Use extensions in this project',
'Do not use extensions',
'Never install extensions',
'Cancel',
],
{
ignoreFocusOut: true,
title: `Ren'Py and VSCode can be synchronized by installing an extension in your Ren'Py ${desination}. Would you like to install it?`,
placeHolder: 'Choose an option',
}
)

if (
selection === 'Always install extensions (recommended)' ||
selection === 'Use extensions in this project'
) {
await set_config(
'renpyExtensionsEnabled',
'Enabled',
selection === 'Use extensions in this project'
)
const installed_path = await install_rpe({
sdk_path,
executable,
game_root,
context,
})

vscode.window
.showInformationMessage(
`Ren'Py Extensions were installed at ${installed_path}`,
'OK',
'Show'
)
.then((selection) => {
if (selection === 'Show') {
vscode.commands.executeCommand(
'vscode.openFolder',
vscode.Uri.file(installed_path)
)
}
})
return 'Enabled'
} else if (
selection === 'Do not use extensions in this project' ||
selection === 'Never install extensions'
) {
await set_config(
'renpyExtensionsEnabled',
'Disabled',
selection === 'Do not use extensions in this project'
)

vscode.window.showInformationMessage(
`RPE features have been disabled in Keep in mind that some features are disabled without it.`,
'OK'
)

return 'Enabled'
} else {
throw new Error('user cancelled')
}
}
4 changes: 2 additions & 2 deletions src/lib/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class RenpyProcess {
cmd: string
message_handler: (data: SocketMessage) => MaybePromise<void>
game_root: string
socket_port: number
socket_port: number | undefined
process: child_process.ChildProcess
socket?: WebSocket = undefined
dead: boolean = false
Expand All @@ -69,7 +69,7 @@ export class RenpyProcess {
cmd: string
message_handler: (data: SocketMessage) => MaybePromise<void>
game_root: string
socket_port: number
socket_port: number | undefined
context: vscode.ExtensionContext
}) {
this.cmd = cmd
Expand Down
Loading

0 comments on commit 0695679

Please sign in to comment.