Commit 02315afe authored by Tt's avatar Tt

1

parent aa11e4b0
/**
* 游戏数据接口定义
*/
/**
* 问题项接口
*/
export interface Question {
/** 问题类型:'txt' 或 'img' */
type: 'txt' | 'img';
/** 图片尺寸:'big' 或 'small' */
imgSize: 'big' | 'small';
/** 音频URL */
audio: string;
/** 文本内容 */
text?: string;
/** 图片URL */
image: string;
/** 时间 */
time: number | null;
/** 持续时间 */
duration?: string;
/** 音频名称 */
audioName: string;
}
/**
* 表单数据接口
*/
export interface FormData {
/** 分数 */
score: number;
/** 标题 */
title: string;
/** 问题文本 */
questionText: string;
/** 问题类型 */
questionType: string;
/** 问题文本音频 */
questionTextAudio: string;
/** 背景音频 */
bgAudio: string;
/** 背景音频名称 */
audioBgName?: string;
/** 问题列表 */
questions: Question[];
/** 类型 */
type?: number;
/** 第一部分数据 */
part_1?: any[];
/** 第二部分数据 */
part_2?: any[];
/** 第三部分数据 */
part_3?: any[];
/** 数据数组(兼容旧版数据结构) */
dataArray?: any[];
}
/**
* 位置接口
*/
export interface Position {
/** x坐标 */
x: number;
/** y坐标 */
y: number;
}
/**
* 位置映射接口
*/
export interface PositionMap {
/** 键为问题数量,值为位置数组 */
[key: string]: Position[];
}
\ No newline at end of file
...@@ -44,67 +44,39 @@ import TWEEN from "@tweenjs/tween.js"; ...@@ -44,67 +44,39 @@ import TWEEN from "@tweenjs/tween.js";
// ] // ]
// } // }
let defaultFormData: any = {"score":0,"title":"","questionText":"","questionType":"read","questionTextAudio":"","bgAudio":"","questions":[{"type":"txt","audio":"http://staging-teach.cdn.ireadabc.com/736c616e8b66a3ae03c8e8636ca46f0f.mp3","text":"","image":"http://staging-teach.cdn.ireadabc.com/bde25b1b2a7fdf976f17ae80b6a20a25.png","time":null,"duration":"","audioName":"","imgSize":"big"},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3","image":"http://staging-teach.cdn.ireadabc.com/761e1b17e16fa4674db9ad5344676bb9.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3","image":"http://staging-teach.cdn.ireadabc.com/f7a3455a80e34c8f0fe9a190381181f4.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3","image":"http://staging-teach.cdn.ireadabc.com/7b470ba3fcee2d4a97bf2ffdf5796109.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3","image":"http://staging-teach.cdn.ireadabc.com/1438d4609714ad1968f546db51067c9c.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3","image":"http://staging-teach.cdn.ireadabc.com/f372eace088da338fa10f65415890c70.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/78ba347c18b181fd4550d30bb14c90c5.mp3","image":"http://staging-teach.cdn.ireadabc.com/63a00af0b7a1d4ad38bbfd7a6363348d.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/ffdb9f038d5549c9deba6d3f92371e61.mp3","image":"http://staging-teach.cdn.ireadabc.com/ee85bdb5170fd9e54e174a7b003b9634.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3","image":"http://staging-teach.cdn.ireadabc.com/2c94dad69f2f031bf910673c0a775651.png","time":null,"audioName":""},{"type":"img","imgSize":"big","audio":"http://staging-teach.cdn.ireadabc.com/5af2246994a28e28e155e71bb8175b85.mp3","image":"http://staging-teach.cdn.ireadabc.com/5ae211fddfdede20852c41c07f69b2a1.png","time":null,"audioName":""}]} import { FormData, Position, PositionMap } from './interfaces';
/**
* 将默认表单数据转换为目标格式 let defaultFormData: FormData = {
* @param formData 原始表单数据 "score": 0,
* @returns 转换后的数据对象,包含part_1、part_2、part_3三个部分 "title": "",
*/ "questionText": "", "questionType": "read", "questionTextAudio": "",
const convertFormData = (formData) => { "bgAudio": "",
console.log('convertFormData,formData') "questions": [
// 使用统一的dataType {
const dataType = formData.dataType; "type": "txt", "audio": "http://staging-teach.cdn.ireadabc.com/736c616e8b66a3ae03c8e8636ca46f0f.mp3", "text": "", "image": "http://staging-teach.cdn.ireadabc.com/bde25b1b2a7fdf976f17ae80b6a20a25.png", "time": null, "duration": "", "audioName": "", "imgSize": "big"
}, {
// 创建结果对象 "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3", "image": "http://staging-teach.cdn.ireadabc.com/761e1b17e16fa4674db9ad5344676bb9.png", "time": null, "audioName": ""
const result = { }, {
title: formData.title || "", "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3", "image": "http://staging-teach.cdn.ireadabc.com/f7a3455a80e34c8f0fe9a190381181f4.png", "time": null, "audioName": ""
type: formData.type || 0, }, {
part_1: [], // 对应single相关配置 "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/7b470ba3fcee2d4a97bf2ffdf5796109.png", "time": null, "audioName": ""
part_2: [], // 对应character_0~character_4相关配置 }, {
part_3: [] // 对应character_00~character_44相关配置 "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3", "image": "http://staging-teach.cdn.ireadabc.com/1438d4609714ad1968f546db51067c9c.png", "time": null, "audioName": ""
}; }, {
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/f372eace088da338fa10f65415890c70.png", "time": null, "audioName": ""
// 处理part_1数据 (single相关配置) }, {
if (dataType.single) { "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/78ba347c18b181fd4550d30bb14c90c5.mp3", "image": "http://staging-teach.cdn.ireadabc.com/63a00af0b7a1d4ad38bbfd7a6363348d.png", "time": null, "audioName": ""
result.part_1.push({ }, {
words: dataType.single.words || "", "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ffdb9f038d5549c9deba6d3f92371e61.mp3", "image": "http://staging-teach.cdn.ireadabc.com/ee85bdb5170fd9e54e174a7b003b9634.png", "time": null, "audioName": ""
wordArr: dataType.single.wordArr || [], }, {
show: dataType.single_show !== undefined ? dataType.single_show : true, "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/2c94dad69f2f031bf910673c0a775651.png", "time": null, "audioName": ""
audio: dataType.single_audio || "" }, {
}); "type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/5af2246994a28e28e155e71bb8175b85.mp3", "image": "http://staging-teach.cdn.ireadabc.com/5ae211fddfdede20852c41c07f69b2a1.png", "time": null, "audioName": ""
} }]
// 处理part_2数据 (character_0~character_4相关配置)
for (let i = 0; i <= 4; i++) {
const key = `character_${i}`;
if (dataType[key]) {
result.part_2.push({
words: dataType[key].words || "",
wordArr: dataType[key].wordArr || [],
show: dataType[`${key}_show`] !== undefined ? dataType[`${key}_show`] : true,
audio: dataType[`${key}_audio`] || ""
});
}
}
// 处理part_3数据 (character_00~character_44相关配置)
const pairKeys = ["00", "11", "22", "33", "44"];
for (const pair of pairKeys) {
const key = `character_${pair}`;
if (dataType[key]) {
result.part_3.push({
words: dataType[key].words || "",
wordArr: dataType[key].wordArr || [],
show: dataType[`${key}_show`] !== undefined ? dataType[`${key}_show`] : true,
audio: dataType[`${key}_audio`] || ""
});
}
}
return result;
} }
const position = {
const position: PositionMap = {
"4": [{ x: 640, y: 140 }, { x: 920, y: 140 }, { x: 640, y: 387 }, { x: 920, y: 387 }], "4": [{ x: 640, y: 140 }, { x: 920, y: 140 }, { x: 640, y: 387 }, { x: 920, y: 387 }],
"6": [{ x: 604, y: 184 }, { x: 791, y: 184 }, { x: 983, y: 184 }, { x: 604, y: 364 }, { x: 791, y: 364 }, { x: 983, y: 364 }], "6": [{ x: 604, y: 184 }, { x: 791, y: 184 }, { x: 983, y: 184 }, { x: 604, y: 364 }, { x: 791, y: 364 }, { x: 983, y: 364 }],
"9": [{ x: 616, y: 144 }, { x: 808, y: 144 }, { x: 987, y: 144 }, { x: 616, y: 298 }, { x: 808, y: 298 }, { x: 987, y: 298 }, { x: 616, y: 447 }, { x: 808, y: 447 }, { x: 987, y: 447 }] "9": [{ x: 616, y: 144 }, { x: 808, y: 144 }, { x: 987, y: 144 }, { x: 616, y: 298 }, { x: 808, y: 298 }, { x: 987, y: 298 }, { x: 616, y: 447 }, { x: 808, y: 447 }, { x: 987, y: 447 }]
...@@ -145,7 +117,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -145,7 +117,7 @@ export class PlayComponent implements OnInit, OnDestroy {
g_clickY; // 点击坐标 Y g_clickY; // 点击坐标 Y
g_ctx; // canvas 实例 g_ctx; // canvas 实例
g_data; // 数据 g_data; // 数据
g_formData; // 表单转换之后的数据 g_formData: FormData; // 表单转换之后的数据
g_teacherFlag = false; // 默认角色 g_teacherFlag = false; // 默认角色
g_currentUser; g_currentUser;
// ------------------------------------ // ------------------------------------
...@@ -331,7 +303,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -331,7 +303,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 显示花瓣效果 // 显示花瓣效果
this.showCorrectPatal("card", 5000) this.showCorrectPatal("card", 5000)
// 播放结束音效 // 播放结束音效
this.g_cartoon.playAudio("success") this.g_cartoon.playAudio("success")
}, 500) }, 500)
} }
...@@ -1221,7 +1193,15 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1221,7 +1193,15 @@ export class PlayComponent implements OnInit, OnDestroy {
if (!this.g_data.contentObj) { if (!this.g_data.contentObj) {
this.g_data.contentObj = {}; this.g_data.contentObj = {};
this.g_formData = {}; this.g_formData = {
score: 0,
title: '',
questionText: '',
questionType: '',
questionTextAudio: '',
bgAudio: '',
questions: []
};
} }
this.initDefaultData(); this.initDefaultData();
...@@ -1246,7 +1226,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1246,7 +1226,7 @@ export class PlayComponent implements OnInit, OnDestroy {
initDefaultData() { initDefaultData() {
if (Object.keys(this.g_formData).length === 0) { if (Object.keys(this.g_formData).length === 0) {
// console.log("Init default form data") // console.log("Init default form data")
this.g_formData = convertFormData(defaultFormData); this.g_formData = defaultFormData;
console.log("this.g_formData", this.g_formData) console.log("this.g_formData", this.g_formData)
} }
} }
......
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