Skip to content

Commit

Permalink
Different game host target handling regarding the use of RW3D_CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Aug 2, 2024
1 parent 12f0262 commit e8709e8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
8 changes: 5 additions & 3 deletions editors/vscode/src/commands/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fspath from 'path';
import * as cp from 'child_process';

import { Cmd } from './index'
import { getConfiguration } from '../config';
import { GameHostType, getConfiguration } from '../config';
import { fileExists } from '../utils';
import * as state from '../state'

Expand Down Expand Up @@ -106,10 +106,12 @@ function runRw3d(ctx: vscode.ExtensionContext, cmd: string, additionalArgs: stri
const rw3dPath = ctx.asAbsolutePath(
`deps/rw3d/bin/rw3d_cli${ext}`
);
const cfg = getConfiguration();

const ip = getConfiguration().gameHostIpAddress;
const target = cfg.gameHostType == GameHostType.Standalone ? "game" : "editor";
const ip = cfg.gameHostIpAddress;
const args = [
"--no-delay", "--log-level=output-only", `--ip=${ip}`,
"--no-delay", "--log-level=output-only", `--target=${target}`, `--ip=${ip}`,
cmd, ...additionalArgs
];

Expand Down
1 change: 1 addition & 0 deletions editors/vscode/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function registerCommands(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("witcherscript-ide.misc.showCommandsInPalette", misc.commandShowCommandsInPalette()),
vscode.commands.registerCommand("witcherscript-ide.misc.openLogs", misc.commandOpenLogs()),
vscode.commands.registerCommand("witcherscript-ide.misc.openSettings", misc.commandOpenSettings()),
vscode.commands.registerCommand("witcherscript-ide.misc.openGameHostSettings", misc.commandOpenGameHostSettings()),
vscode.commands.registerCommand("witcherscript-ide.misc.openFileReadOnly", misc.commandOpenFileReadOnly()),
);

Expand Down
6 changes: 6 additions & 0 deletions editors/vscode/src/commands/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export function commandOpenSettings(): Cmd {
}
}

export function commandOpenGameHostSettings(): Cmd {
return () => {
vscode.commands.executeCommand('workbench.action.openSettings', 'witcherscript-ide.gameHost')
}
}

export function commandOpenFileReadOnly(): Cmd {
return (uri: vscode.Uri) => {
uri = uri.with({ scheme: tdcp.ReadOnlyContentProvider.scheme });
Expand Down
15 changes: 13 additions & 2 deletions editors/vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export function getConfiguration(): Config {
}

export class Config {
readonly config: vscode.WorkspaceConfiguration;
public static readonly SECTION = 'witcherscript-ide';

private readonly config: vscode.WorkspaceConfiguration;

constructor() {
this.config = vscode.workspace.getConfiguration('witcherscript-ide');
this.config = vscode.workspace.getConfiguration(Config.SECTION);
}


Expand All @@ -21,6 +23,10 @@ export class Config {
return this.config.get<string[]>('contentRepositories') ?? [];
}

get gameHostType(): GameHostType {
return this.config.get<string>('gameHost.type') as GameHostType ?? GameHostType.Standalone;
}

get gameHostIpAddress(): string {
return this.config.get<string>('gameHost.ipAddress') ?? '';
}
Expand All @@ -40,4 +46,9 @@ export class Config {
get enableDebugFeatures(): boolean {
return this.config.get<boolean>('debug.enableDebugFeatures') ?? false;
}
}

export enum GameHostType {
Standalone = "standalone",
Editor = "editor"
}
27 changes: 27 additions & 0 deletions editors/vscode/src/providers/dashboard_provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as vscode from 'vscode'

import { Config, getConfiguration } from '../config';


let instance: DashboardProvider;

Expand All @@ -17,6 +19,13 @@ export class DashboardProvider implements vscode.TreeDataProvider<Item> {
if (instance == undefined) {
instance = new DashboardProvider();
}

vscode.workspace.onDidChangeConfiguration((ev) => {
if (ev.affectsConfiguration(Config.SECTION)) {
// making sure that game host type is synced
instance.didChangeTreeData.fire(undefined);
}
});

return instance;
}
Expand Down Expand Up @@ -61,6 +70,7 @@ export type Item =
ProjectSystemOptionsHeaderItem |
ProjectSystemOptionItem |
RemoteCommandsHeaderItem |
RemoteCommandsHostInfoItem |
RemoteCommandItem;


Expand Down Expand Up @@ -137,12 +147,29 @@ class RemoteCommandsHeaderItem extends vscode.TreeItem {

getChildren(): Item[] {
return [
new RemoteCommandsHostInfoItem(this),
new RemoteCommandItem(this, "Recompile scripts", "recompileScripts"),
new RemoteCommandItem(this, "Execute console command", "execConsoleCommand"),
];
}
}

class RemoteCommandsHostInfoItem extends vscode.TreeItem {
constructor(
readonly parent: RemoteCommandsHeaderItem,
) {
const cfg = getConfiguration();
const label = `Game host: ${cfg.gameHostType.toString()}, address: ${cfg.gameHostIpAddress}`;

super(label, vscode.TreeItemCollapsibleState.None);
this.contextValue = "gameHostInfo";
}

getChildren(): Item[] {
return [];
}
}

class RemoteCommandItem extends vscode.TreeItem {
constructor(
readonly parent: RemoteCommandsHeaderItem,
Expand Down

0 comments on commit e8709e8

Please sign in to comment.