Refactoring time!!
parent
aefad322b2
commit
145e66ca18
@ -0,0 +1,4 @@
|
||||
class AsciiIo.HudView
|
||||
constructor: (element) ->
|
||||
@element = $(element)
|
||||
|
@ -1,17 +1,12 @@
|
||||
class AsciiIo.Player
|
||||
class AsciiIo.Movie
|
||||
MIN_DELAY: 0.01
|
||||
SPEED: 1.0
|
||||
|
||||
constructor: (cols, lines, data, timing) ->
|
||||
@terminal = new AsciiIo.Terminal(cols, lines)
|
||||
@interpreter = new AsciiIo.AnsiInterpreter(@terminal)
|
||||
@data = data
|
||||
@timing = timing
|
||||
@dataIndex = 0
|
||||
@frameNo = 0
|
||||
@currentData = ""
|
||||
console.log "started"
|
||||
@startTime = (new Date()).getTime()
|
||||
constructor: (@data, @timing) ->
|
||||
@currentTime = 0
|
||||
@processedFramesTime = 0
|
||||
|
||||
play: ->
|
||||
@nextFrame()
|
||||
|
||||
nextFrame: () ->
|
@ -0,0 +1,13 @@
|
||||
class AsciiIo.PlayerView
|
||||
|
||||
constructor: (@element, cols, lines, data, timing) ->
|
||||
terminalElement = $('<pre class="terminal">')
|
||||
hudElement = $('<div class="hud">')
|
||||
|
||||
@element.append(terminalElement)
|
||||
@element.append(hudElement)
|
||||
|
||||
# @interpreter ?
|
||||
@terminal = new AsciiIo.TerminalView(terminalElement[0], cols, lines)
|
||||
@hud = new AsciiIo.HudView(hudElement[0])
|
||||
@movie = new AsciiIo.Movie(data, timing)
|
@ -1,8 +1,6 @@
|
||||
class AsciiIo.Terminal
|
||||
constructor: (cols, lines) ->
|
||||
@element = $(".player .term")
|
||||
@cols = cols
|
||||
@lines = lines
|
||||
class AsciiIo.TerminalView
|
||||
constructor: (element, @cols, @lines) ->
|
||||
@element = $(element) # $(".player .term")
|
||||
@cursorX = 0
|
||||
@cursorY = 0
|
||||
@normalBuffer = []
|
@ -0,0 +1,3 @@
|
||||
describe AsciiIo.AnsiInterpreter, ->
|
||||
it 'rocks', ->
|
||||
expect(1).toBeTruthy()
|
@ -0,0 +1,9 @@
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toBePlaying: function(expectedSong) {
|
||||
var player = this.actual;
|
||||
return player.currentlyPlayingSong === expectedSong &&
|
||||
player.isPlaying;
|
||||
}
|
||||
});
|
||||
});
|
@ -0,0 +1,15 @@
|
||||
describe AsciiIo.HudView, ->
|
||||
|
||||
describe 'constructor', ->
|
||||
it 'creates child elements', ->
|
||||
|
||||
describe 'play/pause button', ->
|
||||
it 'triggers hud-play-click when click is fired', ->
|
||||
|
||||
describe 'progress bar', ->
|
||||
it 'triggers hud-seek-click when click is fired', ->
|
||||
|
||||
describe 'fullscreen toggle', ->
|
||||
it 'triggers hud-fullscreen-click when click is fired', ->
|
||||
|
||||
# describe 'time display', ->
|
@ -0,0 +1,21 @@
|
||||
describe AsciiIo.Movie, ->
|
||||
|
||||
describe '#play', ->
|
||||
it 'calls nextFrame', ->
|
||||
movie = new AsciiIo.Movie('', [])
|
||||
spyOn movie, 'nextFrame'
|
||||
movie.play()
|
||||
expect(movie.nextFrame).toHaveBeenCalled()
|
||||
|
||||
describe '#pause', ->
|
||||
|
||||
describe '#toggle', ->
|
||||
|
||||
describe '#seek', ->
|
||||
|
||||
describe '#nextFrame', ->
|
||||
describe 'when playing', ->
|
||||
it 'triggers movie-frame event', ->
|
||||
|
||||
describe 'when finished', ->
|
||||
it 'triggers movie-finished event', ->
|
@ -0,0 +1,43 @@
|
||||
describe AsciiIo.PlayerView, ->
|
||||
element = null
|
||||
cols = 2
|
||||
lines = 5
|
||||
data = ''
|
||||
timing = []
|
||||
|
||||
beforeEach ->
|
||||
element = $('<div>')
|
||||
|
||||
describe 'constructor', ->
|
||||
it 'creates needed DOM elements inside player element', ->
|
||||
player = new AsciiIo.PlayerView(element, cols, lines, data, timing)
|
||||
expect(element.find('.terminal').length).toBe(1)
|
||||
expect(element.find('.hud').length).toBe(1)
|
||||
|
||||
it 'creates TerminalView instance passing proper DOM element', ->
|
||||
spyOn(AsciiIo, 'TerminalView')
|
||||
player = new AsciiIo.PlayerView(element, cols, lines, data, timing)
|
||||
expect(AsciiIo.TerminalView).toHaveBeenCalledWith(element.find('.terminal')[0], cols, lines)
|
||||
|
||||
it 'creates HudView instance passing proper DOM element', ->
|
||||
spyOn(AsciiIo, 'HudView')
|
||||
player = new AsciiIo.PlayerView(element, cols, lines, data, timing)
|
||||
expect(AsciiIo.HudView).toHaveBeenCalledWith(element.find('.hud')[0])
|
||||
|
||||
it 'creates Movie instance', ->
|
||||
spyOn(AsciiIo, 'Movie')
|
||||
player = new AsciiIo.PlayerView(element, cols, lines, data, timing)
|
||||
expect(AsciiIo.Movie).toHaveBeenCalledWith(data, timing)
|
||||
|
||||
describe 'events', ->
|
||||
it 'toggles movie playback when terminal-click is fired on terminal', ->
|
||||
|
||||
it 'toggles movie playback when hud-play-click is fired on hud', ->
|
||||
|
||||
it 'seeks movie playback when hud-seek-click is fired on hud', ->
|
||||
|
||||
it 'toggles fullscreen view when hud-fullscreen-click is fired on hud', ->
|
||||
|
||||
it 'stops cursor blinking when movie-finished is fired on movie', ->
|
||||
|
||||
# it ' when movie-frame is fired on movie', ->
|
@ -0,0 +1,10 @@
|
||||
describe AsciiIo.TerminalView, ->
|
||||
|
||||
describe 'constructor', ->
|
||||
it 'creates child elements', ->
|
||||
|
||||
|
||||
describe 'click event', ->
|
||||
it 'triggers terminal-click when click is fired', ->
|
||||
|
||||
it 'shows visual clue when movie-play-toggle is fired', ->
|
Loading…
Reference in New Issue