fix no mascot at first launch

This commit is contained in:
ocogeclub 2021-02-26 20:11:24 +09:00
parent 04b5adaffb
commit e19acb4eb6
4 changed files with 527 additions and 523 deletions

18
package-lock.json generated
View File

@ -775,9 +775,9 @@
} }
}, },
"electron": { "electron": {
"version": "11.2.3", "version": "11.3.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-11.2.3.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-11.3.0.tgz",
"integrity": "sha512-6yxOc42nDAptHKNlUG/vcOh2GI9x2fqp2nQbZO0/3sz2CrwsJkwR3i3oMN9XhVJaqI7GK1vSCJz0verOkWlXcQ==", "integrity": "sha512-MhdS0gok3wZBTscLBbYrOhLaQybCSAfkupazbK1dMP5c+84eVMxJE/QGohiWQkzs0tVFIJsAHyN19YKPbelNrQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@electron/get": "^1.0.1", "@electron/get": "^1.0.1",
@ -1249,9 +1249,9 @@
} }
}, },
"globalthis": { "globalthis": {
"version": "1.0.1", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.1.tgz", "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.2.tgz",
"integrity": "sha512-mJPRTc/P39NH/iNG4mXa9aIhNymaQikTrnspeCa2ZuJ+mH2QN/rXwtX3XwKrHqWgUQFbNZKtHM105aHzJalElw==", "integrity": "sha512-ZQnSFO1la8P7auIOQECnm0sSuoMeaSq0EEdXMBFF2QJO4uNcwbyhSgG3MruWNbFTqCLmxVwGOl7LZ9kASvHdeQ==",
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
@ -1499,9 +1499,9 @@
} }
}, },
"lodash": { "lodash": {
"version": "4.17.20", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true, "dev": true,
"optional": true "optional": true
}, },

View File

@ -19,7 +19,7 @@
}, },
"homepage": "https://github.com/ocogeclub/ocoge#readme", "homepage": "https://github.com/ocogeclub/ocoge#readme",
"devDependencies": { "devDependencies": {
"electron": "11.2.3", "electron": "11.3.0",
"electron-rebuild": "^2.3.4" "electron-rebuild": "^2.3.4"
}, },
"dependencies": { "dependencies": {

View File

@ -18,7 +18,7 @@ const clipboard = require('electron').clipboard;
var saveFilepath = null; var saveFilepath = null;
var wsChanged = false; var wsChanged = false;
var mascotFilePath = './img/cogechee.png'; var mascotFilePath = mascotDefPath + 'cogechee.png';
// 0で数値の桁合わせ // 0で数値の桁合わせ
// NUM=値 LEN=桁数 // NUM=値 LEN=桁数
@ -204,7 +204,7 @@ exports.addChild = (child) => {
} }
// 全ての子プロセスを殺し、配列をクリア // 全ての子プロセスを殺し、配列をクリア
exports.killAllChildren = () => { exports.killAllChildren = () => {
children.forEach(function( child ) { children.forEach(function (child) {
child.kill(); child.kill();
}); });
children = []; children = [];
@ -216,17 +216,19 @@ exports.savePrefsToLS = () => {
if (wsChanged) wc = '1'; if (wsChanged) wc = '1';
let o = { 'saveFilepath': saveFilepath, 'wsChanged': wc, 'mascotFilePath': mascotFilePath }; let o = { 'saveFilepath': saveFilepath, 'wsChanged': wc, 'mascotFilePath': mascotFilePath };
let s = JSON.stringify(o); let s = JSON.stringify(o);
localStorage.setItem("abrage.json", s); localStorage.setItem("ocoge.json", s);
} }
// 設定(保存ファイルパスと未保存フラグ)をローカルストレージからロード // 設定(保存ファイルパスと未保存フラグ)をローカルストレージからロード
exports.loadPrefsFromLS = () => { exports.loadPrefsFromLS = () => {
let s = localStorage.getItem("abrage.json"); let s = localStorage.getItem("ocoge.json");
if (s !== null) {
let o = JSON.parse(s); let o = JSON.parse(s);
setSaveFilepath(o.saveFilepath); setSaveFilepath(o.saveFilepath);
if (o.wsChanged == '0') this.setWsChanged(false); if (o.wsChanged == '0') this.setWsChanged(false);
else this.setWsChanged(true); else this.setWsChanged(true);
if (o.mascotFilePath) this.setMascotFilePath(o.mascotFilePath); if (o.mascotFilePath) this.setMascotFilePath(o.mascotFilePath);
}
} }
// マスコット画像パスをプロパティにセット // マスコット画像パスをプロパティにセット

View File

@ -115,19 +115,19 @@ const ugj_canvasBgImg = (imgSrc, x, y) => { //x,y == -1: center or middle
let el = document.getElementById('canvas_bg'); let el = document.getElementById('canvas_bg');
let ctx = el.getContext('2d'); let ctx = el.getContext('2d');
ctx.fillStyle = 'rgb(255,255,255)'; ctx.fillStyle = 'rgb(255,255,255)';
ctx.fillRect(0,0,480,360); ctx.fillRect(0, 0, 480, 360);
let img = new Image(); let img = new Image();
img.src = imgSrc; img.src = imgSrc;
img.onload = () => { img.onload = () => {
if (x<0) { //センタリング if (x < 0) { //センタリング
let w = img.width; let w = img.width;
if (w>=480) x=0; if (w >= 480) x = 0;
else x = Math.floor((480 - w) / 2); else x = Math.floor((480 - w) / 2);
} }
if (y<0) { //縦中寄せ if (y < 0) { //縦中寄せ
let h = img.height; let h = img.height;
if (h>=360) y=0; if (h >= 360) y = 0;
else y = Math.floor((360 - h) /2); else y = Math.floor((360 - h) / 2);
} }
ctx.drawImage(img, x, y); ctx.drawImage(img, x, y);
} }
@ -220,15 +220,17 @@ const ugj_saveWorkspace = () => {
// Workspace // Workspace
let xml = Blockly.Xml.workspaceToDom(workspace); let xml = Blockly.Xml.workspaceToDom(workspace);
let xml_text = Blockly.Xml.domToText(xml); let xml_text = Blockly.Xml.domToText(xml);
localStorage.setItem("abrage.xml", xml_text); localStorage.setItem("ocoge.xml", xml_text);
} }
const ugj_loadWorkspace = () => { const ugj_loadWorkspace = () => {
// Workspace // Workspace
let xml_text = localStorage.getItem("abrage.xml"); let xml_text = localStorage.getItem("ocoge.xml");
if (xml_text !== null) {
if (xml_text.length != 0) { if (xml_text.length != 0) {
let xml = Blockly.Xml.textToDom(xml_text); let xml = Blockly.Xml.textToDom(xml_text);
Blockly.Xml.domToWorkspace(xml, workspace); Blockly.Xml.domToWorkspace(xml, workspace);
} }
}
} }
// ワークスペースからコードを生成して必要であれば整形処理をする // ワークスペースからコードを生成して必要であれば整形処理をする
@ -507,7 +509,7 @@ window.onload = () => {
workspace.addChangeListener(ugj_wsUpdateCB); workspace.addChangeListener(ugj_wsUpdateCB);
}, 100); }, 100);
// 背景canvas // 背景canvas
ugj_canvasBgImg(elec.getMascotFilePath(), -1,-1); ugj_canvasBgImg(elec.getMascotFilePath(), -1, -1);
} }
window.onbeforeunload = () => { window.onbeforeunload = () => {
ugj_saveWorkspace(); ugj_saveWorkspace();