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

View File

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

View File

@ -18,7 +18,7 @@ const clipboard = require('electron').clipboard;
var saveFilepath = null;
var wsChanged = false;
var mascotFilePath = './img/cogechee.png';
var mascotFilePath = mascotDefPath + 'cogechee.png';
// 0で数値の桁合わせ
// NUM=値 LEN=桁数
@ -204,7 +204,7 @@ exports.addChild = (child) => {
}
// 全ての子プロセスを殺し、配列をクリア
exports.killAllChildren = () => {
children.forEach(function( child ) {
children.forEach(function (child) {
child.kill();
});
children = [];
@ -216,17 +216,19 @@ exports.savePrefsToLS = () => {
if (wsChanged) wc = '1';
let o = { 'saveFilepath': saveFilepath, 'wsChanged': wc, 'mascotFilePath': mascotFilePath };
let s = JSON.stringify(o);
localStorage.setItem("abrage.json", s);
localStorage.setItem("ocoge.json", s);
}
// 設定(保存ファイルパスと未保存フラグ)をローカルストレージからロード
exports.loadPrefsFromLS = () => {
let s = localStorage.getItem("abrage.json");
let s = localStorage.getItem("ocoge.json");
if (s !== null) {
let o = JSON.parse(s);
setSaveFilepath(o.saveFilepath);
if (o.wsChanged == '0') this.setWsChanged(false);
else this.setWsChanged(true);
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 ctx = el.getContext('2d');
ctx.fillStyle = 'rgb(255,255,255)';
ctx.fillRect(0,0,480,360);
ctx.fillRect(0, 0, 480, 360);
let img = new Image();
img.src = imgSrc;
img.onload = () => {
if (x<0) { //センタリング
if (x < 0) { //センタリング
let w = img.width;
if (w>=480) x=0;
if (w >= 480) x = 0;
else x = Math.floor((480 - w) / 2);
}
if (y<0) { //縦中寄せ
if (y < 0) { //縦中寄せ
let h = img.height;
if (h>=360) y=0;
else y = Math.floor((360 - h) /2);
if (h >= 360) y = 0;
else y = Math.floor((360 - h) / 2);
}
ctx.drawImage(img, x, y);
}
@ -220,15 +220,17 @@ const ugj_saveWorkspace = () => {
// Workspace
let xml = Blockly.Xml.workspaceToDom(workspace);
let xml_text = Blockly.Xml.domToText(xml);
localStorage.setItem("abrage.xml", xml_text);
localStorage.setItem("ocoge.xml", xml_text);
}
const ugj_loadWorkspace = () => {
// Workspace
let xml_text = localStorage.getItem("abrage.xml");
let xml_text = localStorage.getItem("ocoge.xml");
if (xml_text !== null) {
if (xml_text.length != 0) {
let xml = Blockly.Xml.textToDom(xml_text);
Blockly.Xml.domToWorkspace(xml, workspace);
}
}
}
// ワークスペースからコードを生成して必要であれば整形処理をする
@ -507,7 +509,7 @@ window.onload = () => {
workspace.addChangeListener(ugj_wsUpdateCB);
}, 100);
// 背景canvas
ugj_canvasBgImg(elec.getMascotFilePath(), -1,-1);
ugj_canvasBgImg(elec.getMascotFilePath(), -1, -1);
}
window.onbeforeunload = () => {
ugj_saveWorkspace();