Commit 93a5aa83 authored by 范雪寒's avatar 范雪寒

feat: 音效

parent 05b2f43e
......@@ -128,5 +128,8 @@
}
}
},
"defaultProject": "ng-template-generator"
}
"defaultProject": "ng-template-generator",
"cli": {
"analytics": false
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -55,4 +55,4 @@
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
}
\ No newline at end of file
}
<div class="model-content">
<div style="padding: 10px;">
<div style="width: 300px;" align='center'>
<span>图1: </span>
<app-upload-image-with-preview
[picUrl]="item.pic_url"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')">
</app-upload-image-with-preview>
<div class="model-content, border">
<div *ngFor="let question of item.questionList; let i = index">
<div class="border">
<button style="color: red; width: 50px; float: right;" nz-button nzType="dashed" class="add-btn"
(click)="removeQuestion(i)">
X
</button>
<span style="height: 30px; font-size: 18px;">第{{i+1}}题:</span>
<br>
<span style="height: 30px; font-size: 18px;">问题音频:</span>
<app-audio-recorder [audioUrl]="question.questionAudio" (audioUploaded)="onQuestionAuidoUploadSuccess($event, i)">
</app-audio-recorder>
<br>
<span style="height: 30px; font-size: 18px; float: left;">候选答案:</span>
<br><br>
<div *ngFor="let answer of question.answerList; let j = index">
<div class="border" style="width: 280px; float: left;">
<button style="color: red; width: 50px; float: right;" nz-button nzType="dashed" class="add-btn"
(click)="removeAnswer(i, j)">
X
</button>
<br>
<nz-radio-group style="margin-left: 30px; margin-bottom: 10px;" [ngModel]="answer.answerType"
(ngModelChange)="radioChange($event, i, j)">
<span nz-radio nzValue="img" style="height: 30px; font-size: 18px;">图片</span>
<span nz-radio nzValue="txt" style="height: 30px; font-size: 18px;">文本</span>
</nz-radio-group>
<div *ngIf="answer.answerType=='img'" style="width: 200px;">
<app-upload-image-with-preview [picUrl]="answer.answerImg"
(imageUploaded)="onAnswerImageUploadSuccess($event, i, j)">
</app-upload-image-with-preview>
</div>
<div *ngIf="answer.answerType=='txt'">
<input type="text" style="width: 200px;" nz-input [(ngModel)]="answer.answerTxt"
(blur)="save()">
</div>
<br>
<button *ngIf="answer.rightAnswer"
style="color: green; border-color: green; font-size: 18px; width: 90px; height: 50px;" nz-button
nzType="dashed">
&nbsp;
</button>
<button *ngIf="!answer.rightAnswer" style="font-size: 18px; width: 90px; height: 50px;" nz-button
nzType="dashed" (click)="setAnswerRight(i, j, true)">
&nbsp;
</button>
<button *ngIf="!answer.rightAnswer"
style="color: red; border-color: red; font-size: 18px; width: 90px; height: 50px; margin-left: 20px;"
nz-button nzType="dashed">
&nbsp;
</button>
<button *ngIf="answer.rightAnswer" style="font-size: 18px; width: 90px; height: 50px; margin-left: 20px;"
nz-button nzType="dashed" (click)="setAnswerRight(i, j, false)">
&nbsp;
</button>
<br>
<div *ngIf="answer.rightAnswer">
<span style="height: 30px; font-size: 18px;">音频:</span>
<app-audio-recorder [audioUrl]="answer.answerAudio" (audioUploaded)="onAnswerAuidoUploadSuccess($event, i, j)">
</app-audio-recorder>
</div>
</div>
</div>
<button style="width: 280px; height: 200px; float: left; margin: 20px;" nz-button nzType="dashed" class="add-btn"
(click)="addAnswer(i)">
Add Answer
</button>
<div style="clear:both;">&nbsp;</div>
</div>
<div style="width: 300px; margin-top: 5px;" align='center'>
<span>图2: </span>
<app-upload-image-with-preview
[picUrl]="item.pic_url_2"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url_2')">
</app-upload-image-with-preview>
</div>
<div style="width: 300px; margin-top: 15px;">
<span>文本: </span>
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()">
</div>
<div style="margin-top: 5px">
<span>音频: </span>
<app-audio-recorder
[audioUrl]="item.audio_url"
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')"
></app-audio-recorder>
</div>
</div>
</div>
<button style="width: 100%; height: 100px; align-self: center;" nz-button nzType="dashed" class="add-btn" (click)="addQuestion()">
Add
</button>
</div>
\ No newline at end of file
......@@ -10,7 +10,7 @@ import { JsonPipe } from '@angular/common';
export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用
saveKey = "test_001";
saveKey = "dfzx_cocos_dqq";
// 储存对象
item;
......@@ -18,24 +18,73 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}
createShell() {
this.item.wordList.push({
word: '',
audio: '',
backWord: '',
backWordAudio: '',
addQuestion() {
this.item.questionList.push({
questionAudio: '',
speedLevel: 2,
rigthNumber: 5,
answerList: []
});
this.save();
}
removeShell(idx) {
this.item.wordList.splice(idx, 1);
removeQuestion(idx) {
this.item.questionList.splice(idx, 1);
console.log('汪汪汪');
this.save();
}
addAnswer(idx) {
this.item.questionList[idx].answerList.push({
answerAudio: '',
answerTxt: '',
answerImg: '',
answerType: 'img',
rightAnswer: false
});
this.save();
}
removeAnswer(questionIdx, answerIdx) {
this.item.questionList[questionIdx].answerList.splice(answerIdx, 1);
this.save();
}
onAnswerAuidoUploadSuccess(e, questionIdx, answerIdx) {
this.item.questionList[questionIdx].answerList[answerIdx].answerAudio = e.url;
this.save();
}
onAnswerImageUploadSuccess(e, questionIdx, answerIdx) {
this.item.questionList[questionIdx].answerList[answerIdx].answerImg = e.url;
this.save();
}
removeAnswerImage(questionIdx, answerIdx) {
this.item.questionList[questionIdx].answerList[answerIdx].answerImg = '';
this.save();
}
setAnswerRight(questionIdx, answerIdx, right) {
this.item.questionList[questionIdx].answerList[answerIdx].rightAnswer = right;
this.save();
}
onQuestionAuidoUploadSuccess(e, questionIdx) {
this.item.questionList[questionIdx].questionAudio = e.url;
this.save();
}
radioChange(event, questionIdx, answerIdx) {
this.item.questionList[questionIdx].answerList[answerIdx].answerType = event;
this.save();
}
ngOnInit() {
this.item = {};
this.item = {
questionList: []
};
// 获取存储的数据
(<any>window).courseware.getData((data) => {
......@@ -82,16 +131,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.save();
}
onWordAudioUploadSuccess(e, idx) {
this.item.wordList[idx].audio = e.url;
this.save();
}
onBackWordAudioUploadSuccess(e, idx) {
this.item.wordList[idx].backWordAudio = e.url;
this.save();
}
/**
* 储存数据
*/
......@@ -99,6 +138,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
(<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
console.log('this.item = ' + JSON.stringify(this.item));
}
......
{
"ver": "2.0.1",
"uuid": "f48aa8fc-dd6e-49ad-8b72-40bf901d9a67",
"downloadMode": 0,
"duration": 0.971833,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "0181b1e4-8035-4088-be16-cf6e2ef9496e",
"downloadMode": 0,
"duration": 0.130612,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "f09f60df-1444-493d-b370-1e0aade49adc",
"downloadMode": 0,
"duration": 4.04898,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "174b36d7-c27d-406a-a644-0cb3f9a88361",
"downloadMode": 0,
"duration": 0.548571,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "fdbbed58-de4a-4cc4-bb3f-6545af8ce922",
"downloadMode": 0,
"duration": 0.600816,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "cdbd6195-cae1-4059-92a9-c0e4125f780c",
"downloadMode": 0,
"duration": 2.115917,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "75ad4844-8b58-4bc3-ba71-96c7382a0466",
"downloadMode": 0,
"duration": 1.102625,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "688eefd5-14a6-42fe-8b27-f71c35999544",
"downloadMode": 0,
"duration": 1.776327,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "45d91d76-ca0d-47fd-8a67-6f51f198b7bc",
"downloadMode": 0,
"duration": 0.264,
"subMetas": {}
}
\ No newline at end of file
import { onHomeworkFinish } from "./util";
import { defaultData } from '../script/defaultData.js';
import {
addBtnListener,
......@@ -12,7 +11,8 @@ import {
jelly,
playAudioByUrl,
playAudioByUrlSync,
RandomInt
RandomInt,
onHomeworkFinish,
} from "../script/util";
cc.Class({
......@@ -299,7 +299,7 @@ cc.Class({
createBall(answer) {
let ball = null;
if (answer.answerImg) {
if (answer.answerType == 'img') {
ball = this.createImgBall(answer);
} else {
ball = this.createTextBall(answer);
......@@ -317,6 +317,10 @@ cc.Class({
.start();
ball.on('touchstart', async (event) => {
if (ball.canNotTouch) {
return;
}
ball.canNotTouch = true;
const location = event.getLocation();
await this.shootTarget(ball, location, true);
if (answer.rightAnswer) {
......@@ -333,6 +337,7 @@ cc.Class({
if (this.isEndGame()) {
this.onGameEnd();
} else {
await this.playQuestionAudio();
this.startShowBalls();
}
}
......@@ -472,4 +477,10 @@ cc.Class({
await asyncTweenBy(node, 0.05, { x: offsetX, y: offsetY });
await asyncTweenTo(node, 0.05, { x: x });
},
async playAudio(audioName) {
const audioNode = cc.find(`AudioBase/${audioName}`);
const audioClip = audioNode.getComponent(cc.AudioSource).clip;
cc.audioEngine.play(audioClip, false, 0.8);
}
});
export const defaultData = {
questionList: [{
questionAudio: 'http://staging-teach.cdn.ireadabc.com/989f78ee25c48624047f9f0275eb4193.mp3',
speedLevel: 2,
rigthNumber: 5,
answerList: [{
answerAudio: '',
answerTxt: 'cat',
answerImg: 'http://staging-teach.cdn.ireadabc.com/d87dd698252e6f2c53d0e8c761b065c5.png',
rightAnswer: true
}, {
answerAudio: '',
answerTxt: 'cet',
answerImg: '',
rightAnswer: false
}, {
answerAudio: '',
answerTxt: 'ket',
answerImg: '',
rightAnswer: false
}, {
answerAudio: '',
answerTxt: 'oet',
answerImg: '',
rightAnswer: false
"questionList": [{
"questionAudio": "http://staging-teach.cdn.ireadabc.com/b44fa51172b19b555fda30717c773027.mp3",
"speedLevel": 2,
"rigthNumber": 5,
"answerList": [{
"answerAudio": "http://staging-teach.cdn.ireadabc.com/b44fa51172b19b555fda30717c773027.mp3",
"answerTxt": "cat",
"answerImg": "",
"answerType": "txt",
"rightAnswer": true
},
{
"answerAudio": "",
"answerTxt": "cet",
"answerImg": "",
"answerType": "txt",
"rightAnswer": false
},
{
"answerAudio": "http://staging-teach.cdn.ireadabc.com/b44fa51172b19b555fda30717c773027.mp3",
"answerTxt": "",
"answerImg": "http://staging-teach.cdn.ireadabc.com/8c6fef67a0095c2564e8df4b536fc540.png",
"answerType": "img",
"rightAnswer": true
},
{
"answerAudio": "",
"answerTxt": "cot",
"answerImg": "",
"answerType": "txt",
"rightAnswer": false
},
{
"answerAudio": "",
"answerTxt": "",
"answerImg": "http://staging-teach.cdn.ireadabc.com/3dc45b8d1403a1eae524ac5a48e5d673.png",
"answerType": "img",
"rightAnswer": false
}]
}, {
questionAudio: '',
speedLevel: 1,
rigthNumber: 5,
answerList: [{
answerAudio: '',
answerTxt: 'cat',
answerImg: '',
rightAnswer: true
}, {
answerAudio: '',
answerTxt: 'cet',
answerImg: '',
rightAnswer: false
}, {
answerAudio: '',
answerTxt: 'ket',
answerImg: '',
rightAnswer: false
}, {
answerAudio: '',
answerTxt: 'oet',
answerImg: '',
rightAnswer: false
},
{
"questionAudio": "http://staging-teach.cdn.ireadabc.com/a6a5c388c636bc6d063946e91b4bd21a.mp3",
"speedLevel": 2,
"rigthNumber": 5,
"answerList": [{
"answerAudio": "http://staging-teach.cdn.ireadabc.com/a6a5c388c636bc6d063946e91b4bd21a.mp3",
"answerTxt": "egg",
"answerImg": "",
"answerType": "txt",
"rightAnswer": true
},
{
"answerAudio": "http://staging-teach.cdn.ireadabc.com/a6a5c388c636bc6d063946e91b4bd21a.mp3",
"answerTxt": "",
"answerImg": "http://staging-teach.cdn.ireadabc.com/7b315ba7227294d63933cd659d5372fb.png",
"answerType": "img",
"rightAnswer": true
},
{
"answerAudio": "",
"answerTxt": "agg",
"answerImg": "",
"answerType": "txt",
"rightAnswer": false
},
{
"answerAudio": "",
"answerTxt": "",
"answerImg": "http://staging-teach.cdn.ireadabc.com/8c6fef67a0095c2564e8df4b536fc540.png",
"answerType": "img",
"rightAnswer": false
}]
}],
}]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment