Skip to content

Commit

Permalink
Make it works again
Browse files Browse the repository at this point in the history
  • Loading branch information
alvachien committed May 2, 2024
1 parent 3873473 commit a032182
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 60 deletions.
6 changes: 6 additions & 0 deletions src/app/models/english-learning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('EnglishWordExplaination', () => {
testobj.explain = 'test';
expect(testobj.explain).toBeTruthy();
});

it('parseData', () => {
const explaincont = `n. 人,人们;人民;民众;国民;民族 `;
testobj.parseData(explaincont);
expect(testobj.partsOfSpeeches).toContain(EnglishPartsofSpeechEnum.Nouns);
});
});

describe('EnglishWord', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/models/english-learning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export class EnglishWordExplaination {
}
});
}
this.explain = expstr.substring(spidx + 1);
this.explain = expstr.substring(spidx + 1).trim();
} else {
this.explain = expstr;
this.explain = expstr.trim();
}
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export class EnglishSentence {
if (wordline.length === 0) {
if (wordcursor !== -1) {
const wordstrs = arwords.filter((val: string, index: number) => {
return index > wordcursor && index < idx;
return index >= wordcursor && index < idx;
});

const objword = new EnglishWord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<mat-option *ngFor="let coll of allCollections" [value]="coll">{{coll}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-label>File</mat-label>
<mat-select [(value)]="selectedFile" (selectionChange)="onFileSelectionChanged($event)">
<mat-option value="">None</mat-option>
<mat-option *ngFor="let file of allFiles" [value]="file">{{file.fileName}}</mat-option>
</mat-select>
</mat-form-field>
<button mat-raised-button color="primary" (click)="onRestart()">Start</button>

<section>
Expand All @@ -30,7 +37,6 @@
<div class="typing-container">
DONE!
</div>
<button (click)="onRestart()">Restart</button>
</div>
<div *ngIf="!isQueueCompleted">
<div class="typing-explain">
Expand Down
83 changes: 41 additions & 42 deletions src/app/pages/puzzle-game/typing-game/typing-game.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ interface typingWord {
letter: string;
}

interface sentenceFile {
fullPath: string;
fileName: string;
}

@Component({
selector: 'khb-typing-game',
templateUrl: './typing-game.component.html',
Expand All @@ -32,6 +37,8 @@ export class TypingGameComponent implements OnInit, AfterViewInit {
dataSource = new MatTableDataSource<any>(sentences);
allCollections: string[] = [];
selectedCollection = '';
allFiles: sentenceFile[] = [];
selectedFile?: sentenceFile;

get chararray(): typingWord[] {
return this._arwords;
Expand Down Expand Up @@ -113,63 +120,55 @@ export class TypingGameComponent implements OnInit, AfterViewInit {

onCollectionSelectionChanged(evnt: any) {
this.dataSource.filter = this.selectedCollection;
this.onRestart();
this.initFileList();
}

onFileSelectionChanged(event: any) {
this.initWordQueue();
}

onRestart() {
this.isQueueCompleted = false;
this.initWordQueue();
this.setWordQueueIndex();
}

initWordQueue() {
this.wordqueues = [];

initFileList(): void {
this.allFiles = [];
this.dataSource.filteredData.forEach((ds) => {
const fileurl =
environment.basehref === '/'
? `assets/data/english-sentences/${ds.folder}/${ds.file}`
: `${environment.basehref.substring(1)}/assets/data/english-sentences/${ds.folder}/${ds.file}`;

if (!this._service.setSentFile.has(fileurl)) {
this._service.setSentFile.add(fileurl);

this._service.readFileContent(fileurl).subscribe({
next: val => {
let sen = new EnglishSentence();
sen.parseData(val);

sen.words.forEach(word => {
this.wordqueues.push({
enword: word.word,
cnword: word.explains.join(';'),
completed: false,
});
});
},
error: err => {
console.error(err);
}
});
} else {
}
this.allFiles.push({
fullPath: fileurl,
fileName: ds.file,
});
});
}

// this.wordqueues.push({
// enword: 'asset',
// cnword: 'n. 有利条件,有价值的人或物;资产,财产',
// completed: false,
// });
// this.wordqueues.push({
// enword: 'knowledge',
// cnword: 'n. 知识,学问;知道,了解;计算机系统存储的信息;(与见解相对的)认知',
// completed: false,
// });
// this.wordqueues.push({
// enword: 'detective',
// cnword: 'n. 侦探,警探;私家侦探',
// completed: false,
// });
initWordQueue() {
this.wordqueues = [];
if (this.selectedFile) {
this._service.readFileContent(this.selectedFile.fullPath).subscribe({
next: (val) => {
const sen = new EnglishSentence();
sen.parseData(val);

sen.words.forEach((word) => {
this.wordqueues.push({
enword: word.word,
cnword: word.explains.map((expval) => expval.explain).join(';'),
completed: false,
});
});
this.setWordQueueIndex();
},
error: (err) => {
console.error(err);
},
});
}
}

setWordQueueIndex(idx = 0) {
Expand Down
14 changes: 0 additions & 14 deletions src/assets/data/english-sentences/TOEFL-100/TOEFL-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

1. **essentially**
ad. 本质上;基本上
- **essence**
n. 本质
- **essential**
adj. 本质的

2. **theory**
n. 理论,原理
Expand All @@ -23,19 +19,9 @@ a. 抽象的,抽象派的

4. **symbolic**
a. 象征的,符号的
- **symbolize**
vt. 象征
- **symbolism**
n. 象征作用,象征意义

5. **representation**
n. 代表;

6. **conceive**
v. 设想,构想
- **conceivable**
a. 可想象的
- **deceive**
vt. 欺骗
- **perceive**
vt. 觉察

0 comments on commit a032182

Please sign in to comment.