Simplified AsciiIo.Player
parent
3fd50d500e
commit
c9eca61c05
@ -1,58 +1,59 @@
|
|||||||
class AsciiIo.Player
|
class AsciiIo.Player
|
||||||
constructor: (cols, lines, data, time) ->
|
MIN_DELAY: 0.01
|
||||||
@minDelay = 0.01
|
SPEED: 1.0
|
||||||
@speed = 1.0
|
|
||||||
|
constructor: (cols, lines, data, timing) ->
|
||||||
@terminal = new AsciiIo.Terminal(cols, lines)
|
@terminal = new AsciiIo.Terminal(cols, lines)
|
||||||
@interpreter = new AsciiIo.AnsiInterpreter(@terminal)
|
@interpreter = new AsciiIo.AnsiInterpreter(@terminal)
|
||||||
@data = data
|
@data = data
|
||||||
@time = time
|
@timing = timing
|
||||||
@dataIndex = 0
|
@dataIndex = 0
|
||||||
@frame = 0
|
@frameNo = 0
|
||||||
@currentData = ""
|
@currentData = ""
|
||||||
console.log "started"
|
console.log "started"
|
||||||
@startTime = (new Date()).getTime()
|
@startTime = (new Date()).getTime()
|
||||||
@nextFrame()
|
@nextFrame()
|
||||||
|
|
||||||
nextFrame: () ->
|
nextFrame: () ->
|
||||||
timing = @time[@frame]
|
frame = @timing[@frameNo]
|
||||||
|
|
||||||
unless timing
|
unless frame
|
||||||
|
@terminal.stopCursorBlink()
|
||||||
console.log "finished in #{((new Date()).getTime() - @startTime) / 1000} seconds"
|
console.log "finished in #{((new Date()).getTime() - @startTime) / 1000} seconds"
|
||||||
return
|
return
|
||||||
|
|
||||||
@terminal.restartCursorBlink()
|
@frameNo += 1
|
||||||
|
|
||||||
run = () =>
|
[delay, count] = frame
|
||||||
rest = @interpreter.feed(@currentData)
|
|
||||||
@terminal.render()
|
|
||||||
n = timing[1]
|
|
||||||
|
|
||||||
if rest.length > 0
|
if delay > @MIN_DELAY
|
||||||
console.log 'rest: ' + Utf8.decode(rest)
|
realDelay = delay * 1000 * (1.0 / @SPEED)
|
||||||
|
|
||||||
@currentData = rest + @data.slice(@dataIndex, @dataIndex + n)
|
setTimeout(
|
||||||
@dataIndex += n
|
=>
|
||||||
@frame += 1
|
@terminal.restartCursorBlink()
|
||||||
|
@processFrame(count)
|
||||||
|
@nextFrame()
|
||||||
|
realDelay
|
||||||
|
)
|
||||||
|
else
|
||||||
|
@processFrame(count)
|
||||||
|
@nextFrame()
|
||||||
|
|
||||||
if rest.length > 100
|
processFrame: (count) ->
|
||||||
head = rest.slice(0, 100)
|
@currentData += @data.slice(@dataIndex, @dataIndex + count)
|
||||||
hex = ("0x#{c.charCodeAt(0).toString(16)}" for c in head)
|
@dataIndex += count
|
||||||
console.log "failed matching: '" + Utf8.decode(head) + "' (" + hex.join() + ") [pos: " + (@dataIndex - n) + "]"
|
|
||||||
return
|
|
||||||
|
|
||||||
unless window.stopped
|
@currentData = @interpreter.feed(@currentData)
|
||||||
@nextFrame()
|
|
||||||
|
|
||||||
if timing[0] > @minDelay
|
if @currentData.length > 0
|
||||||
setTimeout(run, timing[0] * 1000 * (1.0 / @speed))
|
@logStatus()
|
||||||
else
|
|
||||||
run()
|
|
||||||
|
|
||||||
|
logStatus: ->
|
||||||
|
console.log 'rest: ' + Utf8.decode(@currentData)
|
||||||
|
|
||||||
# $(function() {
|
if @currentData.length > 100
|
||||||
# $(window).bind('keyup', function(event) {
|
head = @currentData.slice(0, 100)
|
||||||
# if (event.keyCode == 27) {
|
hex = ("0x#{c.charCodeAt(0).toString(16)}" for c in head)
|
||||||
# window.stopped = true
|
console.log "failed matching: '" + Utf8.decode(head) + "' (" + hex.join() + ") [pos: " + (@dataIndex - count) + "]"
|
||||||
# }
|
return
|
||||||
# })
|
|
||||||
# })
|
|
||||||
|
Loading…
Reference in New Issue