Commits

soycamo  committed 0731181

initial commit, hacked up in Ruby. Non functional.

  • Participants

Comments (0)

Files changed (4)

+syntax: glob
+*.swp
+*.swo

File example_gamefile.txt

+[A18]
+@image = Conclusion.bmp
+@music = shota(Rally the troops).mid
+@description = Conclusion. Here you just basically
+touch things up and prepare the story for its final form to be published (read by others),
+so this is what you need to remember...
+@option3 = --->
+@link3 = A19
+@option4 = <---
+@link4 = A17
+
+[A19]
+@anim = Purpose.bmp, research.bmp, hypothesis.bmp, experiment.bmp, results.bmp, conclusion.bmp
+@animloop = forever
+@animspeed = slow
+@music = shota(Rally the troops).mid
+@description = Purpose\nResearch\nHypothesis\nExperiment\nResults\nConclusion
+@option3 = Choose Another Instructor?
+@link3 = Story
+@option4 = <---
+@link4 = A18
+
+[A20]
+@image = intro.bmp
+@music = shota(Rally the troops).mid
+@description =
+The most important thing is just not to lose faith in yourself.
+As long as you believe you'll always be able to stand...
+There's too many people in this world to all like you and
+your work. 
+@option4 = --->
+@link4 = A21
+
+[A21]
+@image = intro.bmp
+@music = shota(Rally the troops).mid
+@description = Speak proud and your story will be heard.
+\n\n\nLaters,
+\nArima
+@option3 = Choose another Instructor
+@link3 = Advice
+require 'pp'
+
+class Kamishibai
+  require 'iconv' unless String.method_defined?(:encode)
+  attr_accessor :slideset
+
+  # The Slip N Slide holds our wonky data.
+  SlipnSlide = Struct.new(:title, :raw_attributes) 
+
+  def initialize(gamefile_path)
+    #gamefile_path = File.expand_path "~/Projects/tapestry/test\ samples/KamishibaiMasterClass/gamefile.txt" #use ARGV here
+    gamefile = File.open(gamefile_path, 'r')
+    @slideset = []
+    current_slide = nil
+    gamefile.each do |line|
+      # TODO change to auto detect encoding
+      if String.method_defined?(:encode) 
+        line.encode!('UTF-8', 'US-ASCII',{:invalid => :replace, :universal_newline => true})   
+      else
+        ic = Iconv.new('UTF-8', 'UTF-8//IGNORE')
+        line = ic.iconv(line)
+      end
+      line.strip!
+      #puts line
+      if line =~ %r{^\[(.+)\]}
+        @slideset << current_slide unless current_slide.nil? 
+        current_slide = SlipnSlide.new(line[1..(line.length - 2)], [])
+      else
+        current_slide.raw_attributes << line if current_slide
+      end
+
+    end
+    @slideset << current_slide
+
+  end
+
+#  def parse_attributes(attr_array)
+#    attr_array.inject([]) do |memo, str| 
+#      memo << str
+#      end
+#    end
+end
+
+#example = slideset.select { |slide| slide.title == "A4" }.first                            
+#puts parse_attributes(example.raw_attributes) 
+ 
+

File tapestry_spec.rb

+require 'rspec'
+require './tapestry'
+
+describe Kamishibai do
+  it "should merge attributes that included newlines" do
+    ksb = Kamishibai.new("./example_gamefile.txt")
+    ksb.slideset.length.should == 4
+  end
+end