Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 77ead26

Browse files
Merge pull request #12 from hackforplay/textarea
Textarea
2 parents 1c9e937 + f95f4c1 commit 77ead26

File tree

3 files changed

+583
-5
lines changed

3 files changed

+583
-5
lines changed

src/hackforplay/hack.js

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'hackforplay/enchantjs-kit';
2-
2+
import TextArea from 'hackforplay/ui/textarea';
33

44
function refocus() {
55
window.document.activeElement.blur(); // Blur an enchantBook
@@ -33,6 +33,7 @@ Hack.fun2str = function(func) {
3333
return '';
3434
};
3535

36+
// 【旧ログ機能】
3637
// textarea : 画面全体をおおう半透明のテキストエリア(DOM)
3738
Hack.textarea = (function() {
3839
// scope: new Entity
@@ -78,6 +79,18 @@ Hack.textarea = (function() {
7879

7980
}).call(new enchant.Entity());
8081

82+
// canvas のテキストエリアを生成
83+
const textArea = new TextArea(380, 60);
84+
textArea.moveTo(60, 5);
85+
textArea.verticalNormalizedPosition = 1;
86+
textArea.autoResizeVertical = true;
87+
textArea.maxHeight = 310;
88+
Hack.textArea = textArea;
89+
game.on('awake', () => {
90+
Hack.menuGroup.addChild(textArea);
91+
});
92+
93+
// 画面に文字を表示する(次の行に追加)
8194
Hack.log = function() {
8295
try {
8396
var values = [];
@@ -91,16 +104,24 @@ Hack.log = function() {
91104
break;
92105
}
93106
}
94-
this.textarea.text = values.join(' ') + (this.textarea.text !== '' ? '\n' : '') + this.textarea.text;
95-
this.textarea.show();
96107

108+
this.textArea.push(values.join(' ') + (this.textarea.text !== '' ? '\n' : '') + this.textarea.text);
109+
this.textArea.show();
97110
} catch (e) {
98111
Hack.log('Error', e.message);
99112
}
100113
};
101114

115+
// 画面に文字を表示する(上書き)
116+
Hack.show = function () {
117+
Hack.textArea.clear();
118+
Hack.log.apply(this, arguments);
119+
};
120+
102121
Hack.clearLog = function() {
103-
this.textarea.text = '';
122+
Hack.textarea.text = '';
123+
Hack.textArea.clear();
124+
Hack.textArea.hide();
104125
};
105126

106127
// enchantBook
@@ -574,4 +595,4 @@ game.addEventListener('load', function() {
574595
}
575596
throw new Error('Hack.css2rgb requires CSS style string or Array of number');
576597
};
577-
})();
598+
})();

0 commit comments

Comments
 (0)