Commit 3979605c authored by 范雪寒's avatar 范雪寒

fix: 图片路径问题

parent 81445ff1
This source diff could not be displayed because it is too large. You can view the blob instead.
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef} from '@angular/core'; import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef } from '@angular/core';
import { defaultData } from '../../assets/default/formData/defaultData.js' import { defaultData } from '../../assets/default/formData/defaultData.js'
@Component({ @Component({
...@@ -13,7 +13,16 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -13,7 +13,16 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
dataArray: Array<Object> = []; dataArray: Array<Object> = [];
hotZoneItemArr: Array<Object> = []; hotZoneItemArr: Array<Object> = [];
bgItem: Object; bgItem: Object;
bgImages: Object = {leftTop:"", middleTop:"", rightTop:"", leftMiddle:"", rightMiddle:"", leftBottom:"", middleBottom:"", rightBottom:""}; bgImages: Object = {
leftTop: "",
middleTop: "",
rightTop: "",
leftMiddle: "",
rightMiddle: "",
leftBottom: "",
middleBottom: "",
rightBottom: ""
};
KEY = 'DataKey_YM4-11'; KEY = 'DataKey_YM4-11';
set item(item) { set item(item) {
...@@ -32,18 +41,24 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -32,18 +41,24 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.item = {}; this.item = {};
this.item.contentObj = {}; this.item.contentObj = {};
const getData = (<any> window).courseware.getData; const getData = (<any>window).courseware.getData;
getData((data) => { getData((data) => {
// console.log("读取数据", data) // console.log("读取数据", data)
if (data) {
if (data.data) {
this.item = data.data;
} else if (data) {
this.item = data; this.item = data;
} else { } else {
this.item = {}; this.item = {};
} }
if ( !this.item.contentObj ) { if (!this.item.contentObj) {
this.item.contentObj = {}; this.item.contentObj = {};
} }
console.log('this.item:: ', this.item);
this.init(); this.init();
this.refresh(); this.refresh();
}, this.KEY); }, this.KEY);
} }
...@@ -54,7 +69,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -54,7 +69,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnDestroy() { ngOnDestroy() {
} }
saveData(e){ saveData(e) {
this.bgItem = e.bgItem; this.bgItem = e.bgItem;
// this.bgImages = e.bgImages // this.bgImages = e.bgImages
this.hotZoneItemArr.length = 0; this.hotZoneItemArr.length = 0;
...@@ -65,7 +80,11 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -65,7 +80,11 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
} }
init() { init() {
if(typeof(this.item.contentObj.hotZoneItemArr) == undefined || typeof(this.item.contentObj.bgItem) == undefined || typeof(this.item.contentObj.bgImages) == undefined || this.item.contentObj.version != defaultData.version) { if (typeof (this.item.contentObj.hotZoneItemArr) == undefined
|| typeof (this.item.contentObj.bgItem) == undefined
|| typeof (this.item.contentObj.bgImages) == undefined
|| this.item.contentObj.version != defaultData.version) {
console.log("Init defalue data") console.log("Init defalue data")
this.item.contentObj = defaultData this.item.contentObj = defaultData
this.hotZoneItemArr = defaultData.hotZoneItemArr this.hotZoneItemArr = defaultData.hotZoneItemArr
...@@ -80,7 +99,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -80,7 +99,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
} }
cardItemData(){ cardItemData() {
return { return {
audio_url: "", audio_url: "",
image_url: "", image_url: "",
...@@ -88,7 +107,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -88,7 +107,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}; };
} }
cardChoiceData(){ cardChoiceData() {
return { isText: true, text: "", image_url: "" } return { isText: true, text: "", image_url: "" }
} }
...@@ -147,7 +166,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -147,7 +166,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
} }
save() { save() {
(<any> window).courseware.setData(this.item, null, this.KEY); (<any>window).courseware.setData(this.item, null, this.KEY);
this.refresh(); this.refresh();
// console.log("保存", this.item) // console.log("保存", this.item)
} }
......
...@@ -34,7 +34,7 @@ import { ...@@ -34,7 +34,7 @@ import {
shake shake
} from "./Unit"; } from "./Unit";
import { localImages, localAudios, multiSizeBackground} from "./resources"; import { localImages, localAudios, multiSizeBackground } from "./resources";
import { Cartoon } from './Cartoon' import { Cartoon } from './Cartoon'
import { Subject } from "rxjs"; import { Subject } from "rxjs";
...@@ -142,18 +142,18 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -142,18 +142,18 @@ export class PlayComponent implements OnInit, OnDestroy {
g_EnableStageRuler = false; // 使能舞台背景格尺 g_EnableStageRuler = false; // 使能舞台背景格尺
g_ForceChangeDefaultRole = false // 强制当前角色为默认角色 g_ForceChangeDefaultRole = false // 强制当前角色为默认角色
g_EnableTestSendEvent = false // 发送模拟Web数据 g_EnableTestSendEvent = false // 发送模拟Web数据
g_showLeftCornerTest= false // 测试左上角图标 g_showLeftCornerTest = false // 测试左上角图标
// ------------------------------------ // ------------------------------------
// 当数据加载完毕后,执行 // 当数据加载完毕后,执行
systemReady(){ systemReady() {
this.setLeftCornerTest() this.setLeftCornerTest()
this.initGame() this.initGame()
} }
// 屏幕尺寸变化后执行 // 屏幕尺寸变化后执行
handleScreenResize(){ handleScreenResize() {
this.cleanSystemVar() this.cleanSystemVar()
this.cleanGameVar(); this.cleanGameVar();
this.setLeftCornerTest(); this.setLeftCornerTest();
...@@ -163,7 +163,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -163,7 +163,7 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
// 映射预加载图片[网路]资源 返回包含图片路径的数组 // 映射预加载图片[网路]资源 返回包含图片路径的数组
mapToImageArray(contentObj){ mapToImageArray(contentObj) {
let array = [] let array = []
array.push(contentObj.bgItem.url) array.push(contentObj.bgItem.url)
...@@ -183,7 +183,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -183,7 +183,7 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
// 映射预加载音频[网路]资源 返回包含音频路径的数组 // 映射预加载音频[网路]资源 返回包含音频路径的数组
mapToAduioArray(contentObj){ mapToAduioArray(contentObj) {
let array = [] let array = []
contentObj.bgItem.mainTextAudio && array.push(contentObj.bgItem.mainTextAudio) contentObj.bgItem.mainTextAudio && array.push(contentObj.bgItem.mainTextAudio)
...@@ -212,7 +212,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -212,7 +212,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
initGame(){ initGame() {
console.log(this.g_formData); console.log(this.g_formData);
this.initSelectPannel(); this.initSelectPannel();
this.initMainWindow(); this.initMainWindow();
...@@ -225,32 +225,32 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -225,32 +225,32 @@ export class PlayComponent implements OnInit, OnDestroy {
this.initBackgroundSide(); this.initBackgroundSide();
} }
cleanGameVar(){ cleanGameVar() {
this.m_elementDraged = null; this.m_elementDraged = null;
this.m_currentQuestionIndex = -1; this.m_currentQuestionIndex = -1;
this.m_answerAll = [] this.m_answerAll = []
} }
startGame(){ startGame() {
} }
restartGame(){ restartGame() {
this.cleanGameVar() this.cleanGameVar()
this.startGame() this.startGame()
} }
endGame(){ endGame() {
} }
initSelectPannel() { initSelectPannel() {
let element = this.g_cartoon.createCartoonElementImageFunc("select-background", "select-bg", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc("select-background", "select-bg", (w, h) => {
return { return {
sx: 1065 * this.g_mapScale / w, sx: 1065 * this.g_mapScale / w,
sy: 188 * this.g_mapScale / h sy: 188 * this.g_mapScale / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_canvasWidth / 2, x: this.g_canvasWidth / 2,
y: this.g_cartoon.getOrigin().y + (114 + 168 / 2) * this.g_mapScale y: this.g_cartoon.getOrigin().y + (114 + 168 / 2) * this.g_mapScale
...@@ -260,31 +260,31 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -260,31 +260,31 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(element.ref) this.render(element.ref)
} }
initTitle_Part(){ initTitle_Part() {
let element = this.g_cartoon.createCartoonElementImageFunc("part-title", "bg_title_part", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc("part-title", "bg_title_part", (w, h) => {
return { return {
sx: 57*this.g_mapScale / w, sx: 57 * this.g_mapScale / w,
sy: 65*this.g_mapScale / h, sy: 65 * this.g_mapScale / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: 53*this.g_mapScale + (57*this.g_mapScale)/2, x: 53 * this.g_mapScale + (57 * this.g_mapScale) / 2,
y: (65*this.g_mapScale)/2 y: (65 * this.g_mapScale) / 2
} }
}) })
element.ref.x = this.g_partTitle_x - 20 * this.g_mapScale + (57*this.g_mapScale)/2; element.ref.x = this.g_partTitle_x - 20 * this.g_mapScale + (57 * this.g_mapScale) / 2;
let text = this.g_cartoon.createLabel(this.g_formData.bgItem.NO, "BerlinSansFBDemi-Bold", "#FFFFFF", 48) let text = this.g_cartoon.createLabel(this.g_formData.bgItem.NO, "BerlinSansFBDemi-Bold", "#FFFFFF", 48)
element.ref.addChild(text) element.ref.addChild(text)
let partBG = this.g_cartoon.createCartoonElementImageFunc("part-title-background", "part_number_bg", (w, h)=>{ let partBG = this.g_cartoon.createCartoonElementImageFunc("part-title-background", "part_number_bg", (w, h) => {
return { return {
sx: 121*this.g_mapScale / w, sx: 121 * this.g_mapScale / w,
sy: 69*this.g_mapScale / h, sy: 69 * this.g_mapScale / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: (121*this.g_mapScale)/2, x: (121 * this.g_mapScale) / 2,
y: (69*this.g_mapScale)/2 y: (69 * this.g_mapScale) / 2
} }
}) })
...@@ -292,32 +292,32 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -292,32 +292,32 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(element.ref) this.render(element.ref)
} }
initTitle_Main(){ initTitle_Main() {
let labelWidth = 0 let labelWidth = 0
let text = this.g_cartoon.createCartoonElementLabelFunc("main-title", this.g_formData.bgItem.mainText, "FuturaBT-Medium", "#000000", 36 * this.g_mapScale, (w, h)=>{ let text = this.g_cartoon.createCartoonElementLabelFunc("main-title", this.g_formData.bgItem.mainText, "FuturaBT-Medium", "#000000", 36 * this.g_mapScale, (w, h) => {
labelWidth = w/2 labelWidth = w / 2
return { return {
x: this.g_partTitle_x - 20 * this.g_mapScale + labelWidth * this.g_mapScale, x: this.g_partTitle_x - 20 * this.g_mapScale + labelWidth * this.g_mapScale,
y: 5*this.g_mapScale + (65*this.g_mapScale) / 2 y: 5 * this.g_mapScale + (65 * this.g_mapScale) / 2
} }
}) })
let background = this.g_cartoon.createCartoonElementImageFunc("main-title-background", "bg_50_20", (w, h)=>{ let background = this.g_cartoon.createCartoonElementImageFunc("main-title-background", "bg_50_20", (w, h) => {
return { return {
sx: labelWidth*2 / w, sx: labelWidth * 2 / w,
sy: 50*this.g_mapScale / h, sy: 50 * this.g_mapScale / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_partTitle_x + labelWidth + 60 * this.g_mapScale, x: this.g_partTitle_x + labelWidth + 60 * this.g_mapScale,
y: 5*this.g_mapScale + (65*this.g_mapScale) / 2 y: 5 * this.g_mapScale + (65 * this.g_mapScale) / 2
} }
}) })
text.ref.x = this.g_partTitle_x + 60 * this.g_mapScale text.ref.x = this.g_partTitle_x + 60 * this.g_mapScale
text.ref.textAlign = "left" text.ref.textAlign = "left"
this.subscribeMapDownEvent(background.id, ()=>{ this.subscribeMapDownEvent(background.id, () => {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio(this.g_formData.bgItem.mainTextAudio) this.g_cartoon.playAudio(this.g_formData.bgItem.mainTextAudio)
this.g_enableMapDown = true; this.g_enableMapDown = true;
...@@ -327,13 +327,13 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -327,13 +327,13 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(text.ref) this.render(text.ref)
} }
initMainWindow(){ initMainWindow() {
let element = this.g_cartoon.createCartoonElementImageFunc("select-container", "defalut_container", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc("select-container", "defalut_container", (w, h) => {
return { return {
sx: 960 * this.g_mapScale / w, sx: 960 * this.g_mapScale / w,
sy: 155 * this.g_mapScale / h sy: 155 * this.g_mapScale / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_canvasWidth / 2, x: this.g_canvasWidth / 2,
y: this.g_cartoon.getOrigin().y + (114 + 168 / 2) * this.g_mapScale y: this.g_cartoon.getOrigin().y + (114 + 168 / 2) * this.g_mapScale
...@@ -342,14 +342,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -342,14 +342,14 @@ export class PlayComponent implements OnInit, OnDestroy {
let contentImageWidth = 0 let contentImageWidth = 0
let element_t = this.g_cartoon.createCartoonElementImageFunc("window-image-container", this.g_formData.bgItem.url, (w, h)=>{ let element_t = this.g_cartoon.createCartoonElementImageFunc("window-image-container", this.g_formData.bgItem.url, (w, h) => {
let s = Math.min( 960 / w, 155 / h) let s = Math.min(960 / w, 155 / h)
contentImageWidth = (w * s) / 2 contentImageWidth = (w * s) / 2
return { return {
sx: s, sx: s,
sy: s sy: s
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: 0, x: 0,
y: 0 y: 0
...@@ -367,10 +367,10 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -367,10 +367,10 @@ export class PlayComponent implements OnInit, OnDestroy {
initHotZooes(parent) { initHotZooes(parent) {
let hotZoneItemArr = this.g_formData.hotZoneItemArr let hotZoneItemArr = this.g_formData.hotZoneItemArr
hotZoneItemArr.forEach( (item,index) => { hotZoneItemArr.forEach((item, index) => {
let element = null let element = null
element = this.g_cartoon.createCartoonElement("image-puzzle-"+index, "MySprite") element = this.g_cartoon.createCartoonElement("image-puzzle-" + index, "MySprite")
element.ref.init(this.g_cartoon.images.get(item.media.image_url)) element.ref.init(this.g_cartoon.images.get(item.media.image_url))
element.ref.scaleX = (item.rect.width / element.ref.width) * parent.ref.scaleX element.ref.scaleX = (item.rect.width / element.ref.width) * parent.ref.scaleX
element.ref.scaleY = (item.rect.height / element.ref.height) * parent.ref.scaleY element.ref.scaleY = (item.rect.height / element.ref.height) * parent.ref.scaleY
...@@ -383,26 +383,26 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -383,26 +383,26 @@ export class PlayComponent implements OnInit, OnDestroy {
element.hotZooIndex = index; element.hotZooIndex = index;
element.ref.alpha = 0; element.ref.alpha = 0;
let elementDrag = null let elementDrag = null
elementDrag = this.g_cartoon.createCartoonElementLabel("text-puzzle-"+index, " " + item.media.text + " ", "MMTextBook-Bold", "#000", 48 * this.g_mapScale, -500, -500) elementDrag = this.g_cartoon.createCartoonElementLabel("text-puzzle-" + index, " " + item.media.text + " ", "MMTextBook-Bold", "#000", 48 * this.g_mapScale, -500, -500)
this.render(element.ref) this.render(element.ref)
this.render(elementDrag.ref, 10) this.render(elementDrag.ref, 10)
element.timeoutID = null element.timeoutID = null
this.subscribeMapDragEvent(element.id, ()=>{ this.subscribeMapDragEvent(element.id, () => {
element.timeoutID = setTimeout(() => { element.timeoutID = setTimeout(() => {
if(item.media.audio_url) { if (item.media.audio_url) {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio(item.media.audio_url) this.g_cartoon.playAudio(item.media.audio_url)
} }
}, this.g_dragDelay); }, this.g_dragDelay);
}, ()=>{ }, () => {
if(element.timeoutID) { if (element.timeoutID) {
clearTimeout(element.timeoutID) clearTimeout(element.timeoutID)
element.timeoutID = null element.timeoutID = null
} }
elementDrag.ref.x = this.g_clickX, elementDrag.ref.x = this.g_clickX,
elementDrag.ref.y = this.g_clickY elementDrag.ref.y = this.g_clickY
}, ()=>{ }, () => {
elementDrag.ref.x = elementDrag.initX, elementDrag.ref.x = elementDrag.initX,
elementDrag.ref.y = elementDrag.initY elementDrag.ref.y = elementDrag.initY
this.m_elementDraged = element.id; this.m_elementDraged = element.id;
...@@ -416,16 +416,16 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -416,16 +416,16 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
initLeftPart() { initLeftPart() {
if(!this.g_formData.bgItem.wordLeft_text) { if (!this.g_formData.bgItem.wordLeft_text) {
return; return;
} }
let element = this.g_cartoon.createCartoonElementImageFunc("left-part-container", "oval-copy", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc("left-part-container", "oval-copy", (w, h) => {
return { return {
sx: 100 * this.g_mapScale / w, sx: 100 * this.g_mapScale / w,
sy: 100 * this.g_mapScale / h sy: 100 * this.g_mapScale / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_cartoon.getOrigin().x + (108 + 96 / 2) * this.g_mapScale, x: this.g_cartoon.getOrigin().x + (108 + 96 / 2) * this.g_mapScale,
y: this.g_cartoon.getOrigin().y + (150 + 96 / 2) * this.g_mapScale y: this.g_cartoon.getOrigin().y + (150 + 96 / 2) * this.g_mapScale
...@@ -443,22 +443,22 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -443,22 +443,22 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(element.ref) this.render(element.ref)
element.timeoutID = null element.timeoutID = null
this.subscribeMapDragEvent(element.id, ()=>{ this.subscribeMapDragEvent(element.id, () => {
element.timeoutID = setTimeout(() => { element.timeoutID = setTimeout(() => {
if(this.g_formData.bgItem.wordLeft_audio_url) { if (this.g_formData.bgItem.wordLeft_audio_url) {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio(this.g_formData.bgItem.wordLeft_audio_url) this.g_cartoon.playAudio(this.g_formData.bgItem.wordLeft_audio_url)
} }
}, this.g_dragDelay); }, this.g_dragDelay);
text.ref.alpha = 0.5; text.ref.alpha = 0.5;
}, ()=>{ }, () => {
if(element.timeoutID) { if (element.timeoutID) {
clearTimeout(element.timeoutID) clearTimeout(element.timeoutID)
element.timeoutID = null element.timeoutID = null
} }
textDrag.ref.x = this.g_clickX, textDrag.ref.x = this.g_clickX,
textDrag.ref.y = this.g_clickY textDrag.ref.y = this.g_clickY
}, ()=>{ }, () => {
text.ref.alpha = 1; text.ref.alpha = 1;
textDrag.ref.x = textDrag.initX, textDrag.ref.x = textDrag.initX,
textDrag.ref.y = textDrag.initY textDrag.ref.y = textDrag.initY
...@@ -473,16 +473,16 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -473,16 +473,16 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
initRightPart() { initRightPart() {
if(!this.g_formData.bgItem.wordRight_text) { if (!this.g_formData.bgItem.wordRight_text) {
return; return;
} }
let element = this.g_cartoon.createCartoonElementImageFunc("right-part-container", "oval-copy", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc("right-part-container", "oval-copy", (w, h) => {
return { return {
sx: 100 * this.g_mapScale / w, sx: 100 * this.g_mapScale / w,
sy: 100 * this.g_mapScale / h sy: 100 * this.g_mapScale / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_cartoon.getOrigin().x + (1087 + 96 / 2) * this.g_mapScale, x: this.g_cartoon.getOrigin().x + (1087 + 96 / 2) * this.g_mapScale,
y: this.g_cartoon.getOrigin().y + (150 + 96 / 2) * this.g_mapScale y: this.g_cartoon.getOrigin().y + (150 + 96 / 2) * this.g_mapScale
...@@ -500,22 +500,22 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -500,22 +500,22 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(element.ref) this.render(element.ref)
element.timeoutID = null element.timeoutID = null
this.subscribeMapDragEvent(element.id, ()=>{ this.subscribeMapDragEvent(element.id, () => {
element.timeoutID = setTimeout(() => { element.timeoutID = setTimeout(() => {
if(this.g_formData.bgItem.wordRight_audio_url) { if (this.g_formData.bgItem.wordRight_audio_url) {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio(this.g_formData.bgItem.wordRight_audio_url) this.g_cartoon.playAudio(this.g_formData.bgItem.wordRight_audio_url)
} }
}, this.g_dragDelay); }, this.g_dragDelay);
text.ref.alpha = 0.5; text.ref.alpha = 0.5;
}, ()=>{ }, () => {
if(element.timeoutID) { if (element.timeoutID) {
clearTimeout(element.timeoutID) clearTimeout(element.timeoutID)
element.timeoutID = null element.timeoutID = null
} }
textDrag.ref.x = this.g_clickX, textDrag.ref.x = this.g_clickX,
textDrag.ref.y = this.g_clickY textDrag.ref.y = this.g_clickY
}, ()=>{ }, () => {
text.ref.alpha = 1; text.ref.alpha = 1;
textDrag.ref.x = textDrag.initX, textDrag.ref.x = textDrag.initX,
textDrag.ref.y = textDrag.initY textDrag.ref.y = textDrag.initY
...@@ -534,11 +534,11 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -534,11 +534,11 @@ export class PlayComponent implements OnInit, OnDestroy {
item.combin.forEach(combinIndex => { item.combin.forEach(combinIndex => {
let key = Number(combinIndex) let key = Number(combinIndex)
let value = "" let value = ""
if(key == -1) { if (key == -1) {
value = this.g_formData.bgItem.wordLeft_text; value = this.g_formData.bgItem.wordLeft_text;
} else if(key == -2) { } else if (key == -2) {
value = this.g_formData.bgItem.wordRight_text; value = this.g_formData.bgItem.wordRight_text;
} else if(this.g_formData.hotZoneItemArr.length > 0) { } else if (this.g_formData.hotZoneItemArr.length > 0) {
value = this.g_formData.hotZoneItemArr[combinIndex].media.text value = this.g_formData.hotZoneItemArr[combinIndex].media.text
} }
textAll.push( textAll.push(
...@@ -549,14 +549,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -549,14 +549,14 @@ export class PlayComponent implements OnInit, OnDestroy {
) )
}); });
let element = this.g_cartoon.createCartoonElementImageFunc(`line-word-container-${index}`, "bg_250_46", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc(`line-word-container-${index}`, "bg_250_46", (w, h) => {
return { return {
sx: 250 * this.g_mapScale / w, sx: 250 * this.g_mapScale / w,
sy: 46 * this.g_mapScale / h sy: 46 * this.g_mapScale / h
} }
}, (w, h)=>{ }, (w, h) => {
let y = 0; let y = 0;
if(index>3) { if (index > 3) {
y = this.g_cartoon.getOrigin().y + (509 + 46 / 2) * this.g_mapScale y = this.g_cartoon.getOrigin().y + (509 + 46 / 2) * this.g_mapScale
} else { } else {
y = this.g_cartoon.getOrigin().y + (383 + 46 / 2) * this.g_mapScale y = this.g_cartoon.getOrigin().y + (383 + 46 / 2) * this.g_mapScale
...@@ -570,26 +570,26 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -570,26 +570,26 @@ export class PlayComponent implements OnInit, OnDestroy {
}) })
element.questionIndex = index; element.questionIndex = index;
element.done = false; element.done = false;
element.audio_url = item.audio_url?item.audio_url:"" element.audio_url = item.audio_url ? item.audio_url : ""
let number = this.g_cartoon.createCartoonElementImageFunc(`line-word-number-${index}`, `num-${index+1}`, (w, h)=>{ let number = this.g_cartoon.createCartoonElementImageFunc(`line-word-number-${index}`, `num-${index + 1}`, (w, h) => {
return { return {
sx: 46 / w, sx: 46 / w,
sy: 46 / h sy: 46 / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: -102, x: -102,
y: 0 y: 0
} }
}) })
let line = this.g_cartoon.createCartoonElementImageFunc(`line-word-line-${index}`, "line", (w, h)=>{ let line = this.g_cartoon.createCartoonElementImageFunc(`line-word-line-${index}`, "line", (w, h) => {
return { return {
sx: 200 / w, sx: 200 / w,
sy: 2 / h sy: 2 / h
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: 25, x: 25,
y: 22 y: 22
...@@ -603,7 +603,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -603,7 +603,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.m_answerAll.push([]) this.m_answerAll.push([])
textAll.forEach((item, partIndex) => { textAll.forEach((item, partIndex) => {
let color = "#000" let color = "#000"
if(item.key<0) { if (item.key < 0) {
color = "#C8161E" color = "#C8161E"
} }
answerIndex.push(item.key) answerIndex.push(item.key)
...@@ -624,23 +624,23 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -624,23 +624,23 @@ export class PlayComponent implements OnInit, OnDestroy {
startX += el.ref.width startX += el.ref.width
}); });
this.subscribeMapUpEvent(element.id, ()=>{ this.subscribeMapUpEvent(element.id, () => {
if(!this.m_elementDraged) { if (!this.m_elementDraged) {
this.g_enableMapUp = true; this.g_enableMapUp = true;
return; return;
} }
let dragElement = this.g_cartoon.getCartoonElement(this.m_elementDraged) let dragElement = this.g_cartoon.getCartoonElement(this.m_elementDraged)
if(!dragElement) { if (!dragElement) {
this.g_enableMapUp = true; this.g_enableMapUp = true;
return; return;
} }
if(!this.m_elementDraged) { if (!this.m_elementDraged) {
this.g_enableMapUp = true; this.g_enableMapUp = true;
return; return;
} }
if(this.m_currentQuestionIndex != element.questionIndex) { if (this.m_currentQuestionIndex != element.questionIndex) {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio("cuowu") this.g_cartoon.playAudio("cuowu")
this.g_enableMapUp = true; this.g_enableMapUp = true;
...@@ -648,9 +648,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -648,9 +648,9 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
for (let index = 0; index < answerIndex.length; index++) { for (let index = 0; index < answerIndex.length; index++) {
if(dragElement.hotZooIndex == answerIndex[index]) { if (dragElement.hotZooIndex == answerIndex[index]) {
let textShow = this.g_cartoon.getCartoonElement(`word-part-${this.m_currentQuestionIndex}-${dragElement.hotZooIndex}-${index}`) let textShow = this.g_cartoon.getCartoonElement(`word-part-${this.m_currentQuestionIndex}-${dragElement.hotZooIndex}-${index}`)
if(!textShow.isShown) { if (!textShow.isShown) {
textShow.isShown = true; textShow.isShown = true;
textShow.ref.alpha = 1; textShow.ref.alpha = 1;
this.g_cartoon.playAudio("sm-choice-correct") this.g_cartoon.playAudio("sm-choice-correct")
...@@ -662,10 +662,10 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -662,10 +662,10 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
} }
if(this.checkQuestionDone()) { if (this.checkQuestionDone()) {
this.m_currentQuestionIndex++ this.m_currentQuestionIndex++
element.done = true; element.done = true;
if(this.m_currentQuestionIndex > this.g_formData.bgItem.questions.length) { if (this.m_currentQuestionIndex > this.g_formData.bgItem.questions.length) {
this.endGame() this.endGame()
} }
} }
...@@ -674,8 +674,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -674,8 +674,8 @@ export class PlayComponent implements OnInit, OnDestroy {
this.g_enableMapUp = true; this.g_enableMapUp = true;
}) })
this.subscribeMapDownEvent(element.id, ()=>{ this.subscribeMapDownEvent(element.id, () => {
if(element.done) { if (element.done) {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
this.g_cartoon.playAudio(element.audio_url) this.g_cartoon.playAudio(element.audio_url)
} }
...@@ -691,61 +691,61 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -691,61 +691,61 @@ export class PlayComponent implements OnInit, OnDestroy {
checkQuestionDone() { checkQuestionDone() {
let partAll = [] let partAll = []
let result = [] let result = []
if(this.m_currentQuestionIndex >= 0) { if (this.m_currentQuestionIndex >= 0) {
partAll = this.m_answerAll[this.m_currentQuestionIndex]?this.m_answerAll[this.m_currentQuestionIndex]:[] partAll = this.m_answerAll[this.m_currentQuestionIndex] ? this.m_answerAll[this.m_currentQuestionIndex] : []
} }
partAll.forEach(item=>{ partAll.forEach(item => {
let el = this.g_cartoon.getCartoonElement(item) let el = this.g_cartoon.getCartoonElement(item)
if(el && el.isShown) { if (el && el.isShown) {
result.push(true) result.push(true)
} else { } else {
result.push(false) result.push(false)
} }
}) })
if(result.indexOf(false)==-1){ if (result.indexOf(false) == -1) {
return true return true
} else { } else {
return false return false
} }
} }
initAudioPlayerAll(){ initAudioPlayerAll() {
if(!this.g_formData.bgItem.audio_url) { if (!this.g_formData.bgItem.audio_url) {
return return
} }
let element = this.g_cartoon.createCartoonElementImageFunc(`audio-all`, "icon_audio_container", (w, h)=>{ let element = this.g_cartoon.createCartoonElementImageFunc(`audio-all`, "icon_audio_container", (w, h) => {
return { return {
sx: 76 * this.g_mapScale / w, sx: 76 * this.g_mapScale / w,
sy: 77 * this.g_mapScale / h, sy: 77 * this.g_mapScale / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: this.g_cartoon.getOrigin().x + (1190 + 80 / 2) * this.g_mapScale, x: this.g_cartoon.getOrigin().x + (1190 + 80 / 2) * this.g_mapScale,
y: this.g_cartoon.getOrigin().y + (630 + 81.5 / 2) * this.g_mapScale y: this.g_cartoon.getOrigin().y + (630 + 81.5 / 2) * this.g_mapScale
} }
}) })
let play = this.g_cartoon.createCartoonElementImageFunc(`audio-all-play`, "icon_paly", (w, h)=>{ let play = this.g_cartoon.createCartoonElementImageFunc(`audio-all-play`, "icon_paly", (w, h) => {
return { return {
sx: 76 / w, sx: 76 / w,
sy: 77 / h, sy: 77 / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: 0, x: 0,
y: 0 y: 0
} }
}) })
let pause = this.g_cartoon.createCartoonElementImageFunc(`audio-all-pause`, "icon_pause", (w, h)=>{ let pause = this.g_cartoon.createCartoonElementImageFunc(`audio-all-pause`, "icon_pause", (w, h) => {
return { return {
sx: 76 / w, sx: 76 / w,
sy: 77 / h, sy: 77 / h,
} }
}, (w, h)=>{ }, (w, h) => {
return { return {
x: 0, x: 0,
y: 0 y: 0
...@@ -760,14 +760,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -760,14 +760,14 @@ export class PlayComponent implements OnInit, OnDestroy {
element.isPlaying = false element.isPlaying = false
element.audio = this.g_cartoon.audio.get(this.g_formData.bgItem.audio_url) element.audio = this.g_cartoon.audio.get(this.g_formData.bgItem.audio_url)
if(element.audio){ if (element.audio) {
element.audio.onended = ()=>{ element.audio.onended = () => {
element.pause() element.pause()
} }
} }
element.play = ()=>{ element.play = () => {
if(!element.audio){ if (!element.audio) {
return return
} }
element.isPlaying = true; element.isPlaying = true;
...@@ -777,8 +777,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -777,8 +777,8 @@ export class PlayComponent implements OnInit, OnDestroy {
element.pauseIcon.ref.visible = true; element.pauseIcon.ref.visible = true;
} }
element.pause = ()=>{ element.pause = () => {
if(!element.audio){ if (!element.audio) {
return return
} }
element.isPlaying = false; element.isPlaying = false;
...@@ -789,14 +789,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -789,14 +789,14 @@ export class PlayComponent implements OnInit, OnDestroy {
element.enable = true; element.enable = true;
this.subscribeMapDownEvent(element.id, ()=>{ this.subscribeMapDownEvent(element.id, () => {
if(!element.audio || !element.enable){ if (!element.audio || !element.enable) {
this.g_enableMapDown = true; this.g_enableMapDown = true;
return return
} }
if(element.isPlaying){ if (element.isPlaying) {
element.pause() element.pause()
}else{ } else {
element.play() element.play()
} }
this.g_enableMapDown = true; this.g_enableMapDown = true;
...@@ -805,26 +805,26 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -805,26 +805,26 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(element.ref) this.render(element.ref)
} }
resetLongAudio(){ resetLongAudio() {
let audio = this.g_cartoon.getCartoonElement(`audio-all`) let audio = this.g_cartoon.getCartoonElement(`audio-all`)
if(audio.enable){ if (audio.enable) {
audio.pause() audio.pause()
} }
} }
calcPosition(position, width, height) { calcPosition(position, width, height) {
let map = { let map = {
leftTop: {x: 0, y: 0}, leftTop: { x: 0, y: 0 },
middleTop: {x: this.g_canvasWidth / 2, y: 0}, middleTop: { x: this.g_canvasWidth / 2, y: 0 },
rightTop: {x: this.g_canvasWidth, y: 0}, rightTop: { x: this.g_canvasWidth, y: 0 },
leftMiddle: {x: 0, y: this.g_canvasHeight / 2}, leftMiddle: { x: 0, y: this.g_canvasHeight / 2 },
rightMiddle: {x: this.g_canvasWidth, y: this.g_canvasHeight / 2}, rightMiddle: { x: this.g_canvasWidth, y: this.g_canvasHeight / 2 },
leftBottom: {x: 0, y: this.g_canvasHeight}, leftBottom: { x: 0, y: this.g_canvasHeight },
middleBottom: {x: this.g_canvasWidth / 2, y: this.g_canvasHeight}, middleBottom: { x: this.g_canvasWidth / 2, y: this.g_canvasHeight },
rightBottom: {x: this.g_canvasWidth, y: this.g_canvasHeight} rightBottom: { x: this.g_canvasWidth, y: this.g_canvasHeight }
} }
switch(position) { switch (position) {
case "leftTop": case "leftTop":
map["leftTop"].x += width * this.g_mapScale / 2, map["leftTop"].x += width * this.g_mapScale / 2,
map["leftTop"].y += height * this.g_mapScale / 2; map["leftTop"].y += height * this.g_mapScale / 2;
...@@ -858,16 +858,16 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -858,16 +858,16 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
initBackgroundSide() { initBackgroundSide() {
for(let key in this.g_formData.bgImages) { for (let key in this.g_formData.bgImages) {
if(!this.g_formData.bgImages[key]) { if (!this.g_formData.bgImages[key]) {
continue continue
} }
let ele = this.g_cartoon.createCartoonElementImageFunc(`background-side-${key}`, this.g_formData.bgImages[key], (w, h)=>{ let ele = this.g_cartoon.createCartoonElementImageFunc(`background-side-${key}`, this.g_formData.bgImages[key], (w, h) => {
return { return {
sx: this.g_mapScale, sx: this.g_mapScale,
sy: this.g_mapScale, sy: this.g_mapScale,
} }
}, (w, h)=>{ }, (w, h) => {
return this.calcPosition(key, w, h) return this.calcPosition(key, w, h)
}) })
console.log(this.g_formData.bgImages[key]) console.log(this.g_formData.bgImages[key])
...@@ -920,8 +920,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -920,8 +920,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// //
// -------------------------------------------------- // --------------------------------------------------
@ViewChild("canvas", {static: true }) canvas: ElementRef; @ViewChild("canvas", { static: true }) canvas: ElementRef;
@ViewChild("wrap", {static: true }) wrap: ElementRef; @ViewChild("wrap", { static: true }) wrap: ElementRef;
@HostListener("window:resize", ["$event"]) @HostListener("window:resize", ["$event"])
onResize(event) { onResize(event) {
this.g_winResizeEventStream.next(); this.g_winResizeEventStream.next();
...@@ -931,17 +931,23 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -931,17 +931,23 @@ export class PlayComponent implements OnInit, OnDestroy {
window.cancelAnimationFrame(this.g_animationId); window.cancelAnimationFrame(this.g_animationId);
} }
ngOnInit() { ngOnInit() {
console.log('ngOnInit');
const getData = (<any>window).courseware.getData; const getData = (<any>window).courseware.getData;
getData(data => { getData(data => {
if (window['air'].airClassInfo.user.classRole == 'tea') { // if (window['air'].airClassInfo.user.classRole == 'tea') {
if(!this.g_ForceChangeDefaultRole){ // if (!this.g_ForceChangeDefaultRole) {
this.g_teacherFlag = true; // this.g_teacherFlag = true;
} // }
} // }
this.g_currentUser = window['air'].airClassInfo.user; // this.g_currentUser = window['air'].airClassInfo.user;
console.log('getData: ', data);
if (data && typeof data == "object") { if (data && typeof data == "object") {
this.g_data = data; this.g_data = data;
if (data.data) {
this.g_formData = data.data.contentObj;
} else {
this.g_formData = data.contentObj; this.g_formData = data.contentObj;
}
} else { } else {
this.g_data = {}; this.g_data = {};
} }
...@@ -959,6 +965,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -959,6 +965,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 预加载资源 // 预加载资源
this.g_cartoon.loadResources().then(() => { this.g_cartoon.loadResources().then(() => {
window["air"].hideAirClassLoading(this.g_KEY, this.g_data); window["air"].hideAirClassLoading(this.g_KEY, this.g_data);
console.log('hideAirClassLoading');
this.initSystem(); this.initSystem();
this.update(); this.update();
this.systemReady() this.systemReady()
...@@ -972,7 +979,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -972,7 +979,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 初始化默认数据 // 初始化默认数据
// ---------------------------------- // ----------------------------------
initDefaultData() { initDefaultData() {
if ( Object.keys(this.g_formData).length===0 || this.g_formData.version != defaultData.version ) { if (Object.keys(this.g_formData).length === 0 || this.g_formData.version != defaultData.version) {
this.g_formData = defaultData; this.g_formData = defaultData;
console.log("Use default data.", this.g_formData) console.log("Use default data.", this.g_formData)
} }
...@@ -988,14 +995,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -988,14 +995,14 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
// 添加用户上传音效 // 添加用户上传音效
let images:Array<string> = this.mapToAduioArray(contentObj) let images: Array<string> = this.mapToAduioArray(contentObj)
images.forEach(image => { images.forEach(image => {
this.g_cartoon.addAudio( image, image ); this.g_cartoon.addAudio(image, image);
}); });
// 添加本地音效 // 添加本地音效
for( var key in localAudios ){ for (var key in localAudios) {
this.g_cartoon.addAudio( key, localAudios[key] ); this.g_cartoon.addAudio(key, localAudios[key]);
} }
} }
...@@ -1010,14 +1017,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1010,14 +1017,14 @@ export class PlayComponent implements OnInit, OnDestroy {
this.g_cartoon.addImage(url, url); this.g_cartoon.addImage(url, url);
} }
}; };
let images:Array<string> = this.mapToImageArray(contentObj) let images: Array<string> = this.mapToImageArray(contentObj)
images.forEach(image => { images.forEach(image => {
addPicUrl(image) addPicUrl(image)
}); });
} }
// 添加本地图片 // 添加本地图片
for( var key in localImages ){ for (var key in localImages) {
this.g_cartoon.addImage( key, localImages[key] ); this.g_cartoon.addImage(key, localImages[key]);
} }
} }
...@@ -1028,24 +1035,24 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1028,24 +1035,24 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
this.m_mapDownArray.forEach((item)=>{ this.m_mapDownArray.forEach((item) => {
if(!myStopPropagation){ if (!myStopPropagation) {
if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) { if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) {
this.g_enableMapDown = false; this.g_enableMapDown = false;
if(this.m_mapDragObject[item.id]){ if (this.m_mapDragObject[item.id]) {
this.m_mapDragObject[item.id].trigger() this.m_mapDragObject[item.id].trigger()
let dragElement = this.g_cartoon.getCartoonElement(item.id) let dragElement = this.g_cartoon.getCartoonElement(item.id)
if(dragElement){ if (dragElement) {
this.g_currentDragElementID = item.id this.g_currentDragElementID = item.id
this.g_dragFirstClickX = this.g_clickX this.g_dragFirstClickX = this.g_clickX
this.g_dragFirstClickY = this.g_clickY this.g_dragFirstClickY = this.g_clickY
this.enableMoveAsstant(()=>{ this.enableMoveAsstant(() => {
this.m_mapDragObject[item.id].move(dragElement) this.m_mapDragObject[item.id].move(dragElement)
}) })
} }
myStopPropagation = true; myStopPropagation = true;
}else{ } else {
if(item.callback()){ if (item.callback()) {
myStopPropagation = true; myStopPropagation = true;
} }
} }
...@@ -1060,11 +1067,11 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1060,11 +1067,11 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
this.m_mapMoveArray.forEach((item)=>{ this.m_mapMoveArray.forEach((item) => {
if(!myStopPropagation){ if (!myStopPropagation) {
if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) { if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) {
this.g_enableMapMove = false; this.g_enableMapMove = false;
if(item.callback()){ if (item.callback()) {
myStopPropagation = true; myStopPropagation = true;
} }
} }
...@@ -1077,11 +1084,11 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1077,11 +1084,11 @@ export class PlayComponent implements OnInit, OnDestroy {
if (!this.g_enableMapUp) { if (!this.g_enableMapUp) {
return; return;
} }
this.m_mapUpArray.forEach((item)=>{ this.m_mapUpArray.forEach((item) => {
if(!myStopPropagation){ if (!myStopPropagation) {
if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) { if (this.checkClickTarget(this.g_cartoon.getCartoonElementRef(item.id))) {
this.g_enableMapUp = false; this.g_enableMapUp = false;
if(item.callback()){ if (item.callback()) {
myStopPropagation = true; myStopPropagation = true;
} }
this.g_currentDragElementID = null; this.g_currentDragElementID = null;
...@@ -1290,44 +1297,44 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1290,44 +1297,44 @@ export class PlayComponent implements OnInit, OnDestroy {
return len; return len;
} }
subscribeMapDownEvent(id,callback, zIndex?){ subscribeMapDownEvent(id, callback, zIndex?) {
zIndex = zIndex?zIndex:0 zIndex = zIndex ? zIndex : 0
this.m_mapDownObject.push({id:id, zIndex:zIndex?zIndex:1, callback:callback}) this.m_mapDownObject.push({ id: id, zIndex: zIndex ? zIndex : 1, callback: callback })
this.m_mapDownObject.sort((a,b)=>{ this.m_mapDownObject.sort((a, b) => {
return b.zIndex-a.zIndex return b.zIndex - a.zIndex
}) })
this.m_mapDownArray = [] this.m_mapDownArray = []
this.m_mapDownObject.forEach(item=>{ this.m_mapDownObject.forEach(item => {
this.m_mapDownArray.push(item) this.m_mapDownArray.push(item)
}) })
} }
subscribeMapUpEvent(id,callback, zIndex?){ subscribeMapUpEvent(id, callback, zIndex?) {
zIndex = zIndex?zIndex:0 zIndex = zIndex ? zIndex : 0
this.m_mapUpObject.push({id:id, zIndex:zIndex?zIndex:1, callback:callback}) this.m_mapUpObject.push({ id: id, zIndex: zIndex ? zIndex : 1, callback: callback })
this.m_mapUpObject.sort((a,b)=>{ this.m_mapUpObject.sort((a, b) => {
return b.zIndex-a.zIndex return b.zIndex - a.zIndex
}) })
this.m_mapUpArray = [] this.m_mapUpArray = []
this.m_mapUpObject.forEach(item=>{ this.m_mapUpObject.forEach(item => {
this.m_mapUpArray.push(item) this.m_mapUpArray.push(item)
}) })
} }
subscribeMapMoveEvent(id, callback, zIndex?){ subscribeMapMoveEvent(id, callback, zIndex?) {
zIndex = zIndex?zIndex:0 zIndex = zIndex ? zIndex : 0
this.m_mapMoveObject.push({id:id, zIndex:zIndex?zIndex:1, callback:callback}) this.m_mapMoveObject.push({ id: id, zIndex: zIndex ? zIndex : 1, callback: callback })
this.m_mapMoveObject.sort((a,b)=>{ this.m_mapMoveObject.sort((a, b) => {
return a.zIndex - b.zIndex return a.zIndex - b.zIndex
}) })
this.m_mapMoveArray = [] this.m_mapMoveArray = []
this.m_mapMoveObject.forEach(item=>{ this.m_mapMoveObject.forEach(item => {
this.m_mapMoveArray.push(item) this.m_mapMoveArray.push(item)
}) })
} }
subscribeMapDragEvent(id, trigger, move, release){ subscribeMapDragEvent(id, trigger, move, release) {
this.subscribeMapDownEvent(id,()=>{}) this.subscribeMapDownEvent(id, () => { })
this.m_mapDragObject[id] = { this.m_mapDragObject[id] = {
trigger, trigger,
move, move,
...@@ -1335,8 +1342,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1335,8 +1342,8 @@ export class PlayComponent implements OnInit, OnDestroy {
}; };
} }
releaseDragElement(){ releaseDragElement() {
if(this.g_currentDragElementID){ if (this.g_currentDragElementID) {
this.m_mapDragObject[this.g_currentDragElementID].release() this.m_mapDragObject[this.g_currentDragElementID].release()
} }
} }
...@@ -1375,16 +1382,16 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1375,16 +1382,16 @@ export class PlayComponent implements OnInit, OnDestroy {
initStage() { initStage() {
const bgWidth = 1280; const bgWidth = 1280;
const bgHeight = 720; const bgHeight = 720;
this.g_cartoon.stageWidth = bgWidth*this.g_mapScale; this.g_cartoon.stageWidth = bgWidth * this.g_mapScale;
this.g_cartoon.stageHeight= bgHeight*this.g_mapScale; this.g_cartoon.stageHeight = bgHeight * this.g_mapScale;
const imageColor = this.g_cartoon.createCartoonElement("g-ackground-color", "ShapeRect").ref; const imageColor = this.g_cartoon.createCartoonElement("g-ackground-color", "ShapeRect").ref;
// console.log( "stageWidth: " + this.g_cartoon.stageWidth + " stageHeight" + this.g_cartoon.stageHeight) // console.log( "stageWidth: " + this.g_cartoon.stageWidth + " stageHeight" + this.g_cartoon.stageHeight)
// console.log( "clientWidth: " + this.g_cartoon.clientWidth + " clientHeight" + this.g_cartoon.clientHeight) // console.log( "clientWidth: " + this.g_cartoon.clientWidth + " clientHeight" + this.g_cartoon.clientHeight)
// console.log( "canvasWidth: " + this.g_canvasWidth + " canvasHeight" + this.g_canvasHeight) // console.log( "canvasWidth: " + this.g_canvasWidth + " canvasHeight" + this.g_canvasHeight)
// console.log( "mapScale: " + this.g_mapScale ) // console.log( "mapScale: " + this.g_mapScale )
imageColor.x = this.g_cartoon.clientWidth / 2 ; imageColor.x = this.g_cartoon.clientWidth / 2;
imageColor.y = this.g_cartoon.clientHeight / 2 ; imageColor.y = this.g_cartoon.clientHeight / 2;
imageColor.setSize(this.g_cartoon.clientWidth, this.g_cartoon.clientHeight); imageColor.setSize(this.g_cartoon.clientWidth, this.g_cartoon.clientHeight);
imageColor.init(); imageColor.init();
imageColor.fillColor = this.g_background_color; imageColor.fillColor = this.g_background_color;
...@@ -1393,43 +1400,43 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1393,43 +1400,43 @@ export class PlayComponent implements OnInit, OnDestroy {
const image = this.g_cartoon.createCartoonElement("bg_1280_720_Ruler", "MySprite").ref; const image = this.g_cartoon.createCartoonElement("bg_1280_720_Ruler", "MySprite").ref;
image.init(this.g_cartoon.images.get("_bg_1280_720_Ruler")); image.init(this.g_cartoon.images.get("_bg_1280_720_Ruler"));
image.x = this.g_canvasWidth / 2; image.x = this.g_canvasWidth / 2;
image.y = this.g_canvasHeight /2; image.y = this.g_canvasHeight / 2;
image.visible = this.g_EnableStageRuler image.visible = this.g_EnableStageRuler
this.g_cartoon.setOrigin( image.x-(bgWidth/2*this.g_mapScale), image.y-(bgHeight/2*this.g_mapScale) ) this.g_cartoon.setOrigin(image.x - (bgWidth / 2 * this.g_mapScale), image.y - (bgHeight / 2 * this.g_mapScale))
this.g_cartoon.setRelativeOrigin( -bgWidth/2, -bgHeight/2) this.g_cartoon.setRelativeOrigin(-bgWidth / 2, -bgHeight / 2)
image.setScaleXY(this.g_mapScale); image.setScaleXY(this.g_mapScale);
this.render(image, -999) this.render(image, -999)
this.g_stage = image this.g_stage = image
this.subscribeMapUpEvent("g-ackground-color", ()=>{ this.subscribeMapUpEvent("g-ackground-color", () => {
if(this.g_currentDragElementID){ if (this.g_currentDragElementID) {
this.releaseDragElement() this.releaseDragElement()
this.g_currentDragElementID = null; this.g_currentDragElementID = null;
}else{ } else {
this.g_enableMapUp = true; this.g_enableMapUp = true;
} }
}) })
} }
render(ele, zIndex?:number){ render(ele, zIndex?: number) {
this.m_renderObject.push({element:ele, zIndex:zIndex?zIndex:1}) this.m_renderObject.push({ element: ele, zIndex: zIndex ? zIndex : 1 })
this.m_renderObject.sort((a,b)=>{ this.m_renderObject.sort((a, b) => {
return a.zIndex - b.zIndex return a.zIndex - b.zIndex
}) })
this.m_renderArr = [] this.m_renderArr = []
this.m_renderObject.forEach(item=>{ this.m_renderObject.forEach(item => {
this.m_renderArr.push(item.element) this.m_renderArr.push(item.element)
}) })
} }
sendServerEvent(key, data) { sendServerEvent(key, data) {
const c = (<any> window).courseware; const c = (<any>window).courseware;
c.sendEvent(key, JSON.stringify(data)); c.sendEvent(key, JSON.stringify(data));
} }
addServerListener(msg_key, callback) { addServerListener(msg_key, callback) {
const c = (<any> window).courseware; const c = (<any>window).courseware;
c.onEvent(msg_key, (data,next) => { c.onEvent(msg_key, (data, next) => {
callback(JSON.parse(data)) callback(JSON.parse(data))
next && next(); next && next();
}); });
...@@ -1437,8 +1444,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1437,8 +1444,8 @@ export class PlayComponent implements OnInit, OnDestroy {
randomArray_shuffle(array) { randomArray_shuffle(array) {
var input = array; var input = array;
for (var i = input.length-1; i >=0; i--) { for (var i = input.length - 1; i >= 0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1)); var randomIndex = Math.floor(Math.random() * (i + 1));
var itemAtIndex = input[randomIndex]; var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i]; input[randomIndex] = input[i];
input[i] = itemAtIndex; input[i] = itemAtIndex;
...@@ -1451,75 +1458,75 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1451,75 +1458,75 @@ export class PlayComponent implements OnInit, OnDestroy {
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize); return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
} }
stopAllTimeout(){ stopAllTimeout() {
this.m_setTimeoutIDs.forEach(id=>clearTimeout(id)) this.m_setTimeoutIDs.forEach(id => clearTimeout(id))
this.m_setTimeoutIDs = [] this.m_setTimeoutIDs = []
} }
stopAllInterval(){ stopAllInterval() {
this.m_setIntervalIDs.forEach(id=>clearInterval(id)) this.m_setIntervalIDs.forEach(id => clearInterval(id))
this.m_setIntervalIDs = [] this.m_setIntervalIDs = []
} }
topOfRenderArray(element){ topOfRenderArray(element) {
let index = this.m_renderArr.indexOf(element) let index = this.m_renderArr.indexOf(element)
if(index !=-1){ if (index != -1) {
this.m_renderArr.splice(index, 1) this.m_renderArr.splice(index, 1)
this.m_renderArr.push(element) this.m_renderArr.push(element)
} }
} }
setRenderZIndex(element, zIndex){ setRenderZIndex(element, zIndex) {
let index = null; let index = null;
for(let i=0; i<this.m_renderObject.length; i++){ for (let i = 0; i < this.m_renderObject.length; i++) {
if( this.m_renderObject[i].element.id == element.id ){ if (this.m_renderObject[i].element.id == element.id) {
index = i index = i
} }
} }
if(index){ if (index) {
this.m_renderObject.splice(index, 1) this.m_renderObject.splice(index, 1)
this.m_renderObject.push({element:element, zIndex:zIndex?zIndex:1}) this.m_renderObject.push({ element: element, zIndex: zIndex ? zIndex : 1 })
this.m_renderObject.sort((a,b)=>{ this.m_renderObject.sort((a, b) => {
return a.zIndex - b.zIndex return a.zIndex - b.zIndex
}) })
this.m_renderArr = [] this.m_renderArr = []
this.m_renderObject.forEach(item=>{ this.m_renderObject.forEach(item => {
this.m_renderArr.push(item.element) this.m_renderArr.push(item.element)
}) })
} }
} }
deleteElementInRender(id){ deleteElementInRender(id) {
let index = null; let index = null;
for(let i=0; i<this.m_renderObject.length; i++){ for (let i = 0; i < this.m_renderObject.length; i++) {
if( this.m_renderObject[i].element.id == id ){ if (this.m_renderObject[i].element.id == id) {
index = i index = i
} }
} }
if(index){ if (index) {
this.m_renderObject.splice(index, 1) this.m_renderObject.splice(index, 1)
this.m_renderObject.sort((a,b)=>{ this.m_renderObject.sort((a, b) => {
return a.zIndex - b.zIndex return a.zIndex - b.zIndex
}) })
this.m_renderArr = [] this.m_renderArr = []
this.m_renderObject.forEach(item=>{ this.m_renderObject.forEach(item => {
this.m_renderArr.push(item.element) this.m_renderArr.push(item.element)
}) })
}else{ } else {
console.warn("Can not found element id:" + id) console.warn("Can not found element id:" + id)
} }
} }
enableMoveAsstant(callback){ enableMoveAsstant(callback) {
if (this.m_moveAsstantIntervalId) { if (this.m_moveAsstantIntervalId) {
this.g_enableDragging = false; this.g_enableDragging = false;
clearInterval(this.m_moveAsstantIntervalId) clearInterval(this.m_moveAsstantIntervalId)
} }
this.m_moveAsstantIntervalId = setInterval(() => { this.m_moveAsstantIntervalId = setInterval(() => {
if(this.g_enableDragging){ if (this.g_enableDragging) {
callback() callback()
}else{ } else {
let moveX = Math.abs(this.g_dragFirstClickX - this.g_clickX) let moveX = Math.abs(this.g_dragFirstClickX - this.g_clickX)
let moveY = Math.abs(this.g_dragFirstClickY - this.g_clickY) let moveY = Math.abs(this.g_dragFirstClickY - this.g_clickY)
if (moveX > this.g_enableDragDistance || moveY > this.g_enableDragDistance) { if (moveX > this.g_enableDragDistance || moveY > this.g_enableDragDistance) {
...@@ -1529,12 +1536,12 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1529,12 +1536,12 @@ export class PlayComponent implements OnInit, OnDestroy {
}, 50) }, 50)
} }
disableMoveAsstant(){ disableMoveAsstant() {
this.g_enableDragging = false; this.g_enableDragging = false;
clearInterval(this.m_moveAsstantIntervalId) clearInterval(this.m_moveAsstantIntervalId)
} }
cleanSystemVar(){ cleanSystemVar() {
this.m_mapDownQueue = {} this.m_mapDownQueue = {}
this.m_mapDownArray = [] this.m_mapDownArray = []
this.m_mapDownObject = [] this.m_mapDownObject = []
...@@ -1551,18 +1558,18 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1551,18 +1558,18 @@ export class PlayComponent implements OnInit, OnDestroy {
this.g_cartoon.stopAllAudio() this.g_cartoon.stopAllAudio()
} }
getMaxSubstringLength(str){ getMaxSubstringLength(str) {
let maxLength = 0; let maxLength = 0;
let subSubstring = str.split(" ") let subSubstring = str.split(" ")
for (let index=0; index<subSubstring.length; index++) { for (let index = 0; index < subSubstring.length; index++) {
if(subSubstring[index].length > maxLength){ if (subSubstring[index].length > maxLength) {
maxLength = subSubstring[index].length; maxLength = subSubstring[index].length;
} }
} }
return maxLength return maxLength
} }
setLeftCornerTest(){ setLeftCornerTest() {
const bgRect = new ShapeRect(); const bgRect = new ShapeRect();
bgRect.setSize(57, 65); bgRect.setSize(57, 65);
bgRect.fillColor = '#f8c224'; bgRect.fillColor = '#f8c224';
...@@ -1576,28 +1583,28 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1576,28 +1583,28 @@ export class PlayComponent implements OnInit, OnDestroy {
this.render(bgRect, 9999); this.render(bgRect, 9999);
} }
alignCenter(elementArray, spacing, withAni?, callback?){ alignCenter(elementArray, spacing, withAni?, callback?) {
let totlaWidth = 0 let totlaWidth = 0
let length = elementArray.length let length = elementArray.length
elementArray.forEach(element => { elementArray.forEach(element => {
let bd = element.ref.getBoundingBox() let bd = element.ref.getBoundingBox()
totlaWidth += bd.width totlaWidth += bd.width
}); });
totlaWidth += (elementArray.length-1) * spacing totlaWidth += (elementArray.length - 1) * spacing
let laseX = this.g_canvasWidth / 2 - totlaWidth/2; let laseX = this.g_canvasWidth / 2 - totlaWidth / 2;
elementArray.forEach((element, index) => { elementArray.forEach((element, index) => {
let bd = element.ref.getBoundingBox() let bd = element.ref.getBoundingBox()
if(withAni){ if (withAni) {
tweenChange(element.ref, {x: laseX + bd.width / 2}, 0.2, ()=>{ tweenChange(element.ref, { x: laseX + bd.width / 2 }, 0.2, () => {
this.g_cartoon.saveSize(element.id) this.g_cartoon.saveSize(element.id)
if(length == (index+1)){ if (length == (index + 1)) {
callback && callback() callback && callback()
} }
}) })
}else{ } else {
element.ref.x = laseX + bd.width / 2 element.ref.x = laseX + bd.width / 2
this.g_cartoon.saveSize(element.id) this.g_cartoon.saveSize(element.id)
if(length == (index+1)){ if (length == (index + 1)) {
callback && callback() callback && callback()
} }
} }
...@@ -1606,21 +1613,21 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1606,21 +1613,21 @@ export class PlayComponent implements OnInit, OnDestroy {
}); });
} }
alignLeft(elementArray, spacing, startX = 0, withAni?, callback?){ alignLeft(elementArray, spacing, startX = 0, withAni?, callback?) {
let laseX = startX; let laseX = startX;
elementArray.forEach((element, index) => { elementArray.forEach((element, index) => {
let bd = element.ref.getBoundingBox() let bd = element.ref.getBoundingBox()
if(withAni){ if (withAni) {
tweenChange(element.ref, {x: laseX + bd.width / 2}, 0.2, ()=>{ tweenChange(element.ref, { x: laseX + bd.width / 2 }, 0.2, () => {
this.g_cartoon.saveSize(element.id) this.g_cartoon.saveSize(element.id)
if(length == (index+1)){ if (length == (index + 1)) {
callback && callback() callback && callback()
} }
}) })
}else{ } else {
element.ref.x = laseX + bd.width / 2 element.ref.x = laseX + bd.width / 2
this.g_cartoon.saveSize(element.id) this.g_cartoon.saveSize(element.id)
if(length == (index+1)){ if (length == (index + 1)) {
callback && callback() callback && callback()
} }
} }
...@@ -1629,9 +1636,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1629,9 +1636,9 @@ export class PlayComponent implements OnInit, OnDestroy {
}); });
} }
createTestLine(x, y, height, color?){ createTestLine(x, y, height, color?) {
var colorAll = ['#ff0000','#eb4310','#f6941d','#fbb417','#ffff00','#cdd541','#99cc33','#3f9337','#219167','#239676','#24998d','#1f9baa','#0080ff','#3366cc','#333399','#003366','#800080','#a1488e','#c71585','#bd2158']; var colorAll = ['#ff0000', '#eb4310', '#f6941d', '#fbb417', '#ffff00', '#cdd541', '#99cc33', '#3f9337', '#219167', '#239676', '#24998d', '#1f9baa', '#0080ff', '#3366cc', '#333399', '#003366', '#800080', '#a1488e', '#c71585', '#bd2158'];
color = color ? color : colorAll[Math.floor(Math.random()*20)] color = color ? color : colorAll[Math.floor(Math.random() * 20)]
this.render(this.g_cartoon.createRectangula({ this.render(this.g_cartoon.createRectangula({
width: 5, width: 5,
height: height, height: height,
...@@ -1641,14 +1648,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1641,14 +1648,14 @@ export class PlayComponent implements OnInit, OnDestroy {
}), 9999) }), 9999)
} }
getSuitSizeBackground(key, width){ getSuitSizeBackground(key, width) {
let bgAll = multiSizeBackground[key] let bgAll = multiSizeBackground[key]
if(!bgAll){ if (!bgAll) {
return "" return ""
} }
let suitFileName = "" let suitFileName = ""
for(let fileName in bgAll){ for (let fileName in bgAll) {
if( Number(fileName) >= width){ if (Number(fileName) >= width) {
suitFileName = bgAll[fileName] suitFileName = bgAll[fileName]
break break
} }
...@@ -1729,7 +1736,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1729,7 +1736,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 泡泡 // 泡泡
showParticle(card) { showParticle(card) {
let myCard = this.g_cartoon.getCartoonElementRelativePosition(card.id) let myCard = this.g_cartoon.getCartoonElementRelativePosition(card.id)
showPopParticle(this.g_cartoon.images.get("_bubble"), { x: myCard.x , y: myCard.y }, this.g_stage); showPopParticle(this.g_cartoon.images.get("_bubble"), { x: myCard.x, y: myCard.y }, this.g_stage);
} }
// 选择正确动画 // 选择正确动画
...@@ -1737,13 +1744,13 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1737,13 +1744,13 @@ export class PlayComponent implements OnInit, OnDestroy {
this.m_elementPetalArr = []; this.m_elementPetalArr = [];
this.m_showElementPetalFlag = true; this.m_showElementPetalFlag = true;
this.addCorrectPetal(card_id); this.addCorrectPetal(card_id);
setTimeout(()=>{ setTimeout(() => {
this.m_elementPetalArr = []; this.m_elementPetalArr = [];
this.m_showElementPetalFlag = false; this.m_showElementPetalFlag = false;
callback && callback() callback && callback()
},showTime) }, showTime)
} }
stopAllCorrectPatal(){ stopAllCorrectPatal() {
this.m_elementPetalArr = []; this.m_elementPetalArr = [];
this.m_showElementPetalFlag = false; this.m_showElementPetalFlag = false;
} }
...@@ -1858,48 +1865,48 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1858,48 +1865,48 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
showJellyAnimation(element_id, callback?){ showJellyAnimation(element_id, callback?) {
let element = this.g_cartoon.getCartoonElement(element_id).ref let element = this.g_cartoon.getCartoonElement(element_id).ref
tweenChange(element,{ scaleX: this.g_mapScale * 1.2 , scaleY: this.g_mapScale * 1.1 }, 0.1, ()=>{ tweenChange(element, { scaleX: this.g_mapScale * 1.2, scaleY: this.g_mapScale * 1.1 }, 0.1, () => {
tweenChange(element,{ scaleX: this.g_mapScale * 0.8 , scaleY: this.g_mapScale * 0.9 }, 0.1, ()=>{ tweenChange(element, { scaleX: this.g_mapScale * 0.8, scaleY: this.g_mapScale * 0.9 }, 0.1, () => {
tweenChange(element,{ scaleX: this.g_mapScale , scaleY: this.g_mapScale }, 0.1, ()=>{ tweenChange(element, { scaleX: this.g_mapScale, scaleY: this.g_mapScale }, 0.1, () => {
callback && callback() callback && callback()
}) })
}) })
}) })
} }
showShakeAnimation(element_id, callback?){ showShakeAnimation(element_id, callback?) {
let element = this.g_cartoon.getCartoonElement(element_id).ref let element = this.g_cartoon.getCartoonElement(element_id).ref
let originX = element.x let originX = element.x
tweenChange(element,{ x: originX - 10*this.g_mapScale }, 0.1, ()=>{ tweenChange(element, { x: originX - 10 * this.g_mapScale }, 0.1, () => {
tweenChange(element,{ x: originX + 10*this.g_mapScale }, 0.1, ()=>{ tweenChange(element, { x: originX + 10 * this.g_mapScale }, 0.1, () => {
tweenChange(element,{ x: originX }, 0.1, ()=>{ tweenChange(element, { x: originX }, 0.1, () => {
callback && callback() callback && callback()
}) })
}) })
}) })
} }
convertPercentToRadian(per, direction){ convertPercentToRadian(per, direction) {
let radian = 0; let radian = 0;
if(direction) { //逆时针 if (direction) { //逆时针
if(per*360 > 270){ if (per * 360 > 270) {
radian = 361 - (per*360 - 270) radian = 361 - (per * 360 - 270)
}else{ } else {
radian = 270 - per*360 radian = 270 - per * 360
} }
}else{ //顺时针 } else { //顺时针
if(per*360 > 90){ if (per * 360 > 90) {
radian = per*360 - 90 radian = per * 360 - 90
}else{ } else {
radian = 270 + per*360 radian = 270 + per * 360
} }
} }
return (radian * Math.PI) / 180; return (radian * Math.PI) / 180;
} }
showBlingStar(element, callback?){ showBlingStar(element, callback?) {
let rect = element.getBoundingBox() let rect = element.getBoundingBox()
showBlingBling(this.g_cartoon.images.get('icon_star'), rect, element, 0.5, 1, 0.08, 0.5); showBlingBling(this.g_cartoon.images.get('icon_star'), rect, element, 0.5, 1, 0.08, 0.5);
this.m_setTimeoutIDs.push(setTimeout(() => { this.m_setTimeoutIDs.push(setTimeout(() => {
...@@ -1913,19 +1920,19 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1913,19 +1920,19 @@ export class PlayComponent implements OnInit, OnDestroy {
// },400) // },400)
} }
movePaoWuxian(element,dis,time,callback?){ movePaoWuxian(element, dis, time, callback?) {
let disX = dis.x - element.x let disX = dis.x - element.x
let disY = (element.y - dis.y) let disY = (element.y - dis.y)
let count = 0 let count = 0
let runTime = time/5 let runTime = time / 5
let vx = disX/runTime let vx = disX / runTime
let a = -0.05 let a = -0.05
let vy0 = disY/runTime - 0.5*a*runTime let vy0 = disY / runTime - 0.5 * a * runTime
let id = setInterval(()=>{ let id = setInterval(() => {
element.x += vx element.x += vx
element.y -= vy0 + a*count element.y -= vy0 + a * count
count++; count++;
if(count>runTime){ if (count > runTime) {
clearInterval(id) clearInterval(id)
callback && callback() callback && callback()
} }
......
import os
import json
def file_name(file_dir):
fileList =["bg_kuang", "bg_kuang2", "bg_light"]
f = open('filename.txt', 'w');
blank = False
for root, dirs, files in os.walk(file_dir):
for fileName in files:
if root.split("\\")[-1]=="frame" or root.split("\\")[-1]=="sound" or root.split("\\")[-1]=="play" or (root.split("\\")[-1] in fileList):
blank = True
if root.split("\\")[-1] != "play":
f.write("'" + fileName.split(".")[0] + "': 'assets/play/" + root.split("\\")[-1] + "/" + fileName + "',\n")
else:
f.write("'" + fileName.split(".")[0] + "': 'assets/" + root.split("\\")[-1] + "/" + fileName + "',\n")
if blank:
f.write("\n")
blank = False
f.close()
fileList = file_name(os.path.abspath('.'))
'bg_70_40': 'assets/play/bg_70_40.png',
'creatJsonProfile': 'assets/play/creatJsonProfile.py',
'filename': 'assets/play/filename.txt',
'line': 'assets/play/line.png',
'num-1': 'assets/play/num-1.png',
'num-2': 'assets/play/num-2.png',
'num-3': 'assets/play/num-3.png',
'num-4': 'assets/play/num-4.png',
'num-5': 'assets/play/num-5.png',
'num-6': 'assets/play/num-6.png',
'num-7': 'assets/play/num-7.png',
'num-8': 'assets/play/num-8.png',
'oval-copy': 'assets/play/oval-copy.png',
'question-bg': 'assets/play/question-bg.png',
'resizeImg': 'assets/play/resizeImg.py',
'1': 'assets/play/sound/1.mp3',
'2': 'assets/play/sound/2.mp3',
'3': 'assets/play/sound/3.mp3',
'check': 'assets/play/sound/check.mp3',
'fanye': 'assets/play/sound/fanye.mp3',
'jifen': 'assets/play/sound/jifen.mp3',
'kulian': 'assets/play/sound/kulian.mp3',
'putong': 'assets/play/sound/putong.mp3',
'start': 'assets/play/sound/start.mp3',
'xianshi': 'assets/play/sound/xianshi.mp3',
'xiaolian': 'assets/play/sound/xiaolian.mp3',
'xingxing': 'assets/play/sound/xingxing.mp3',
import os
import json
def file_name(file_dir):
fileList =["bg_kuang", "bg_kuang2", "bg_light"]
f = open('filename.txt', 'w');
blank = False
for root, dirs, files in os.walk(file_dir):
for fileName in files:
print(root.split("\\")[-1])
f.write("'" + fileName.split(".")[0] + "': 'assets/hotZooCard/" + root.split("\\")[-1] + "/" + fileName + "',\n")
f.close()
fileList = file_name(os.path.abspath('.'))
'bg_70_40_1': 'assets/hotZooCard/hotZooCard/bg_70_40_1.png',
'bg_70_40_10': 'assets/hotZooCard/hotZooCard/bg_70_40_10.png',
'bg_70_40_11': 'assets/hotZooCard/hotZooCard/bg_70_40_11.png',
'bg_70_40_12': 'assets/hotZooCard/hotZooCard/bg_70_40_12.png',
'bg_70_40_13': 'assets/hotZooCard/hotZooCard/bg_70_40_13.png',
'bg_70_40_14': 'assets/hotZooCard/hotZooCard/bg_70_40_14.png',
'bg_70_40_15': 'assets/hotZooCard/hotZooCard/bg_70_40_15.png',
'bg_70_40_16': 'assets/hotZooCard/hotZooCard/bg_70_40_16.png',
'bg_70_40_17': 'assets/hotZooCard/hotZooCard/bg_70_40_17.png',
'bg_70_40_18': 'assets/hotZooCard/hotZooCard/bg_70_40_18.png',
'bg_70_40_19': 'assets/hotZooCard/hotZooCard/bg_70_40_19.png',
'bg_70_40_2': 'assets/hotZooCard/hotZooCard/bg_70_40_2.png',
'bg_70_40_20': 'assets/hotZooCard/hotZooCard/bg_70_40_20.png',
'bg_70_40_21': 'assets/hotZooCard/hotZooCard/bg_70_40_21.png',
'bg_70_40_22': 'assets/hotZooCard/hotZooCard/bg_70_40_22.png',
'bg_70_40_23': 'assets/hotZooCard/hotZooCard/bg_70_40_23.png',
'bg_70_40_24': 'assets/hotZooCard/hotZooCard/bg_70_40_24.png',
'bg_70_40_25': 'assets/hotZooCard/hotZooCard/bg_70_40_25.png',
'bg_70_40_3': 'assets/hotZooCard/hotZooCard/bg_70_40_3.png',
'bg_70_40_4': 'assets/hotZooCard/hotZooCard/bg_70_40_4.png',
'bg_70_40_5': 'assets/hotZooCard/hotZooCard/bg_70_40_5.png',
'bg_70_40_6': 'assets/hotZooCard/hotZooCard/bg_70_40_6.png',
'bg_70_40_7': 'assets/hotZooCard/hotZooCard/bg_70_40_7.png',
'bg_70_40_8': 'assets/hotZooCard/hotZooCard/bg_70_40_8.png',
'bg_70_40_9': 'assets/hotZooCard/hotZooCard/bg_70_40_9.png',
'creatJsonProfile': 'assets/hotZooCard/hotZooCard/creatJsonProfile.py',
'filename': 'assets/hotZooCard/hotZooCard/filename.txt',
import os
import shutil
from PIL import Image
fileName = os.listdir('./')
withBorder = False
border_left = ""
border_right = ""
imageName = input("图片名:")
if input("是否包含边框? (y/n):")=="y":
withBorder = True
if withBorder:
border_left = input("左边框文件名:")
border_right = input("右边框文件名:")
number = int(input("数量:"))
if os.path.exists('./' + imageName + '/'):
shutil.rmtree('./' + imageName + '/')
os.mkdir('./' + imageName + '/')
pic = Image.open('./' + imageName + '.PNG')
width = pic.width
height = pic.height
f = open('./' + imageName + '/' + imageName + '_map.txt', 'w')
if withBorder:
borderImg_left, borderImg_right = Image.open('./' + border_left + '.PNG'), Image.open('./' + border_right + '.PNG')
for index in range(1, number):
newpic = pic.resize((width*index, height),Image.ANTIALIAS)
loc1, loc2, loc3 = (0, 0), (borderImg_left.width, 0), (borderImg_left.width +newpic.width, 0)
join_pic = Image.new('RGBA', (borderImg_left.width + newpic.width + borderImg_right.width, newpic.height))
join_pic.paste(borderImg_left, loc1)
join_pic.paste(newpic, loc2)
join_pic.paste(borderImg_right, loc3)
join_pic.save('./' + imageName + '/' + imageName + '_' + str(index) + 'x.PNG')
f.write('"' + str(width*index) + '": "' + imageName + '_' + str(index) + 'x",\n')
f.close()
else:
for index in range(1, number):
newpic = pic.resize((width*index, height),Image.ANTIALIAS)
newpic.save('./' + imageName + '/' + imageName + '_' + str(index) + 'x.PNG')
f.write('"' + str(width*index) + '": "' + imageName + '_' + str(index) + 'x",\n')
f.close()
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh">
<head>
<head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>NgOne</title> <title>NgOne</title>
<base href="/" /> <base href="/" />
<style> <style>
html, body{ html,
body {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" />
<!-- <script type="text/javascript" src="http://teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js" ></script> --> <!-- <script type="text/javascript" src="http://teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js" ></script> -->
<script type="text/javascript" src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air_online.js"></script> <script type="text/javascript"
</head> src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
<body> </head>
<body>
<app-root></app-root> <app-root></app-root>
</body> </body>
</html> </html>
\ 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