Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
YM_L5_26
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
YM_L5_26
Commits
429b4c9c
Commit
429b4c9c
authored
Jun 15, 2021
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 删除无用的代码
parent
96599ac9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
231 deletions
+7
-231
form.component.ts
src/app/form/form.component.ts
+0
-4
play.component.ts
src/app/play/play.component.ts
+7
-227
No files found.
src/app/form/form.component.ts
View file @
429b4c9c
...
@@ -56,10 +56,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
...
@@ -56,10 +56,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this
.
item
=
data
;
this
.
item
=
data
;
}
}
if
(
!
this
.
item
.
groupTitle
)
{
this
.
item
.
groupTitle
=
[
''
,
''
,
''
,
''
];
}
this
.
init
();
this
.
init
();
this
.
changeDetectorRef
.
markForCheck
();
this
.
changeDetectorRef
.
markForCheck
();
this
.
changeDetectorRef
.
detectChanges
();
this
.
changeDetectorRef
.
detectChanges
();
...
...
src/app/play/play.component.ts
View file @
429b4c9c
import
{
Component
,
ElementRef
,
ViewChild
,
OnInit
,
Input
,
OnDestroy
,
HostListener
}
from
'
@angular/core
'
;
import
{
Component
,
ElementRef
,
ViewChild
,
OnInit
,
Input
,
OnDestroy
,
HostListener
}
from
'
@angular/core
'
;
import
{
import
{
Label
,
Label
,
MySprite
,
tweenChange
,
MySprite
,
tweenChange
,
}
from
'
./Unit
'
;
}
from
'
./Unit
'
;
import
{
res
,
resAudio
}
from
'
./resources
'
;
import
{
res
,
resAudio
}
from
'
./resources
'
;
...
@@ -12,9 +9,6 @@ import {debounceTime} from 'rxjs/operators';
...
@@ -12,9 +9,6 @@ import {debounceTime} from 'rxjs/operators';
import
TWEEN
from
'
@tweenjs/tween.js
'
;
import
TWEEN
from
'
@tweenjs/tween.js
'
;
@
Component
({
@
Component
({
selector
:
'
app-play
'
,
selector
:
'
app-play
'
,
templateUrl
:
'
./play.component.html
'
,
templateUrl
:
'
./play.component.html
'
,
...
@@ -57,26 +51,16 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -57,26 +51,16 @@ export class PlayComponent implements OnInit, OnDestroy {
canvasLeft
;
canvasLeft
;
canvasTop
;
canvasTop
;
saveKey
=
'
test_0011
'
;
saveKey
=
'
test_001211
'
;
btnLeft
;
btnRight
;
pic1
;
pic2
;
canTouch
=
true
;
canTouch
=
true
;
curPic
;
@
HostListener
(
'
window:resize
'
,
[
'
$event
'
])
@
HostListener
(
'
window:resize
'
,
[
'
$event
'
])
onResize
(
event
)
{
onResize
(
event
)
{
this
.
winResizeEventStream
.
next
();
this
.
winResizeEventStream
.
next
();
}
}
ngOnInit
()
{
ngOnInit
()
{
this
.
data
=
{};
this
.
data
=
{};
// 获取数据
// 获取数据
...
@@ -145,20 +129,13 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -145,20 +129,13 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
canvas
.
nativeElement
.
width
=
this
.
wrap
.
nativeElement
.
clientWidth
;
this
.
canvas
.
nativeElement
.
width
=
this
.
wrap
.
nativeElement
.
clientWidth
;
this
.
canvas
.
nativeElement
.
height
=
this
.
wrap
.
nativeElement
.
clientHeight
;
this
.
canvas
.
nativeElement
.
height
=
this
.
wrap
.
nativeElement
.
clientHeight
;
this
.
ctx
=
this
.
canvas
.
nativeElement
.
getContext
(
'
2d
'
);
this
.
ctx
=
this
.
canvas
.
nativeElement
.
getContext
(
'
2d
'
);
this
.
canvas
.
nativeElement
.
width
=
this
.
canvasWidth
;
this
.
canvas
.
nativeElement
.
width
=
this
.
canvasWidth
;
this
.
canvas
.
nativeElement
.
height
=
this
.
canvasHeight
;
this
.
canvas
.
nativeElement
.
height
=
this
.
canvasHeight
;
window
[
'
curCtx
'
]
=
this
.
ctx
;
window
[
'
curCtx
'
]
=
this
.
ctx
;
window
[
'
curImages
'
]
=
this
.
images
;
}
}
updateItem
(
item
)
{
updateItem
(
item
)
{
if
(
item
)
{
if
(
item
)
{
item
.
update
();
item
.
update
();
...
@@ -174,12 +151,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -174,12 +151,6 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
}
}
initListener
()
{
initListener
()
{
this
.
winResizeEventStream
this
.
winResizeEventStream
...
@@ -188,7 +159,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -188,7 +159,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
renderAfterResize
();
this
.
renderAfterResize
();
});
});
// ---------------------------------------------
// ---------------------------------------------
const
setParentOffset
=
()
=>
{
const
setParentOffset
=
()
=>
{
const
rect
=
this
.
canvas
.
nativeElement
.
getBoundingClientRect
();
const
rect
=
this
.
canvas
.
nativeElement
.
getBoundingClientRect
();
...
@@ -212,7 +182,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -212,7 +182,6 @@ export class PlayComponent implements OnInit, OnDestroy {
};
};
// ---------------------------------------------
// ---------------------------------------------
let
firstTouch
=
true
;
let
firstTouch
=
true
;
const
touchDownFunc
=
(
e
)
=>
{
const
touchDownFunc
=
(
e
)
=>
{
...
@@ -249,7 +218,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -249,7 +218,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
mapUp
(
e
);
this
.
mapUp
(
e
);
};
};
const
element
=
this
.
canvas
.
nativeElement
;
const
element
=
this
.
canvas
.
nativeElement
;
const
addTouchListener
=
()
=>
{
const
addTouchListener
=
()
=>
{
...
@@ -280,7 +248,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -280,7 +248,6 @@ export class PlayComponent implements OnInit, OnDestroy {
addTouchListener
();
addTouchListener
();
}
}
playAudio
(
key
,
now
=
false
,
callback
=
null
)
{
playAudio
(
key
,
now
=
false
,
callback
=
null
)
{
const
audio
=
this
.
audioObj
[
key
];
const
audio
=
this
.
audioObj
[
key
];
...
@@ -299,8 +266,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -299,8 +266,6 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
}
}
loadResources
()
{
loadResources
()
{
const
pr
=
[];
const
pr
=
[];
this
.
rawImages
.
forEach
((
value
,
key
)
=>
{
// 预加载图片
this
.
rawImages
.
forEach
((
value
,
key
)
=>
{
// 预加载图片
...
@@ -341,7 +306,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -341,7 +306,7 @@ export class PlayComponent implements OnInit, OnDestroy {
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
audio
=
new
Audio
();
const
audio
=
new
Audio
();
audio
.
oncanplay
=
(
a
)
=>
{
audio
.
oncanplay
=
(
a
)
=>
{
resolve
();
resolve
(
null
);
};
};
audio
.
onerror
=
()
=>
{
audio
.
onerror
=
()
=>
{
reject
();
reject
();
...
@@ -351,17 +316,12 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -351,17 +316,12 @@ export class PlayComponent implements OnInit, OnDestroy {
});
});
}
}
renderAfterResize
()
{
renderAfterResize
()
{
this
.
canvasWidth
=
this
.
wrap
.
nativeElement
.
clientWidth
;
this
.
canvasWidth
=
this
.
wrap
.
nativeElement
.
clientWidth
;
this
.
canvasHeight
=
this
.
wrap
.
nativeElement
.
clientHeight
;
this
.
canvasHeight
=
this
.
wrap
.
nativeElement
.
clientHeight
;
this
.
init
();
this
.
init
();
}
}
checkClickTarget
(
target
)
{
checkClickTarget
(
target
)
{
const
rect
=
target
.
getBoundingBox
();
const
rect
=
target
.
getBoundingBox
();
...
@@ -394,10 +354,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -394,10 +354,6 @@ export class PlayComponent implements OnInit, OnDestroy {
return
false
;
return
false
;
}
}
addUrlToAudioObj
(
key
,
url
=
null
,
vlomue
=
1
,
loop
=
false
,
callback
=
null
)
{
addUrlToAudioObj
(
key
,
url
=
null
,
vlomue
=
1
,
loop
=
false
,
callback
=
null
)
{
const
audioObj
=
this
.
audioObj
;
const
audioObj
=
this
.
audioObj
;
...
@@ -427,60 +383,42 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -427,60 +383,42 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
rawImages
.
set
(
url
,
url
);
this
.
rawImages
.
set
(
url
,
url
);
}
}
// ======================================================编写区域==========================================================================
// ======================================================编写区域==========================================================================
/**
/**
* 添加默认数据 便于无数据时的展示
* 添加默认数据 便于无数据时的展示
*/
*/
initDefaultData
()
{
initDefaultData
()
{
if
(
!
this
.
data
.
pic_url
)
{
if
(
!
this
.
data
.
pic_url
)
{
this
.
data
.
pic_url
=
'
assets/play/default/pic.jpg
'
;
this
.
data
.
pic_url
=
'
assets/play/default/pic.jpg
'
;
this
.
data
.
pic_url_2
=
'
assets/play/default/pic.jpg
'
;
this
.
data
.
pic_url_2
=
'
assets/play/default/pic.jpg
'
;
}
}
}
}
/**
/**
* 添加预加载图片
* 添加预加载图片
*/
*/
initImg
()
{
initImg
()
{
this
.
addUrlToImages
(
this
.
data
.
pic_url
);
this
.
addUrlToImages
(
this
.
data
.
pic_url
);
this
.
addUrlToImages
(
this
.
data
.
pic_url_2
);
this
.
addUrlToImages
(
this
.
data
.
pic_url_2
);
}
}
/**
/**
* 添加预加载音频
* 添加预加载音频
*/
*/
initAudio
()
{
initAudio
()
{
// 音频资源
// 音频资源
this
.
addUrlToAudioObj
(
this
.
data
.
audio_url
);
this
.
addUrlToAudioObj
(
this
.
data
.
audio_url
);
this
.
addUrlToAudioObj
(
this
.
data
.
audio_url_2
);
this
.
addUrlToAudioObj
(
this
.
data
.
audio_url_2
);
// 音效
// 音效
this
.
addUrlToAudioObj
(
'
click
'
,
this
.
rawAudios
.
get
(
'
click
'
),
0.3
);
this
.
addUrlToAudioObj
(
'
click
'
,
this
.
rawAudios
.
get
(
'
click
'
),
0.3
);
}
}
/**
/**
* 初始化数据
* 初始化数据
*/
*/
initData
()
{
initData
()
{
const
sx
=
this
.
canvasWidth
/
this
.
canvasBaseW
;
const
sx
=
this
.
canvasWidth
/
this
.
canvasBaseW
;
const
sy
=
this
.
canvasHeight
/
this
.
canvasBaseH
;
const
sy
=
this
.
canvasHeight
/
this
.
canvasBaseH
;
const
s
=
Math
.
min
(
sx
,
sy
);
const
s
=
Math
.
min
(
sx
,
sy
);
...
@@ -489,173 +427,25 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -489,173 +427,25 @@ export class PlayComponent implements OnInit, OnDestroy {
// this.mapScale = sx;
// this.mapScale = sx;
// this.mapScale = sy;
// this.mapScale = sy;
this
.
renderArr
=
[];
this
.
renderArr
=
[];
}
}
/**
/**
* 初始化试图
* 初始化试图
*/
*/
initView
()
{
initView
()
{
this
.
initPic
();
this
.
initBottomPart
();
}
initBottomPart
()
{
const
btnLeft
=
new
MySprite
();
btnLeft
.
init
(
this
.
images
.
get
(
'
btn_left
'
));
btnLeft
.
x
=
this
.
canvasWidth
-
150
*
this
.
mapScale
;
btnLeft
.
y
=
this
.
canvasHeight
-
100
*
this
.
mapScale
;
btnLeft
.
setScaleXY
(
this
.
mapScale
);
this
.
renderArr
.
push
(
btnLeft
);
this
.
btnLeft
=
btnLeft
;
const
btnRight
=
new
MySprite
();
btnRight
.
init
(
this
.
images
.
get
(
'
btn_right
'
));
btnRight
.
x
=
this
.
canvasWidth
-
50
*
this
.
mapScale
;
btnRight
.
y
=
this
.
canvasHeight
-
100
*
this
.
mapScale
;
btnRight
.
setScaleXY
(
this
.
mapScale
);
this
.
renderArr
.
push
(
btnRight
);
this
.
btnRight
=
btnRight
;
}
initPic
()
{
const
maxW
=
this
.
canvasWidth
*
0.7
;
const
pic1
=
new
MySprite
();
pic1
.
init
(
this
.
images
.
get
(
this
.
data
.
pic_url
));
pic1
.
x
=
this
.
canvasWidth
/
2
;
pic1
.
y
=
this
.
canvasHeight
/
2
;
pic1
.
setScaleXY
(
maxW
/
pic1
.
width
);
this
.
renderArr
.
push
(
pic1
);
this
.
pic1
=
pic1
;
const
label1
=
new
Label
();
label1
.
text
=
this
.
data
.
text
;
label1
.
textAlign
=
'
center
'
;
label1
.
fontSize
=
50
;
label1
.
fontName
=
'
BRLNSDB
'
;
label1
.
fontColor
=
'
#ffffff
'
;
pic1
.
addChild
(
label1
);
const
pic2
=
new
MySprite
();
pic2
.
init
(
this
.
images
.
get
(
this
.
data
.
pic_url_2
));
pic2
.
x
=
this
.
canvasWidth
/
2
+
this
.
canvasWidth
;
pic2
.
y
=
this
.
canvasHeight
/
2
;
pic2
.
setScaleXY
(
maxW
/
pic2
.
width
);
this
.
renderArr
.
push
(
pic2
);
this
.
pic2
=
pic2
;
this
.
curPic
=
pic1
;
}
btnLeftClicked
()
{
this
.
lastPage
();
}
btnRightClicked
()
{
this
.
nextPage
();
}
lastPage
()
{
if
(
this
.
curPic
==
this
.
pic1
)
{
return
;
}
this
.
canTouch
=
false
;
const
moveLen
=
this
.
canvasWidth
;
tweenChange
(
this
.
pic1
,
{
x
:
this
.
pic1
.
x
+
moveLen
},
1
);
tweenChange
(
this
.
pic2
,
{
x
:
this
.
pic2
.
x
+
moveLen
},
1
,
()
=>
{
this
.
canTouch
=
true
;
this
.
curPic
=
this
.
pic1
;
});
}
nextPage
()
{
if
(
this
.
curPic
==
this
.
pic2
)
{
return
;
}
this
.
canTouch
=
false
;
const
moveLen
=
this
.
canvasWidth
;
tweenChange
(
this
.
pic1
,
{
x
:
this
.
pic1
.
x
-
moveLen
},
1
);
tweenChange
(
this
.
pic2
,
{
x
:
this
.
pic2
.
x
-
moveLen
},
1
,
()
=>
{
this
.
canTouch
=
true
;
this
.
curPic
=
this
.
pic2
;
});
}
pic1Clicked
()
{
this
.
playAudio
(
this
.
data
.
audio_url
);
}
pic2Clicked
()
{
this
.
playAudio
(
this
.
data
.
audio_url_2
);
}
}
mapDown
(
event
)
{
mapDown
(
event
)
{
if
(
!
this
.
canTouch
)
{
if
(
!
this
.
canTouch
)
{
return
;
return
;
}
}
if
(
this
.
checkClickTarget
(
this
.
btnLeft
)
)
{
// if ( this.checkClickTarget(this.btnLeft) ) {
this
.
btnLeftClicked
();
// this.btnLeftClicked();
return
;
// return;
}
// }
if
(
this
.
checkClickTarget
(
this
.
btnRight
)
)
{
this
.
btnRightClicked
();
return
;
}
if
(
this
.
checkClickTarget
(
this
.
pic1
)
)
{
this
.
pic1Clicked
();
return
;
}
if
(
this
.
checkClickTarget
(
this
.
pic2
)
)
{
this
.
pic2Clicked
();
return
;
}
}
}
mapMove
(
event
)
{
mapMove
(
event
)
{
...
@@ -666,10 +456,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -666,10 +456,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
update
()
{
update
()
{
// ----------------------------------------------------------
// ----------------------------------------------------------
this
.
animationId
=
window
.
requestAnimationFrame
(
this
.
update
.
bind
(
this
));
this
.
animationId
=
window
.
requestAnimationFrame
(
this
.
update
.
bind
(
this
));
// 清除画布内容
// 清除画布内容
...
@@ -678,13 +465,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -678,13 +465,6 @@ export class PlayComponent implements OnInit, OnDestroy {
TWEEN
.
update
();
TWEEN
.
update
();
// ----------------------------------------------------------
// ----------------------------------------------------------
this
.
updateArr
(
this
.
renderArr
);
this
.
updateArr
(
this
.
renderArr
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment