forked from comozilla/parapara-canvas-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
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
shundroid
committed
May 4, 2016
1 parent
10ed02a
commit fb97dbe
Showing
4 changed files
with
50 additions
and
0 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
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,34 @@ | ||
import eventPublisher from "./publisher"; | ||
|
||
// 将来的にもこれが変えられると面白いような(#85 参照) | ||
const playInterval = 250; | ||
|
||
/** | ||
* 再生しているかを表すisPlayingを所持し、 | ||
* 再生された時に、Frameを切り替える処理もここで行う。 | ||
* 再生された時に他に必要な処理(Menuを隠すなど)は、各自クラスでsubscribeして行う。 | ||
*/ | ||
function Player(framesController) { | ||
this.isPlaying = false; | ||
this.playInterval = playInterval; | ||
this.framesController = framesController; | ||
eventPublisher.subscribe("isPlaying", (isPlaying) => { | ||
this.isPlaying = isPlaying; | ||
this.changeFrame(0); | ||
}); | ||
} | ||
|
||
Player.prototype.changeFrame = function(currentFrameId) { | ||
let nextCurrentFrameId; | ||
this.framesController.setCurrentFrame(currentFrameId); | ||
if (currentFrameId >= this.framesController.frames.length - 1) { | ||
nextCurrentFrameId = 0; | ||
} else { | ||
nextCurrentFrameId = currentFrameId + 1; | ||
} | ||
setTimeout(() => { | ||
this.changeFrame(nextCurrentFrameId); | ||
}, this.playInterval); | ||
}; | ||
|
||
export default Player; |
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,10 @@ | ||
import eventPublisher from "./../publisher"; | ||
|
||
function PlayerView(element) { | ||
this.element = element; | ||
this.element.addEventListener("click", () => { | ||
eventPublisher.publish("isPlaying", true); | ||
}); | ||
} | ||
|
||
export default PlayerView; |