Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JM-15
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
JM-15
Commits
e5f1c4f8
Commit
e5f1c4f8
authored
Oct 13, 2021
by
limingzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加语法评测
parent
404a936f
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
368 additions
and
94 deletions
+368
-94
Unit.ts
src/app/play/Unit.ts
+98
-45
play.component.ts
src/app/play/play.component.ts
+266
-49
resources.js
src/app/play/resources.js
+4
-0
ai_icon.png
src/assets/play/ai_icon.png
+0
-0
No files found.
src/app/play/Unit.ts
View file @
e5f1c4f8
...
...
@@ -841,48 +841,67 @@ export class RichTextOld extends Label {
export
class
RichText
extends
Label
{
topH
=
8
;
topH
=
0
;
disH
=
10
;
offW
=
10
;
private
rowCount
=
1
;
row
=
1
;
textBaseline
=
"
middle
"
;
isShowWordBg
=
false
;
wordBgData
;
constructor
(
ctx
?:
any
)
{
super
(
ctx
);
// this.dataArr = dataArr;
}
getLineNum
()
{
this
.
drawSelf
();
return
this
.
row
Count
;
return
this
.
row
;
}
getAreaHeight
()
{
this
.
drawSelf
();
const
tmpTextH
=
this
.
row
Count
*
this
.
fontSize
;
const
tmpDisH
=
(
this
.
row
Count
-
1
)
*
this
.
disH
const
tmpTextH
=
this
.
row
*
this
.
fontSize
;
const
tmpDisH
=
(
this
.
row
-
1
)
*
this
.
disH
return
tmpTextH
+
tmpDisH
;
}
// addLabelMask(mask) {
// this._labelMaskArr.push(mask);
// this._createLabelOffCtx();
// }
getSubTextRectGroup
(
text
,
targetIndex
=
0
)
{
const
rectGroup
=
[];
const
subTextArr
=
text
.
split
(
'
'
);
let
baseIndex
=
targetIndex
;
console
.
log
(
'
subTextArr:
'
,
subTextArr
);
for
(
let
i
=
0
;
i
<
subTextArr
.
length
;
i
++
)
{
const
subtText
=
subTextArr
[
i
];
const
subData
=
this
.
getSubTextRect
(
subtText
,
baseIndex
)
if
(
subData
)
{
rectGroup
.
push
(
subData
);
baseIndex
=
Number
(
subData
.
index
);
}
}
// _createLabelOffCtx() {
// if (!this._labelOffCtx) {
// this._labelOffCanvas = document.createElement('canvas'); // 创建一个新的canvas
// this._labelOffCanvas.width = this.width; // 创建一个正好包裹住一个粒子canvas
// this._labelOffCanvas.height = this.height;
// this._labelOffCtx = this._labelOffCanvas.getContext('2d');
// }
// }
return
rectGroup
;
}
getSubTextRect
(
subText
,
targetIndex
=
0
)
{
subText
=
subText
.
trim
();
if
(
!
subText
)
{
return
;
}
this
.
isShowWordBg
=
true
;
this
.
update
();
getSubTextRect
(
subText
)
{
const
tmpLabel
=
new
RichText
();
tmpLabel
.
fontSize
=
this
.
fontSize
;
...
...
@@ -892,22 +911,31 @@ export class RichText extends Label {
tmpLabel
.
fontWeight
=
this
.
fontWeight
;
tmpLabel
.
width
=
this
.
width
;
tmpLabel
.
height
=
this
.
height
;
console
.
log
(
'
subText:
'
,
subText
);
console
.
log
(
'
this.text:
'
,
this
.
text
);
// const indexArr = searchSubStr(this.text, subText);
// console.log('indexArr: ', indexArr);
// const index = indexArr[targetIndex];
const
index
=
this
.
text
.
indexOf
(
subText
);
tmpLabel
.
text
=
this
.
text
.
substring
(
0
,
index
);
tmpLabel
.
refreshSize
();
const
index
=
this
.
text
.
indexOf
(
subText
,
targetIndex
);
const
x
=
tmpLabel
.
width
;
console
.
log
(
'
index:
'
,
index
);
if
(
index
==
-
1
)
{
return
;
}
tmpLabel
.
text
=
subText
;
tmpLabel
.
refreshSize
();
// console.log('this.wordBgData: ', this.wordBgData);
// const index = this.text.indexOf(subText);
// console.log('!!!index: ', index);
const
width
=
tmpLabel
.
width
;
const
data
=
this
.
wordBgData
[
index
.
toString
()];
// console.log('!!!wordBgData: ', this.wordBgData);
// console.log('!!!data: ', data);
return
data
;
const
y
=
this
.
fontSize
/
2
;
const
height
=
this
.
fontSize
;
return
{
x
,
y
,
width
,
height
}
}
...
...
@@ -930,7 +958,6 @@ export class RichText extends Label {
curCtx
=
this
.
_offCtx
;
}
curCtx
.
font
=
`
${
this
.
fontSize
}
px
${
this
.
fontName
}
`
;
curCtx
.
textAlign
=
this
.
textAlign
;
curCtx
.
textBaseline
=
this
.
textBaseline
;
...
...
@@ -943,40 +970,68 @@ export class RichText extends Label {
const
chr
=
this
.
text
.
split
(
'
'
);
let
temp
=
''
;
const
row
s
=
[];
const
row
=
[];
const
w
=
selfW
-
this
.
offW
*
2
;
const
disH
=
(
this
.
fontSize
+
this
.
disH
)
*
this
.
scaleY
;
let
isPushWordData
=
false
;
if
(
this
.
isShowWordBg
&&
!
this
.
wordBgData
)
{
this
.
wordBgData
=
{};
isPushWordData
=
true
;
}
let
wordIndex
=
-
1
;
for
(
const
c
of
chr
)
{
if
(
isPushWordData
)
{
}
for
(
const
c
of
chr
)
{
if
(
curCtx
.
measureText
(
temp
).
width
<
w
&&
curCtx
.
measureText
(
temp
+
(
c
)).
width
<=
w
)
{
if
(
c
==
'
\n
'
)
{
row
.
push
(
temp
);
temp
=
''
;
}
else
if
(
curCtx
.
measureText
(
temp
).
width
<
w
&&
curCtx
.
measureText
(
temp
+
(
c
)).
width
<=
w
)
{
temp
+=
'
'
+
c
;
}
else
{
row
s
.
push
(
temp
);
row
.
push
(
temp
);
temp
=
'
'
+
c
;
}
if
(
isPushWordData
)
{
wordIndex
=
this
.
text
.
indexOf
(
c
,
wordIndex
+
1
);
const
key
=
wordIndex
.
toString
();
const
rectX
=
curCtx
.
measureText
(
temp
).
width
const
rectY
=
(
row
.
length
)
*
disH
/
this
.
scaleY
const
rectW
=
curCtx
.
measureText
(
c
).
width
;
const
rectH
=
this
.
fontSize
;
this
.
wordBgData
[
key
]
=
{
rect
:
{
x
:
rectX
,
y
:
rectY
,
width
:
rectW
,
height
:
rectH
},
text
:
c
,
index
:
wordIndex
}
}
}
row
s
.
push
(
temp
);
row
.
push
(
temp
);
this
.
row
Count
=
rows
.
length
;
this
.
row
=
row
.
length
;
const
x
=
0
;
const
y
=
this
.
topH
;
const
y
=
this
.
topH
//-row.length * disH / 2;
// for (let b = 0 ; b < row.length; b++) {
// curCtx.strokeText(row[b], x, y + ( b + 1 ) * disH ); // 每行字体y坐标间隔20
// }
if
(
this
.
_outlineFlag
)
{
curCtx
.
lineWidth
=
this
.
_outLineWidth
;
curCtx
.
strokeStyle
=
this
.
_outLineColor
;
for
(
let
b
=
0
;
b
<
row
s
.
length
;
b
++
)
{
curCtx
.
strokeText
(
row
s
[
b
],
x
,
y
+
(
b
+
0
)
*
disH
/
this
.
scaleY
);
// 每行字体y坐标间隔20
for
(
let
b
=
0
;
b
<
row
.
length
;
b
++
)
{
curCtx
.
strokeText
(
row
[
b
],
x
,
y
+
(
b
+
0
)
*
disH
/
this
.
scaleY
);
// 每行字体y坐标间隔20
}
// curCtx.strokeText(this.text, 0, 0);
}
for
(
let
b
=
0
;
b
<
rows
.
length
;
b
++
)
{
curCtx
.
fillText
(
rows
[
b
],
x
,
y
+
(
b
+
0
)
*
disH
/
this
.
scaleY
);
// 每行字体y坐标间隔20
// curCtx.fillStyle = '#ff7600';
for
(
let
b
=
0
;
b
<
row
.
length
;
b
++
)
{
curCtx
.
fillText
(
row
[
b
],
x
,
y
+
(
b
+
0
)
*
disH
/
this
.
scaleY
);
// 每行字体y坐标间隔20
}
...
...
@@ -991,7 +1046,6 @@ export class RichText extends Label {
this
.
_maskSprArr
[
i
].
ctx
=
this
.
_offCtx
;
this
.
_maskSprArr
[
i
].
update
();
}
// console.log('aaaaa1');
}
...
...
@@ -1001,11 +1055,10 @@ export class RichText extends Label {
}
drawSelf
()
{
super
.
drawSelf
();
this
.
drawText
();
}
}
...
...
src/app/play/play.component.ts
View file @
e5f1c4f8
This diff is collapsed.
Click to expand it.
src/app/play/resources.js
View file @
e5f1c4f8
...
...
@@ -32,6 +32,8 @@ const res = [
[
'
info_icon
'
,
"
assets/play/info_icon.png
"
],
[
'
info_bg
'
,
"
assets/play/info_bg.png
"
],
[
'
ai_icon
'
,
"
assets/play/ai_icon.png
"
],
];
...
...
@@ -42,6 +44,8 @@ const resAudio = [
[
'
submit
'
,
"
assets/play/music/submit.mp3
"
],
[
'
more
'
,
"
assets/play/music/more.mp3
"
],
];
export
{
res
,
resAudio
};
...
...
src/assets/play/ai_icon.png
0 → 100644
View file @
e5f1c4f8
3.44 KB
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