updated empty list item regex (fixes #1); added internal scene id to player (fixes #2)

This commit is contained in:
Rudis Muiznieks 2014-07-02 15:51:21 -05:00
parent e5b9e87735
commit 5797639f99
6 changed files with 45 additions and 12 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.swp *.swp
bin/ bin/
node_modules/ node_modules/
.DS_Store

View File

@ -40,14 +40,14 @@ module.exports = (grunt) ->
files: [ files: [
expand: true expand: true
flatten: true flatten: true
src: ['src/example/*.html', 'src/example/*.png', 'src/example/*.md'] src: ['src/example/*.html', 'src/example/*.png', 'src/example/*.md', 'bin/ficdown.min.js']
dest: 'bin/example/' dest: 'bin/example/'
] ]
watch: watch:
js: js:
files: ['src/**/*.coffee'] files: ['src/**/*.coffee']
tasks: ['build:js'] tasks: ['build:js', 'copy:example']
css: css:
files: ['src/**/*.styl'] files: ['src/**/*.styl']
tasks: ['stylus:compile'] tasks: ['stylus:compile']

View File

@ -14,9 +14,13 @@
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.min.js"></script>
<script src="../ficdown.min.js"></script> <script src="ficdown.min.js"></script>
<script> <script>
$.get('story.md', function(data){ var story = location.search.replace('?', '');
if(!story){
story = 'story.md';
}
$.get(story, function(data){
story = parseText(data); story = parseText(data);
player = new Player(story, 'main'); player = new Player(story, 'main');
player.play(); player.play();

28
src/example/testing.md Normal file
View File

@ -0,0 +1,28 @@
# [Testing](/scene)
Testing
## Scene
> This is first-seen text for the main scene.
This is a test.
- [|Set condition](?condition#condition)
- [Go to another scene](/another-scene)
## Another Scene
> This is the first seen text of the unconditional scene.
This is the regular text of the unconditional scene.
- [Go back](/scene)
## [Another Scene](?condition)
> This is the first seen text of the conditional scene.
This is the regular text of the conditional scene.
- [Go back](/scene)

View File

@ -7,6 +7,8 @@ class Player
@visitedScenes = {} @visitedScenes = {}
@currentScene = null @currentScene = null
@moveCounter = 0 @moveCounter = 0
i = 0
scene.id = "s#{++i}" for scene in scenes for key, scenes of @story.scenes
play: -> play: ->
@container.html @converter.makeHtml "##{story.name}\n\n#{story.description}\n\n[Click to start...](/#{story.firstScene})" @container.html @converter.makeHtml "##{story.name}\n\n#{story.description}\n\n[Click to start...](/#{story.firstScene})"
@ -50,9 +52,9 @@ class Player
$this.unbind 'click' $this.unbind 'click'
$this.click -> return false $this.click -> return false
processHtml: (scene, html) -> processHtml: (sceneid, html) ->
temp = $('<div/>').append $.parseHTML html temp = $('<div/>').append $.parseHTML html
if @visitedScenes[scene] if @visitedScenes[sceneid]
temp.find('blockquote').remove() temp.find('blockquote').remove()
else else
temp.find('blockquote').each (i) -> temp.find('blockquote').each (i) ->
@ -73,7 +75,6 @@ class Player
matchedScene = null matchedScene = null
actions = [] actions = []
if match?.toggles? if match?.toggles?
console.log "toggles: " + JSON.stringify match.toggles
toggles = match.toggles.split '+' toggles = match.toggles.split '+'
for toggle in toggles for toggle in toggles
if @story.actions[toggle]? if @story.actions[toggle]?
@ -95,14 +96,13 @@ class Player
newContent = "###{newScene.name}\n\n" newContent = "###{newScene.name}\n\n"
newContent += "#{action.description}\n\n" for action in actions newContent += "#{action.description}\n\n" for action in actions
newContent += newScene.description newContent += newScene.description
newHtml = @processHtml newScene.key, @converter.makeHtml newContent newHtml = @processHtml newScene.id, @converter.makeHtml newContent
@visitedScenes[newScene.key] = true @visitedScenes[newScene.id] = true
scrollId = "move-#{@moveCounter++}" scrollId = "move-#{@moveCounter++}"
@container.append $('<span/>').attr 'id', scrollId @container.append $('<span/>').attr 'id', scrollId
@container.append newHtml @container.append newHtml
@wireLinks() @wireLinks()
@checkGameOver() @checkGameOver()
console.log "scrolling to #{scrollId}"
@container.parent('.container').animate @container.parent('.container').animate
scrollTop: $("##{scrollId}").offset().top - @container.offset().top scrollTop: $("##{scrollId}").offset().top - @container.offset().top
, 1000 , 1000

View File

@ -10,7 +10,7 @@ regexLib =
escapeChar: /\\(?=[^\\])/g escapeChar: /\\(?=[^\\])/g
emptyListItem: /^\s*-\s*([\r\n]+|$)/gm emptyListItem: /^[ ]*-\s*([\r\n]+|$)/gm
matchAnchor = (text) -> matchAnchor = (text) ->
re = new RegExp regexLib.anchors re = new RegExp regexLib.anchors