diff --git a/entry.js b/entry.js
index 5f9e7ffe..22ab8735 100644
--- a/entry.js
+++ b/entry.js
@@ -1,18 +1,21 @@
-const elec = require("electron");
+require("update-electron-app")();
+
+const { app: eApp, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const WIN_WIDTH = 1000;
const WIN_HEIGHT = 700;
let main_window;
-elec.app.on("open-file", (e, path) => {
+eApp.on("open-file", (e, path) => {
if (main_window); //main_window.webContents.send('open-file', path);
});
-elec.app.commandLine.appendSwitch("enable-gpu-rasterization", "true");
-elec.app.on("ready", function () {
- let display = elec.screen.getPrimaryDisplay();
+eApp.commandLine.appendSwitch("enable-gpu-rasterization", "true");
+eApp.on("ready", function () {
+ const { screen } = require("electron");
+ let display = screen.getPrimaryDisplay();
- main_window = new elec.BrowserWindow({
+ main_window = new BrowserWindow({
x: display.bounds.x + (display.bounds.width - WIN_WIDTH) / 2,
y: display.bounds.y + (display.bounds.height - WIN_HEIGHT) / 2,
width: WIN_WIDTH,
@@ -43,9 +46,12 @@ elec.app.on("ready", function () {
e.preventDefault();
if (url.length > 1) require("electron").shell.openExternal(url);
});
+
+ ipcMain.on("openDevTools", e => main_window.webContents.openDevTools());
+ ipcMain.on("showWindow", e => main_window.show());
});
-elec.app.commandLine.appendSwitch("ignore-gpu-blacklist");
+eApp.commandLine.appendSwitch("ignore-gpu-blacklist");
process.on("uncaughtException", err => {
console.log(err);
diff --git a/package-lock.json b/package-lock.json
index 41769207..9e6f3844 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1165,6 +1165,11 @@
}
}
},
+ "electron-is-dev": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.3.0.tgz",
+ "integrity": "sha1-FOb9pcaOnk7L7/nM8DfL18BcWv4="
+ },
"electron-notarize": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-0.1.1.tgz",
@@ -1672,6 +1677,14 @@
"assert-plus": "^1.0.0"
}
},
+ "github-url-to-object": {
+ "version": "4.0.4",
+ "resolved": "https://registry.npmjs.org/github-url-to-object/-/github-url-to-object-4.0.4.tgz",
+ "integrity": "sha512-1Ri1pR8XTfzLpbtPz5MlW/amGNdNReuExPsbF9rxLsBfO1GH9RtDBamhJikd0knMWq3RTTQDbTtw0GGvvEAJEA==",
+ "requires": {
+ "is-url": "^1.1.0"
+ }
+ },
"glob": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
@@ -1889,6 +1902,11 @@
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
+ "is-url": {
+ "version": "1.2.4",
+ "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz",
+ "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww=="
+ },
"is-utf8": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
@@ -2201,8 +2219,7 @@
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
- "dev": true
+ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node-watch": {
"version": "0.6.2",
@@ -3155,6 +3172,17 @@
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
+ "update-electron-app": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/update-electron-app/-/update-electron-app-1.5.0.tgz",
+ "integrity": "sha512-g7noW9JfQ8Hwq6zw9lmZei+R/ikOIBcaZ04TbmIcU5zNfv23HkN80QLLAyiR/47KvfS4sjnh2/wuDq5nh8+0mQ==",
+ "requires": {
+ "electron-is-dev": "^0.3.0",
+ "github-url-to-object": "^4.0.4",
+ "is-url": "^1.2.4",
+ "ms": "^2.1.1"
+ }
+ },
"update-notifier": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.0.tgz",
diff --git a/package.json b/package.json
index 7944d2b2..8bb967a3 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,14 @@
{
"name": "BlankE",
- "description": "BlankE game dev",
- "version": "0.1.0",
+ "description": "BlankE game dev environment",
+ "version": "0.11.1",
"main": "entry.js",
"single-instance": false,
"chromium-args": "--enable-webgl --ignore-gpu-blacklist --allow-file-access-from-files",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/xharris/blankejs.git"
+ },
"scripts": {
"electron": "electron .",
"build": "electron-builder",
@@ -32,6 +36,7 @@
"node-watch": "^0.6.0",
"request": "^2.88.0",
"uglify-es": "^3.3.9",
+ "update-electron-app": "^1.5.0",
"walk": "^2.3.13"
},
"devDependencies": {
diff --git a/projects/test_zone/config.json b/projects/test_zone/config.json
index 1a6525d9..29241df6 100644
--- a/projects/test_zone/config.json
+++ b/projects/test_zone/config.json
@@ -7,14 +7,14 @@
"game_size": 2,
"window_size": 3,
"quick_access": [
- [
- "platformer.lua=script+?",
- "platformer.lua"
- ],
[
"main.lua=script+?",
"main.lua"
],
+ [
+ "platformer.lua=script+?",
+ "platformer.lua"
+ ],
[
"conf.lua=script+?",
"conf.lua"
diff --git a/src/blanke-kit/blanke.js b/src/blanke-kit/blanke.js
index 1cc87db9..a89c4e4a 100644
--- a/src/blanke-kit/blanke.js
+++ b/src/blanke-kit/blanke.js
@@ -997,8 +997,10 @@ var blanke = {
chooseFile: function (options, cb) {
//type, onChange, filename='', multiple=false) {
- if (!blanke.elec_ref) return;
- blanke.elec_ref.remote.dialog.showOpenDialog(options, files => {
+ //const elec_ref = require('electron');
+ //if (!blanke.elec_ref) return;
+ // blanke.elec_ref.
+ remote.dialog.showOpenDialog(options, files => {
if (!files) return "";
if (files.length == 1) cb(files[0]);
else cb(files);
diff --git a/src/js/code.js b/src/js/code.js
index 253fd933..0f39013f 100644
--- a/src/js/code.js
+++ b/src/js/code.js
@@ -412,7 +412,7 @@ class Code extends Editor {
// this line is closing someting
if (curr_line_offset < 0) indentation--;
- // console.log({prev_line, prev_line_offset, indentation})
+ // console.log({ prev_line, prev_line_offset, indentation });
}
/*
diff --git a/src/js/core/editor.js b/src/js/core/editor.js
index 31846ee9..b533ad91 100644
--- a/src/js/core/editor.js
+++ b/src/js/core/editor.js
@@ -1,338 +1,363 @@
+const { Menu, MenuItem } = require("electron");
+
class Editor {
- constructor () {
- this.app = app;
- this.closed = false;
-
- // asset list
- this.asset_list = document.createElement("div");
- this.asset_list.classList.add('asset-list');
-
- // real content area
- this.content_area = document.createElement("div");
- this.content_area.classList.add('editor-content');
- }
-
- setupPopup(content) {
- this.container_type = 'dragbox';
- // create drag box
- this.container = new DragBox(content || this.constructor.name);
- }
-
- setupDragbox(content) {
- this.container_type = 'dragbox';
- // create drag box
- this.container = new DragBox(content || this.constructor.name)
- this.container.appendTo(workspace);
- this.container.width = 400;
- this.container.height = 300;
- this.container.drag_container.appendChild(this.asset_list);
- this.container.appendChild(this.content_area);
- // menu button click
- this.container.btn_menu.onclick = (e) => {
- this.onMenuClick(e);
- }
- this.container.onClose = (...args) => this.onClose(...args);
- this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
- app.refreshQuickAccess();
- return this;
- }
-
- setupTab(content) {
- var this_ref = this;
- this.container_type = 'tab';
- // create tab
- this.container = new Tab(content || this.constructor.name);
- this.container.appendChild(this.content_area);
- app.setHistoryActive(this.container.history_id, true);
- app.setHistoryContextMenu(this.container.history_id, function(e) {
- this_ref.onMenuClick(e);
- });
- this.container.onClose = (...args)=>{
- this.onClose(...args);
- app.refreshQuickAccess();
- }
- this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
- app.refreshQuickAccess();
- return this;
- }
-
- setupFibWindow(content) {
- var this_ref = this;
- this.container_type = "fibwindow";
- this.container = new FibWindow(typeof content == 'string' ? content : this.constructor.name);
- this.container.appendTo(workspace);
- this.container.appendChild(this.content_area);
- this.container.btn_menu.onclick = function(e) {
- this_ref.onMenuClick(e);
- }
- app.setHistoryActive(this.container.history_id, true);
- app.setHistoryContextMenu(this.container.history_id, function(e) {
- this_ref.onMenuClick(e);
- });
- this.container.onClose = (...args) => {
- this.onClose(...args);
- app.refreshQuickAccess();
- }
- this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
- app.refreshQuickAccess();
- return this;
- }
-
- setupSideWindow(transparent, content) {
- let this_ref = this;
- this.container_type = "sidewindow";
- this.container = new SideWindow(content || this.constructor.name);
- this.container.appendChild(this.content_area);
- this.container.btn_menu.onclick = function(e) {
- this_ref.onMenuClick(e);
- }
- app.setHistoryActive(this.container.history_id, true);
- app.setHistoryContextMenu(this.container.history_id, function(e) {
- this_ref.onMenuClick(e);
- });
- this.container.onClose = (...args)=>{
- this.onClose(...args);
- app.refreshQuickAccess();
- }
- if (transparent)
- this.container.el_container.classList.add("transparent");
- app.refreshQuickAccess();
- return this;
- }
-
- setupMenu (opt) {
- let items = [];
- if (!opt.file_key) opt.file_key = 'file';
-
- if (opt.close) {
- items.push({label:'close', click:() => { this.close(); }});
- }
-
- // file_key='file' : where filename is stored
- // rename : callback when file is renamed
- if (opt.rename) {
- items.push({label:'rename', click:() => {
- let full_path = this[opt.file_key];
- let filename = nwPATH.basename(full_path);
- let ext = nwPATH.extname(filename);
- blanke.showModal(
- ""+
- "",
- {
- "yes": () => {
- let new_path = nwPATH.join(nwPATH.dirname(full_path), app.getElement('#new-file-name').value+ext);
- app.renameSafely(full_path, new_path, (success, err) => {
- if (success) {
- this[opt.file_key] = app.cleanPath(new_path);
- if (typeof(opt.rename) == "function") opt.rename(new_path, full_path);
- } else
- blanke.toast("could not rename \'"+nwPATH.basename(full_path)+"\' ("+err+")");
- });
- },
- "no": () => {}
- });
- }});
- }
-
- // file_key='file'
- // delete
- if (opt.delete) {
- items.push({label:'delete', click:() => {
- blanke.showModal(
- "delete \'"+nwPATH.basename(this[opt.file_key])+"\'?",
- {
- "yes": () => {
- this.deleted = true;
- nwFS.remove(this[opt.file_key]);
- if (typeof(opt.delete) == "function") opt.delete();
- },
- "no": () => {}
- });
- }});
- }
-
-
- this.onMenuClick = (e) => {
- let items_copy = [...items];
- if (opt.extra)
- items_copy = items_copy.concat(opt.extra());
- app.contextMenu(e.x, e.y, items_copy);
- }
- }
-
- removeHistory() {
- if (this.container)
- app.removeHistory(this.container.history_id);
- }
-
- setOnClick() {
- let fn = arguments;
- if (this.container_type != 'tab')
- fn = arguments[0];
- let old_fn = fn;
-
- if (['tab','fibwindow','sidewindow'].includes(this.container_type))
- fn = (...args) => {
- app.refreshQuickAccess(this.getTitle());
- if (this.container.onTabFocus)
- this.container.onTabFocus();
- old_fn(...args);
- };
-
- if (this.container_type == 'tab')
- this.container.setOnClick.apply(this.container, fn);
- if (this.container_type == 'fibwindow')
- app.setHistoryClick(this.container.history_id, fn);
- if (this.container_type == 'sidewindow')
- app.setHistoryClick(this.container.history_id, fn);
- }
-
- onBeforeClose(res) { res(); }
- onClose() {}
-
- close(...args) {
- let real_close = () => {
- app.setHistoryActive(this.container.history_id, false);
- this.container.close(...args);
- if (this.onClose) this.onClose();
- this.closed = true;
- }
- if (this.onBeforeClose) { // return TRUE to prevent closing
- (new Promise((res,rej) => this.onBeforeClose(res, rej))).then(real_close, () => {})
- } else
- real_close();
- }
-
- static closeAll (type) {
- DragBox.closeAll(type);
- Tab.closeAll(type);
- FibWindow.closeAll();
- }
-
- addCallback(cb_name, new_func) {
- this.container[cb_name] = new_func;
- }
-
- getCenter() {
- if (this.container.getCenter) return this.container.getCenter();
- return [ this.width/2, this.height/2 ];
- }
-
- get width() {
- return this.container.width;
- }
-
- get height() {
- return this.container.height;
- }
-
- set width (v) {
- this.container.width = v;
- }
-
- set height (v) {
- this.container.height = v;
- }
-
- get bg_width() {
- if (this.container.in_background)
- return app.getElement('#bg-workspace').clientWidth;
- else
- return this.width;
- }
-
- get bg_height() {
- if (this.container.in_background)
- return app.getElement('#bg-workspace').clientHeight;
- else
- return this.height;
- }
-
- hideMenuButton () {
- if (this.container.btn_menu)
- this.container.btn_menu.style.display = 'none';
- }
-
- getContent() {
- return this.container.getContent();
- }
-
- getContainer() {
- return this.container;
- }
-
- appendChild (el) {
- this.content_area.appendChild(el);
- }
-
- appendBackground (el) {
- if (this.container.appendBackground)
- this.container.appendBackground(el);
- else
- this.appendChild(el);
- }
-
- isInBackground () {
- return this.container.in_background == true;
- }
-
- getTitle (with_sub) {
- return this.container.getTitle(with_sub);
- }
-
- setTitle (val) {
- this.container.setTitle(val);
- return this;
- }
-
- setSubtitle (val) {
- if (['dragbox','fibwindow','sidewindow'].includes(this.container_type))
- this.container.setSubtitle(val);
- return this;
- }
-
- onMenuClick (e) {
- this.toggleMenu();
- }
-
- toggleMenu () {
- this.asset_list.classList.toggle("open");
- }
-
- setAssetList (list, context_menu, on_menu_click) {
- var this_ref = this;
-
- // clear list
- this.asset_list.innerHTML = "";
-
- // context menu
- var menu = new elec.Menu();
- context_menu.forEach(function(m){
- var item = new elec.MenuItem(m);
- item.click = function() { on_menu_click(this.label, this_ref.list_value); }
- menu.append(item);
- });
-
- // add asset buttons
- for (var l = 0; l < list.length; l++) {
- let el_asset = this.app.createElement("button", "asset");
- el_asset.innerHTML = list[l];
- el_asset.onclick = function() {
- this_ref.toggleMenu();
- if (this_ref.onAssetSelect) this_ref.onAssetSelect(this.innerHTML);
- }
- el_asset.addEventListener('contextmenu', function(ev) {
- ev.preventDefault();
- menu.popup(ev.x, ev.y);
- this_ref.list_value = ev.target.innerHTML;
- return false;
- });
-
- this.asset_list.appendChild(el_asset);
- }
- }
+ constructor() {
+ this.app = app;
+ this.closed = false;
+
+ // asset list
+ this.asset_list = document.createElement("div");
+ this.asset_list.classList.add("asset-list");
+
+ // real content area
+ this.content_area = document.createElement("div");
+ this.content_area.classList.add("editor-content");
+ }
+
+ setupPopup(content) {
+ this.container_type = "dragbox";
+ // create drag box
+ this.container = new DragBox(content || this.constructor.name);
+ }
+
+ setupDragbox(content) {
+ this.container_type = "dragbox";
+ // create drag box
+ this.container = new DragBox(content || this.constructor.name);
+ this.container.appendTo(workspace);
+ this.container.width = 400;
+ this.container.height = 300;
+ this.container.drag_container.appendChild(this.asset_list);
+ this.container.appendChild(this.content_area);
+ // menu button click
+ this.container.btn_menu.onclick = e => {
+ this.onMenuClick(e);
+ };
+ this.container.onClose = (...args) => this.onClose(...args);
+ this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
+ app.refreshQuickAccess();
+ return this;
+ }
+
+ setupTab(content) {
+ var this_ref = this;
+ this.container_type = "tab";
+ // create tab
+ this.container = new Tab(content || this.constructor.name);
+ this.container.appendChild(this.content_area);
+ app.setHistoryActive(this.container.history_id, true);
+ app.setHistoryContextMenu(this.container.history_id, function (e) {
+ this_ref.onMenuClick(e);
+ });
+ this.container.onClose = (...args) => {
+ this.onClose(...args);
+ app.refreshQuickAccess();
+ };
+ this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
+ app.refreshQuickAccess();
+ return this;
+ }
+
+ setupFibWindow(content) {
+ var this_ref = this;
+ this.container_type = "fibwindow";
+ this.container = new FibWindow(
+ typeof content == "string" ? content : this.constructor.name
+ );
+ this.container.appendTo(workspace);
+ this.container.appendChild(this.content_area);
+ this.container.btn_menu.onclick = function (e) {
+ this_ref.onMenuClick(e);
+ };
+ app.setHistoryActive(this.container.history_id, true);
+ app.setHistoryContextMenu(this.container.history_id, function (e) {
+ this_ref.onMenuClick(e);
+ });
+ this.container.onClose = (...args) => {
+ this.onClose(...args);
+ app.refreshQuickAccess();
+ };
+ this.container.onBeforeClose = (...args) => this.onBeforeClose(...args);
+ app.refreshQuickAccess();
+ return this;
+ }
+
+ setupSideWindow(transparent, content) {
+ let this_ref = this;
+ this.container_type = "sidewindow";
+ this.container = new SideWindow(content || this.constructor.name);
+ this.container.appendChild(this.content_area);
+ this.container.btn_menu.onclick = function (e) {
+ this_ref.onMenuClick(e);
+ };
+ app.setHistoryActive(this.container.history_id, true);
+ app.setHistoryContextMenu(this.container.history_id, function (e) {
+ this_ref.onMenuClick(e);
+ });
+ this.container.onClose = (...args) => {
+ this.onClose(...args);
+ app.refreshQuickAccess();
+ };
+ if (transparent) this.container.el_container.classList.add("transparent");
+ app.refreshQuickAccess();
+ return this;
+ }
+
+ setupMenu(opt) {
+ let items = [];
+ if (!opt.file_key) opt.file_key = "file";
+
+ if (opt.close) {
+ items.push({
+ label: "close",
+ click: () => {
+ this.close();
+ },
+ });
+ }
+
+ // file_key='file' : where filename is stored
+ // rename : callback when file is renamed
+ if (opt.rename) {
+ items.push({
+ label: "rename",
+ click: () => {
+ let full_path = this[opt.file_key];
+ let filename = nwPATH.basename(full_path);
+ let ext = nwPATH.extname(filename);
+ blanke.showModal(
+ "" +
+ "",
+ {
+ yes: () => {
+ let new_path = nwPATH.join(
+ nwPATH.dirname(full_path),
+ app.getElement("#new-file-name").value + ext
+ );
+ app.renameSafely(full_path, new_path, (success, err) => {
+ if (success) {
+ this[opt.file_key] = app.cleanPath(new_path);
+ if (typeof opt.rename == "function")
+ opt.rename(new_path, full_path);
+ } else
+ blanke.toast(
+ "could not rename '" +
+ nwPATH.basename(full_path) +
+ "' (" +
+ err +
+ ")"
+ );
+ });
+ },
+ no: () => {},
+ }
+ );
+ },
+ });
+ }
+
+ // file_key='file'
+ // delete
+ if (opt.delete) {
+ items.push({
+ label: "delete",
+ click: () => {
+ blanke.showModal(
+ "delete '" + nwPATH.basename(this[opt.file_key]) + "'?",
+ {
+ yes: () => {
+ this.deleted = true;
+ nwFS.remove(this[opt.file_key]);
+ if (typeof opt.delete == "function") opt.delete();
+ },
+ no: () => {},
+ }
+ );
+ },
+ });
+ }
+
+ this.onMenuClick = e => {
+ let items_copy = [...items];
+ if (opt.extra) items_copy = items_copy.concat(opt.extra());
+ app.contextMenu(e.x, e.y, items_copy);
+ };
+ }
+
+ removeHistory() {
+ if (this.container) app.removeHistory(this.container.history_id);
+ }
+
+ setOnClick() {
+ let fn = arguments;
+ if (this.container_type != "tab") fn = arguments[0];
+ let old_fn = fn;
+
+ if (["tab", "fibwindow", "sidewindow"].includes(this.container_type))
+ fn = (...args) => {
+ app.refreshQuickAccess(this.getTitle());
+ if (this.container.onTabFocus) this.container.onTabFocus();
+ old_fn(...args);
+ };
+
+ if (this.container_type == "tab")
+ this.container.setOnClick.apply(this.container, fn);
+ if (this.container_type == "fibwindow")
+ app.setHistoryClick(this.container.history_id, fn);
+ if (this.container_type == "sidewindow")
+ app.setHistoryClick(this.container.history_id, fn);
+ }
+
+ onBeforeClose(res) {
+ res();
+ }
+ onClose() {}
+
+ close(...args) {
+ let real_close = () => {
+ app.setHistoryActive(this.container.history_id, false);
+ this.container.close(...args);
+ if (this.onClose) this.onClose();
+ this.closed = true;
+ };
+ if (this.onBeforeClose) {
+ // return TRUE to prevent closing
+ new Promise((res, rej) => this.onBeforeClose(res, rej)).then(
+ real_close,
+ () => {}
+ );
+ } else real_close();
+ }
+
+ static closeAll(type) {
+ DragBox.closeAll(type);
+ Tab.closeAll(type);
+ FibWindow.closeAll();
+ }
+
+ addCallback(cb_name, new_func) {
+ this.container[cb_name] = new_func;
+ }
+
+ getCenter() {
+ if (this.container.getCenter) return this.container.getCenter();
+ return [this.width / 2, this.height / 2];
+ }
+
+ get width() {
+ return this.container.width;
+ }
+
+ get height() {
+ return this.container.height;
+ }
+
+ set width(v) {
+ this.container.width = v;
+ }
+
+ set height(v) {
+ this.container.height = v;
+ }
+
+ get bg_width() {
+ if (this.container.in_background)
+ return app.getElement("#bg-workspace").clientWidth;
+ else return this.width;
+ }
+
+ get bg_height() {
+ if (this.container.in_background)
+ return app.getElement("#bg-workspace").clientHeight;
+ else return this.height;
+ }
+
+ hideMenuButton() {
+ if (this.container.btn_menu) this.container.btn_menu.style.display = "none";
+ }
+
+ getContent() {
+ return this.container.getContent();
+ }
+
+ getContainer() {
+ return this.container;
+ }
+
+ appendChild(el) {
+ this.content_area.appendChild(el);
+ }
+
+ appendBackground(el) {
+ if (this.container.appendBackground) this.container.appendBackground(el);
+ else this.appendChild(el);
+ }
+
+ isInBackground() {
+ return this.container.in_background == true;
+ }
+
+ getTitle(with_sub) {
+ return this.container.getTitle(with_sub);
+ }
+
+ setTitle(val) {
+ this.container.setTitle(val);
+ return this;
+ }
+
+ setSubtitle(val) {
+ if (["dragbox", "fibwindow", "sidewindow"].includes(this.container_type))
+ this.container.setSubtitle(val);
+ return this;
+ }
+
+ onMenuClick(e) {
+ this.toggleMenu();
+ }
+
+ toggleMenu() {
+ this.asset_list.classList.toggle("open");
+ }
+
+ setAssetList(list, context_menu, on_menu_click) {
+ var this_ref = this;
+
+ // clear list
+ this.asset_list.innerHTML = "";
+
+ // context menu
+ var menu = new Menu();
+ context_menu.forEach(function (m) {
+ var item = new MenuItem(m);
+ item.click = function () {
+ on_menu_click(this.label, this_ref.list_value);
+ };
+ menu.append(item);
+ });
+
+ // add asset buttons
+ for (var l = 0; l < list.length; l++) {
+ let el_asset = this.app.createElement("button", "asset");
+ el_asset.innerHTML = list[l];
+ el_asset.onclick = function () {
+ this_ref.toggleMenu();
+ if (this_ref.onAssetSelect) this_ref.onAssetSelect(this.innerHTML);
+ };
+ el_asset.addEventListener("contextmenu", function (ev) {
+ ev.preventDefault();
+ menu.popup(ev.x, ev.y);
+ this_ref.list_value = ev.target.innerHTML;
+ return false;
+ });
+
+ this.asset_list.appendChild(el_asset);
+ }
+ }
}
-document.addEventListener("openProject", function(e){
- Editor.closeAll();
-});
\ No newline at end of file
+document.addEventListener("openProject", function (e) {
+ Editor.closeAll();
+});
diff --git a/src/js/exporter.js b/src/js/exporter.js
index 73ebeda7..0bd1e5d2 100644
--- a/src/js/exporter.js
+++ b/src/js/exporter.js
@@ -1,7 +1,7 @@
var re_resolution = /resolution[\s=]*(?:(\d+)|{([\d\s]+),([\s\d]+)})/;
const DEFAULT_EXPORT_SETTINGS = () => ({
- name: nwPATH.basename(app.project_path),
- /*
+ name: nwPATH.basename(app.project_path),
+ /*
web_autoplay: false,
scale_mode: 'linear',
frameless: false,
@@ -11,72 +11,76 @@ const DEFAULT_EXPORT_SETTINGS = () => ({
});
class Exporter extends Editor {
- constructor (...args) {
- super(...args);
- let this_ref = this;
-
- if (DragBox.focus('Exporter')) return;
-
- this.setupDragbox();
- this.setTitle('Exporter');
- this.removeHistory();
- this.hideMenuButton();
-
- this.container.width = 384;
- this.container.height = 112;
-
- // diplay list of target platforms
- this.platforms = Object.keys(app.engine.export_targets || []);
-
- this.el_platforms = app.createElement("div","platforms");
- let el_title1 = app.createElement("p","title1");
- el_title1.innerHTML = "One-click export";
- this.el_platforms.appendChild(el_title1);
-
- this.platforms.forEach(function(platform){
- let el_platform_container = app.createElement("button",["ui-button-rect","platform",platform]);
- el_platform_container.title = platform;
-
- let el_platform_icon = app.createElement("object");
- el_platform_icon.type = "image/svg+xml";
- el_platform_icon.data = "icons/"+platform+".svg";
-
- el_platform_container.value = platform;
- el_platform_container.addEventListener('click', function(e){
- this_ref.export(e.target.value);
- });
-
- el_platform_container.appendChild(el_platform_icon);
- this_ref.el_platforms.appendChild(el_platform_container);
- });
-
- this.appendChild(this.el_platforms);
-
- }
-
- // dir : target directory to write bundled files to
- bundle (dir, target_os, cb_done) {
- if (app.engine.bundle)
- app.engine.bundle(dir, target_os, cb_done);
- }
-
- static openDistFolder(os) {
- let path = nwPATH.join(app.project_path,"dist",os);
- elec.remote.shell.openItem(path);
- elec.remote.clipboard.writeText(path);
- }
-
- doneToast (os) {
- process.noAsar = false;
- if (this.temp_dir)
- nwFS.removeSync(this.temp_dir);
- if (this.toast) {
- this.toast.icon = 'check-bold';
- this.toast.style = 'good';
- this.toast.text = "Export done! View files";
- this.toast.die(8000);
-
- /*
+ constructor(...args) {
+ super(...args);
+ let this_ref = this;
+
+ if (DragBox.focus("Exporter")) return;
+
+ this.setupDragbox();
+ this.setTitle("Exporter");
+ this.removeHistory();
+ this.hideMenuButton();
+
+ this.container.width = 384;
+ this.container.height = 112;
+
+ // diplay list of target platforms
+ this.platforms = Object.keys(app.engine.export_targets || []);
+
+ this.el_platforms = app.createElement("div", "platforms");
+ let el_title1 = app.createElement("p", "title1");
+ el_title1.innerHTML = "One-click export";
+ this.el_platforms.appendChild(el_title1);
+
+ this.platforms.forEach(function (platform) {
+ let el_platform_container = app.createElement("button", [
+ "ui-button-rect",
+ "platform",
+ platform,
+ ]);
+ el_platform_container.title = platform;
+
+ let el_platform_icon = app.createElement("object");
+ el_platform_icon.type = "image/svg+xml";
+ el_platform_icon.data = "icons/" + platform + ".svg";
+
+ el_platform_container.value = platform;
+ el_platform_container.addEventListener("click", function (e) {
+ this_ref.export(e.target.value);
+ });
+
+ el_platform_container.appendChild(el_platform_icon);
+ this_ref.el_platforms.appendChild(el_platform_container);
+ });
+
+ this.appendChild(this.el_platforms);
+ }
+
+ // dir : target directory to write bundled files to
+ bundle(dir, target_os, cb_done) {
+ if (app.engine.bundle) app.engine.bundle(dir, target_os, cb_done);
+ }
+
+ static openDistFolder(os) {
+ let path = nwPATH.join(app.project_path, "dist", os);
+ remote.shell.openItem(path);
+ remote.clipboard.writeText(path);
+ }
+
+ doneToast(os) {
+ process.noAsar = false;
+ if (this.temp_dir) nwFS.removeSync(this.temp_dir);
+ if (this.toast) {
+ this.toast.icon = "check-bold";
+ this.toast.style = "good";
+ this.toast.text =
+ "Export done! View files";
+ this.toast.die(8000);
+
+ /*
app.notify({
title: 'Export complete!',
body: `\\( ^o^ )/`,
@@ -84,31 +88,30 @@ class Exporter extends Editor {
Exporter.openDistFolder(os);
}
})*/
- }
- }
-
- errToast () {
- process.noAsar = false;
- if (this.temp_dir)
- nwFS.removeSync(this.temp_dir);
-
- if (this.toast) {
- this.toast.icon = 'close';
- this.toast.style = 'bad';
- this.toast.text = "Export failed!";
- this.toast.die(8000);
-
- app.notify({
- title: 'Export failed!',
- body: `( -_-")`,
- onclick: () => {
- Exporter.openDistFolder(os);
- }
- })
- }
- }
-
- /*
+ }
+ }
+
+ errToast() {
+ process.noAsar = false;
+ if (this.temp_dir) nwFS.removeSync(this.temp_dir);
+
+ if (this.toast) {
+ this.toast.icon = "close";
+ this.toast.style = "bad";
+ this.toast.text = "Export failed!";
+ this.toast.die(8000);
+
+ app.notify({
+ title: "Export failed!",
+ body: `( -_-")`,
+ onclick: () => {
+ Exporter.openDistFolder(os);
+ },
+ });
+ }
+ }
+
+ /*
darwin
- darwin-x64
linux
@@ -120,91 +123,111 @@ class Exporter extends Editor {
- mas-x64
*/
- export (target_os) {
- let os_dir = nwPATH.join(app.project_path,"dist",target_os);
- let temp_dir = os_dir;
-
- blanke.toast("Starting export for "+target_os);
-
- let setupBinary = (binary_list) => {
- let platforms = binary_list.reduce((a, c) => {
- let [ plat, arch ] = c.split('-');
- if (!a[plat]) a[plat] = [];
- if (!a[plat].includes(arch)) a[plat].push(arch);
- return a;
- },{});
- binary_list.forEach((c) => {
- c = c.split('-');
- if (!platforms[c[0]].includes(c[1])) platforms[c[0]].push(c[1]);
- });
- // iterate platforms
- let cb_done = () => {
- this.doneToast(target_os);
- };
- let cb_err = (err) => {
- app.error(err)
- this.errToast();
- }
- for (let platform in platforms) {
- if (app.engine.setupBinary)
- app.engine.setupBinary(os_dir, temp_dir, platform, platforms[platform], cb_done, cb_err);
- }
- }
-
- this.toast = blanke.toast('Removing old files',-1);
- this.toast.icon = 'dots-horizontal';
- this.toast.style = 'wait';
-
- process.noAsar = true;
- nwFS.emptyDir(os_dir, err => {
- if (err) {
- this.errToast();
- return console.error(err)
- }
- // move assets
- if (app.engine.export_assets !== false)
- nwFS.copySync(app.getAssetPath(), nwPATH.join(temp_dir, 'assets'));
- let e_assets = app.engine.extra_bundle_assets || {}
- let extra_assets = e_assets[target_os] || e_assets['.'] || [];
- for (let a of extra_assets) {
- a = a.replace('',app.project_path).replace('',app.ideSetting('engine_path'));
- nwFS.copySync(a, app.cleanPath(nwPATH.join(temp_dir, a)).replace(app.ideSetting('engine_path')+'/',''));
- }
-
- if (app.engine.preBundle)
- app.engine.preBundle(temp_dir, target_os);
- // create js file
- this.toast.text = `Bundling files`
- this.bundle(temp_dir, target_os, () => {
-
- let platforms = app.engine.export_targets[target_os]
-
- if (platforms === false)
- this.doneToast(target_os);
- else {
- this.toast.text = "Building app";
- setupBinary(platforms === true ? [target_os] : platforms);
- }
-
-
- });
- });
- }
+ export(target_os) {
+ let os_dir = nwPATH.join(app.project_path, "dist", target_os);
+ let temp_dir = os_dir;
+
+ blanke.toast("Starting export for " + target_os);
+
+ let setupBinary = binary_list => {
+ let platforms = binary_list.reduce((a, c) => {
+ let [plat, arch] = c.split("-");
+ if (!a[plat]) a[plat] = [];
+ if (!a[plat].includes(arch)) a[plat].push(arch);
+ return a;
+ }, {});
+ binary_list.forEach(c => {
+ c = c.split("-");
+ if (!platforms[c[0]].includes(c[1])) platforms[c[0]].push(c[1]);
+ });
+ // iterate platforms
+ let cb_done = () => {
+ this.doneToast(target_os);
+ };
+ let cb_err = err => {
+ app.error(err);
+ this.errToast();
+ };
+ for (let platform in platforms) {
+ if (app.engine.setupBinary)
+ app.engine.setupBinary(
+ os_dir,
+ temp_dir,
+ platform,
+ platforms[platform],
+ cb_done,
+ cb_err
+ );
+ }
+ };
+
+ this.toast = blanke.toast("Removing old files", -1);
+ this.toast.icon = "dots-horizontal";
+ this.toast.style = "wait";
+
+ process.noAsar = true;
+ nwFS.emptyDir(os_dir, err => {
+ if (err) {
+ this.errToast();
+ return console.error(err);
+ }
+ // move assets
+ if (app.engine.export_assets !== false)
+ nwFS.copySync(app.getAssetPath(), nwPATH.join(temp_dir, "assets"));
+ let e_assets = app.engine.extra_bundle_assets || {};
+ let extra_assets = e_assets[target_os] || e_assets["."] || [];
+ for (let a of extra_assets) {
+ a = a
+ .replace("", app.project_path)
+ .replace("", app.ideSetting("engine_path"));
+ nwFS.copySync(
+ a,
+ app
+ .cleanPath(nwPATH.join(temp_dir, a))
+ .replace(app.ideSetting("engine_path") + "/", "")
+ );
+ }
+
+ if (app.engine.preBundle) app.engine.preBundle(temp_dir, target_os);
+ // create js file
+ this.toast.text = `Bundling files`;
+ this.bundle(temp_dir, target_os, () => {
+ let platforms = app.engine.export_targets[target_os];
+
+ if (platforms === false) this.doneToast(target_os);
+ else {
+ this.toast.text = "Building app";
+ setupBinary(platforms === true ? [target_os] : platforms);
+ }
+ });
+ });
+ }
}
-document.addEventListener("openProject", function(e){
- app.removeSearchGroup("Exporter");
- app.addSearchKey({key: 'Export game', group:"Exporter", onSelect: function() {
- new Exporter(app);
- }});
-
- let eng_settings = {};
- (app.engine.export_settings || []).forEach(s => {
- for (let prop of s) {
- if (typeof(prop) == "object" && prop.default)
- eng_settings[s[0]] = prop.default;
- }
- });
-
- app.projSetting("export",Object.assign(DEFAULT_EXPORT_SETTINGS(), eng_settings, app.projSetting("export")))
+document.addEventListener("openProject", function (e) {
+ app.removeSearchGroup("Exporter");
+ app.addSearchKey({
+ key: "Export game",
+ group: "Exporter",
+ onSelect: function () {
+ new Exporter(app);
+ },
+ });
+
+ let eng_settings = {};
+ (app.engine.export_settings || []).forEach(s => {
+ for (let prop of s) {
+ if (typeof prop == "object" && prop.default)
+ eng_settings[s[0]] = prop.default;
+ }
+ });
+
+ app.projSetting(
+ "export",
+ Object.assign(
+ DEFAULT_EXPORT_SETTINGS(),
+ eng_settings,
+ app.projSetting("export")
+ )
+ );
});
diff --git a/src/main.js b/src/main.js
index cc09e61b..e26a622f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -19,7 +19,7 @@ C sceneeditor: image search keys still remain after closing scene editor
C sceneeditor: re-opening opens 3 instances
*/
const elec = require("electron");
-const { remote } = elec;
+const { remote, shell, ipcRenderer } = elec;
var fs = require("fs").promises;
var nwFS = require("fs-extra");
@@ -74,6 +74,10 @@ var app = {
return remote.getCurrentWindow();
},
+ get renderer() {
+ return ipcRenderer;
+ },
+
get size() {
return app.window.getSize();
},
@@ -1370,7 +1374,7 @@ var app = {
{
yes: function () {
if (manual)
- elec.shell.openExternal("https://xhh.itch.io/blanke");
+ shell.openExternal("https://xhh.itch.io/blanke");
else app.update(latest_version);
},
no: function () {},
@@ -1501,7 +1505,7 @@ document.addEventListener("click", function (event) {
if (event.target.tagName === "A") {
event.preventDefault();
if (event.target.href.startsWith("http")) {
- elec.shell.openExternal(event.target.href);
+ shell.openExternal(event.target.href);
}
}
});
@@ -1763,7 +1767,7 @@ app.window.webContents.once("dom-ready", () => {
active: function () {},
});
- elec.ipcRenderer.on("close", (e, arg) => {
+ app.renderer.on("close", (e, arg) => {
if (app.isProjectOpen()) {
blanke.showModal("", {
yes: function () {
@@ -1899,7 +1903,7 @@ app.window.webContents.once("dom-ready", () => {
// app.openProject('projects/test zone');
setTimeout(() => {
- app.window.show();
+ app.renderer.send("showWindow");
}, 500);
});
});