Skip to content

Commit 972483d

Browse files
committed
Entry Js PUBLISH by v3.20201202.71
1 parent 5747074 commit 972483d

File tree

4 files changed

+592
-480
lines changed

4 files changed

+592
-480
lines changed

dist/entry.js

Lines changed: 512 additions & 405 deletions
Large diffs are not rendered by default.

dist/entry.min.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/playground/blocks/block_ai_learning.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,14 @@ module.exports = {
6969
],
7070
events: {},
7171
def: {
72-
params: [
73-
null,
74-
],
72+
params: [null],
7573
type: 'insert_data_for_test',
7674
},
7775
pyHelpDef: {
7876
params: [],
7977
type: 'insert_data_for_test',
8078
},
81-
paramsKeyMap: {
82-
},
79+
paramsKeyMap: {},
8380
class: 'ai_learning',
8481
isNotFor: ['ai_learning'],
8582
func(sprite, script) {
@@ -160,8 +157,7 @@ module.exports = {
160157
params: [],
161158
type: 'test_result',
162159
},
163-
paramsKeyMap: {
164-
},
160+
paramsKeyMap: {},
165161
class: 'ai_learning',
166162
isNotFor: ['ai_learning'],
167163
func(sprite, script) {
@@ -181,18 +177,24 @@ module.exports = {
181177
{
182178
type: 'DropdownDynamic',
183179
value: null,
184-
menuName: () => Entry.aiLearning.labels.map((name, index) => [name, index]),
180+
menuName: () => {
181+
if (Entry?.aiLearning?.labels?.length) {
182+
return Entry.aiLearning.labels.map((name, index) => [name, index]);
183+
} else {
184+
return [[Lang.Blocks.no_target, 'null']];
185+
}
186+
},
185187
needDeepCopy: true,
186188
fontSize: 11,
187189
bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,
188190
arrowColor: EntryStatic.colorSet.common.WHITE,
189191
defaultValue: (value, options) => {
190-
if(options[0] && options[0][1]){
192+
if (options[0] && options[0][1]) {
191193
return options[0][1];
192194
}
193195
return value || 0;
194-
}
195-
}
196+
},
197+
},
196198
],
197199
events: {},
198200
def: {
@@ -226,18 +228,24 @@ module.exports = {
226228
{
227229
type: 'DropdownDynamic',
228230
value: null,
229-
menuName: () => Entry.aiLearning.labels.map((name, index) => [name, index]),
231+
menuName: () => {
232+
if (Entry?.aiLearning?.labels?.length) {
233+
return Entry.aiLearning.labels.map((name, index) => [name, index]);
234+
} else {
235+
return [[Lang.Blocks.no_target, 'null']];
236+
}
237+
},
230238
needDeepCopy: true,
231239
fontSize: 11,
232240
bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,
233241
arrowColor: EntryStatic.colorSet.common.WHITE,
234242
defaultValue: (value, options) => {
235-
if(options[0] && options[0][1]){
243+
if (options[0] && options[0][1]) {
236244
return options[0][1];
237245
}
238246
return value || 0;
239-
}
240-
}
247+
},
248+
},
241249
],
242250
events: {},
243251
def: {
@@ -250,16 +258,16 @@ module.exports = {
250258
GROUP: 0,
251259
},
252260
func(sprite, script) {
253-
const group = script.getNumberValue('GROUP', script)
254-
const {labels} = Entry.aiLearning;
261+
const group = script.getNumberValue('GROUP', script);
262+
const { labels } = Entry.aiLearning;
255263
const result = Entry.aiLearning.getResult().className;
256264
return result === labels[group];
257265
},
258266
syntax: {
259267
js: [],
260268
py: [],
261269
},
262-
}
270+
},
263271
};
264272
},
265273
};

src/playground/blocks/block_ai_utilize_tts.js

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
115115
return {
116116
result: true,
117117
message: _trim(text),
118-
hash: hashCode(text),
118+
hash: hashCode(text + new Date().getTime()),
119119
};
120120
};
121121

@@ -125,49 +125,56 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
125125
* 한번에 로드가 가능하도록 매번 로더를 따로 만들어서 사용하도록 수정
126126
* https://github.com/CreateJS/PreloadJS/issues/232#issuecomment-338739115
127127
* */
128-
const read = function(args) {
129-
const { message, hash, prop, callback } = args;
130-
const tts = Entry.AI_UTILIZE_BLOCK.tts;
131-
const id = `tts-${hash}-${JSON.stringify(prop)}`;
132-
const type = createjs.LoadQueue.SOUND;
128+
const read = async function(args, isWait) {
129+
const currentInstance = new Promise((resolve, reject) => {
130+
const { message, hash, prop } = args;
131+
const tts = Entry.AI_UTILIZE_BLOCK.tts;
132+
const id = `tts-${hash}-${JSON.stringify(prop)}`;
133+
const type = createjs.LoadQueue.SOUND;
133134

134-
const soundQueue = new createjs.LoadQueue(true);
135-
soundQueue.installPlugin(createjs.Sound);
136-
soundQueue.maintainScriptOrder = true;
137-
const src = `${Entry.baseUrl}${Entry.AI_UTILIZE_BLOCK.tts.api}.mp3?${toQueryString({
138-
text: message,
139-
...prop,
140-
})}`;
141-
142-
const loadHandler = ({ currentTarget }) => {
143-
const items = currentTarget.getItems().map(({ item }) => item);
144-
tts.loadQueue = tts.loadQueue.filter((id) => {
145-
const filtered = items.find((item) => item.id === id);
146-
if (filtered) {
147-
const instance = Entry.Utils.playSound(id, filtered.prop);
148-
instance.soundType = 'tts';
149-
Entry.Utils.addSoundInstances(instance);
150-
if (filtered.callback) {
135+
const soundQueue = new createjs.LoadQueue(true);
136+
soundQueue.installPlugin(createjs.Sound);
137+
soundQueue.maintainScriptOrder = true;
138+
const src = `${Entry.baseUrl}${Entry.AI_UTILIZE_BLOCK.tts.api}.mp3?${toQueryString({
139+
text: message,
140+
...prop,
141+
})}`;
142+
const loadHandler = ({ currentTarget }) => {
143+
const items = currentTarget.getItems().map(({ item }) => item);
144+
tts.loadQueue = tts.loadQueue.filter((id) => {
145+
const filtered = items.find((item) => item.id === id);
146+
if (filtered) {
147+
const instance = Entry.Utils.playSound(id, filtered.prop);
148+
instance.soundType = 'tts';
149+
Entry.Utils.addSoundInstances(instance);
151150
const duration =
152151
instance.duration > 0 ? instance.duration : filtered.duration * 300;
153-
setTimeout(filtered.callback, duration);
152+
setTimeout(() => {
153+
resolve();
154+
}, duration);
154155
}
155-
return false;
156+
return true;
157+
});
158+
};
159+
// if Error, retry
160+
const errorHandler = async (error) => {
161+
soundQueue.removeEventListener('complete', loadHandler);
162+
soundQueue.removeEventListener('error', errorHandler);
163+
soundQueue.destroy();
164+
if (isWait) {
165+
await read(args, true);
166+
} else {
167+
read(args);
156168
}
157-
return true;
158-
});
159-
};
160-
// if Error, retry
161-
const errorHandler = (error) => {
162-
soundQueue.removeEventListener('complete', loadHandler);
163-
soundQueue.removeEventListener('error', errorHandler);
164-
soundQueue.destroy();
165-
read(args);
166-
};
167-
soundQueue.on('complete', loadHandler);
168-
soundQueue.on('error', errorHandler);
169-
soundQueue.loadFile({ id, src, type, prop, callback, duration: message.length });
170-
tts.loadQueue.push(id);
169+
};
170+
soundQueue.on('complete', loadHandler);
171+
soundQueue.on('error', errorHandler);
172+
soundQueue.loadFile({ id, src, type, prop, duration: message.length });
173+
tts.loadQueue.push(id);
174+
});
175+
if (isWait) {
176+
return await currentInstance;
177+
}
171178
};
172179

173180
return {
@@ -289,29 +296,19 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
289296
},
290297
class: 'tts',
291298
isNotFor: ['tts'],
292-
func(sprite, script) {
299+
async func(sprite, script) {
293300
const { result, message, hash } = checkText(script.getStringValue('TEXT', script));
294301
const prop = sprite.getVoiceProp();
295302
if (result) {
296-
if (!script.isPlay) {
297-
script.isPlay = true;
298-
script.playState = 1;
299-
read({
303+
await read(
304+
{
300305
message,
301306
hash,
302307
prop,
303-
callback: () => {
304-
script.playState = 0;
305-
},
306-
});
307-
return script;
308-
} else if (script.playState == 1) {
309-
return script;
310-
} else {
311-
delete script.playState;
312-
delete script.isPlay;
313-
return script.callReturn();
314-
}
308+
},
309+
true
310+
);
311+
return script.callReturn();
315312
}
316313
},
317314
syntax: {

0 commit comments

Comments
 (0)