-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f114141
commit b6ff4ad
Showing
6 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { EventEmitter } from '../utils/eventmitter'; | ||
import { Danma, Commander } from '../types'; | ||
import Track from '../track'; | ||
|
||
export default abstract class Base<T extends Danma> extends EventEmitter { | ||
protected trackHeight: number; | ||
|
||
protected duration: number; | ||
|
||
protected trackCnt: number; | ||
|
||
protected tracks: Track<T>[] = []; | ||
|
||
waitingQueue: T[] = []; | ||
|
||
constructor(config: Commander) { | ||
super(); | ||
this.trackHeight = config.trackHeight; | ||
this.duration = config.duration; | ||
this.trackCnt = config.trackCnt; | ||
|
||
for (let i = 0; i < config.trackCnt; ++i) { | ||
this.tracks[i] = new Track(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import RollingCommander from './rolling'; | ||
|
||
export { RollingCommander }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class RollingCommander { | ||
constructor() { | ||
console.log(1111); | ||
} | ||
} | ||
|
||
export default RollingCommander; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Danma } from './types'; | ||
|
||
interface TrackForEachHandler<T extends Danma> { | ||
(track: T, index: number, array: T[]): void; | ||
} | ||
|
||
export default class Track<T extends Danma> { | ||
danmas: T[] = []; | ||
|
||
offset = 0; | ||
|
||
forEach(handler: TrackForEachHandler<T>) { | ||
for (let i = 0; i < this.danmas.length; ++i) { | ||
handler(this.danmas[i], i, this.danmas); | ||
} | ||
} | ||
|
||
push(...items: T[]) { | ||
this.danmas.push(...items); | ||
} | ||
|
||
removeTop() { | ||
this.danmas.shift(); | ||
} | ||
|
||
remove(index: number) { | ||
if (index < 0 || index >= this.danmas.length) { | ||
return; | ||
} | ||
this.danmas.splice(index, 1); | ||
} | ||
|
||
reset() { | ||
this.danmas = []; | ||
this.offset = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
export interface DanmakuOptions { | ||
tracks: number; | ||
tracksCnt: number; | ||
trackHeight: number; | ||
fontSize: number; | ||
duration: number; | ||
} | ||
|
||
export interface Danma { | ||
text: string; | ||
} | ||
|
||
export interface Commander { | ||
trackHeight: number; | ||
duration: number; | ||
trackCnt: number; | ||
} |