Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
PhaserEditor2D committed Apr 28, 2023
2 parents 7350161 + 5564cf7 commit fb18df4
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 70 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## v3.60.3 - Apr 27, 2023

* Fixes regression bug with the Play command.

## v3.60.2 - Apr 27, 2023

* Fixes creating a prefab layer with a selected container or layer.
* Updates the ScriptNode resources with the bug fixes.
* [#129](https://github.com/PhaserEditor2D/PhaserEditor2D-v3/issues/129) Adds Preview Scene command (Ctrl+0). It runs the game in the browser and passes the `start=<scene-name>` parameter.

## v3.60.1 - Apr 21, 2023

* Fixes plain object serialization (keyboard keys, colliders,...).
Expand Down
1 change: 1 addition & 0 deletions source/editor/plugins/colibri/src/ui/ide/EditorRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace colibri.ui.ide {
for (const factory of this._factories) {

if (factory.acceptInput(input)) {

return factory;
}
}
Expand Down
12 changes: 12 additions & 0 deletions source/editor/plugins/phasereditor2d.files/src/FilesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ namespace phasereditor2d.files {
export class FilesPlugin extends colibri.Plugin {

private static _instance = new FilesPlugin();
private _openFileAction: (file: colibri.core.io.FilePath) => void;

static getInstance() {

return this._instance;
}

private constructor() {
super("phasereditor2d.files");
}

setOpenFileAction(action: (file: colibri.core.io.FilePath) => void) {

this._openFileAction = action;
}

getOpenFileAction() {

return this._openFileAction;
}

public registerExtensions(reg: colibri.ExtensionRegistry) {

// icons loader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ namespace phasereditor2d.files.ui.views {
}

getPropertyProvider() {

return this._propertyProvider;
}

Expand All @@ -181,7 +182,7 @@ namespace phasereditor2d.files.ui.views {

viewer.repaint();

viewer.eventOpenItem.addListener((file: io.FilePath) => {
viewer.eventOpenItem.addListener(async (file: io.FilePath) => {

if (file.isFolder()) {

Expand All @@ -192,7 +193,7 @@ namespace phasereditor2d.files.ui.views {
return;
}

wb.openEditor(file);
FilesPlugin.getInstance().getOpenFileAction()(file);
});

wb.getFileStorage().addChangeListener(change => this.onFileStorageChange(change));
Expand Down
60 changes: 58 additions & 2 deletions source/editor/plugins/phasereditor2d.ide/src/IDEPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace phasereditor2d.ide {
export const ICON_PLAY = "play";

export class IDEPlugin extends colibri.Plugin {

public eventActivationChanged = new controls.ListenerList<boolean>();

private static _instance = new IDEPlugin();
Expand Down Expand Up @@ -82,6 +82,8 @@ namespace phasereditor2d.ide {
command: ui.actions.CMD_LOCATE_FILE
}));
}

phasereditor2d.files.FilesPlugin.getInstance().setOpenFileAction(file => this.openFileFromFilesView(file));
}

async compileProject() {
Expand Down Expand Up @@ -141,6 +143,25 @@ namespace phasereditor2d.ide {
});
}

async playProject(startScene?: string) {

const config = await IDEPlugin.getInstance().requestProjectConfig();

const search = startScene ? `?start=${startScene}` : "";

const url = (config.playUrl || colibri.ui.ide.FileUtils.getRoot().getExternalUrl())
+ search;

colibri.Platform.onElectron(electron => {

colibri.core.io.apiRequest("OpenBrowser", { url: config.playUrl });

}, () => {

controls.Controls.openUrlInNewPage(url);
});
}

async requestUpdateAvailable() {

if (this.isDesktopMode()) {
Expand All @@ -166,6 +187,7 @@ namespace phasereditor2d.ide {
}

isDesktopMode() {

return this._desktopMode;
}

Expand Down Expand Up @@ -246,6 +268,40 @@ namespace phasereditor2d.ide {
this.openFileExternalEditor(colibri.ui.ide.FileUtils.getRoot());
}

setEnableOpenCodeFileInExternalEditor(enabled: boolean) {

window.localStorage.setItem("phasereditor2d.ide.enableOpenCodeFileInExternalEditor", enabled? "1" : "0");
}

isEnableOpenCodeFileInExternalEditor() {

return window.localStorage.getItem("phasereditor2d.ide.enableOpenCodeFileInExternalEditor") === "1";
}

private openFileFromFilesView(file: io.FilePath) {

// a hack, detect if content type is JS, TS, or plain text, so it opens the external editor
if (this.isEnableOpenCodeFileInExternalEditor()) {

const ct = colibri.Platform.getWorkbench().getContentTypeRegistry().getCachedContentType(file);

switch (ct) {
case "typescript":
case "javascript":
case "html":
case "css":

console.log(`Openin ${file.getFullName()} with external editor`);

this.openFileExternalEditor(file);

return;
}
}

colibri.Platform.getWorkbench().openEditor(file);
}

async openFileExternalEditor(file: io.FilePath) {

const resp = await colibri.core.io.apiRequest("OpenVSCode", { location: file.getFullName() });
Expand All @@ -261,7 +317,7 @@ namespace phasereditor2d.ide {

/* program entry point */

export const VER = "3.60.1";
export const VER = "3.60.3";

async function main() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace phasereditor2d.ide.ui.actions {
export const CMD_PLAY_PROJECT = "phasereditor2d.ide.ui.actions.PlayProject";
export const CMD_QUICK_PLAY_PROJECT = "phasereditor2d.ide.ui.actions.QuickPlayProject";
export const CMD_OPEN_VSCODE = "phasereditor2d.ide.ui.actions.OpenVSCode";
export const CMD_ENABLE_OPEN_SOURCE_FILE_IN_EXTERNAL_EDITOR = "phasereditor2d.ide.ui.actions.EnableOpenCodeFileInExternalEditor";
export const CMD_DISABLE_OPEN_SOURCE_FILE_IN_EXTERNAL_EDITOR = "phasereditor2d.ide.ui.actions.EnableOpenCodeFileInExternalEditor";

import controls = colibri.ui.controls;
import commands = colibri.ui.ide.commands;
import io = colibri.core.io;

Expand All @@ -27,6 +28,38 @@ namespace phasereditor2d.ide.ui.actions {
name: "Project"
});

manager.add({
command: {
id: CMD_ENABLE_OPEN_SOURCE_FILE_IN_EXTERNAL_EDITOR,
category: CAT_PROJECT,
name: "Enable Open Code File In External Editor",
tooltip: "If enable, clicking on a coding file in the Files view opens the external editor"
},
handler: {
testFunc: isNotWelcomeWindowScope,
executeFunc: () => {

IDEPlugin.getInstance().setEnableOpenCodeFileInExternalEditor(true);
}
}
});

manager.add({
command: {
id: CMD_DISABLE_OPEN_SOURCE_FILE_IN_EXTERNAL_EDITOR,
category: CAT_PROJECT,
name: "Disable Open Code File In External Editor",
tooltip: "If disabled, clicking on a coding file open the built-in editor."
},
handler: {
testFunc: isNotWelcomeWindowScope,
executeFunc: () => {

IDEPlugin.getInstance().setEnableOpenCodeFileInExternalEditor(false);
}
}
});

// play game

manager.add({
Expand All @@ -45,18 +78,7 @@ namespace phasereditor2d.ide.ui.actions {

executeFunc: async (args) => {

const config = await IDEPlugin.getInstance().requestProjectConfig();

const url = config.playUrl || colibri.ui.ide.FileUtils.getRoot().getExternalUrl();

colibri.Platform.onElectron(electron => {

colibri.core.io.apiRequest("OpenBrowser", { url: config.playUrl });

}, () => {

controls.Controls.openUrlInNewPage(url);
});
IDEPlugin.getInstance().playProject();
}
},
keys: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import Phaser from "phaser";


export default class ScriptNode {

/**
/**
* @private
* @type {Phaser.Scene}
*/
* @type {Phaser.Scene}
**/
_scene;

/**
* @private
* @type {Phaser.GameObjects.GameObject}
* @private
* @type {Phaser.GameObjects.GameObject | undefined}
*/
_gameObject;

Expand All @@ -23,12 +22,11 @@ export default class ScriptNode {

/**
* @private
* @type {ScriptNode[]}
* @type {ScriptNode[] | undefined}
*/
_children;

/**
*
* @param {ScriptNode | Phaser.GameObjects.GameObject | Phaser.Scene} parent
*/
constructor(parent) {
Expand Down Expand Up @@ -72,10 +70,11 @@ export default class ScriptNode {
this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this);
}

if (listenStart || listenUpdate || listenDestroy) {
if (listenAwake || listenStart || listenUpdate || listenDestroy) {

const destroyCallback = () => {

this.scene.events.off("scene-awake", this.awake, this);
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.start, this);
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.update, this);

Expand All @@ -91,7 +90,7 @@ export default class ScriptNode {

} else {

this.scene.events.on(Phaser.Scenes.Events.DESTROY, destroyCallback);
this.scene.events.on(Phaser.Scenes.Events.SHUTDOWN, destroyCallback);
}
}
}
Expand All @@ -111,9 +110,6 @@ export default class ScriptNode {
return this._parent;
}

/**
* @type {ScriptNode[]}
*/
get children() {

if (!this._children) {
Expand All @@ -125,7 +121,6 @@ export default class ScriptNode {
}

/**
*
* @param {ScriptNode} child
*/
add(child) {
Expand All @@ -134,25 +129,23 @@ export default class ScriptNode {
}

/**
*
* @param {any | undefined} args
* @param {...any} args
*/
executeChildren(args) {
executeChildren(...args) {

if (this._children) {

for(const child of this._children) {
for (const child of this._children) {

child.execute(args);
child.execute(...args);
}
}
}

/**
*
* @param {any | undefined} args
* @param {...any} args
*/
execute(args) {
execute(...args) {
// override this on executable nodes
}

Expand Down
Loading

0 comments on commit fb18df4

Please sign in to comment.