pie 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/MIT-LICENSE.txt +20 -0
  2. data/README.md +43 -0
  3. data/lib/pie.rb +171 -0
  4. data/lib/player.rb +13 -0
  5. metadata +66 -0
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Sarah Allen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Pie
2
+
3
+ A game development DSL, inspired by Yasuko Ohba's Ruby Kaigi talk and a late night coversaton with @knowtheory, @wycats, @sarahmei and @ultrasaurus.
4
+
5
+ This is very experimental and marginally useful. Spec works, but coverage is meager.
6
+
7
+ Pie requires Ruby 1.9, because it is so cool.
8
+
9
+ ## Examples
10
+
11
+ ### Book
12
+
13
+ There is a sample in book.rb. To use it:
14
+
15
+ ruby book.rb
16
+
17
+ then go to:
18
+ http://localhost:4567/ship
19
+ http://localhost:4567/building
20
+ http://localhost:4567/tower
21
+
22
+ Someday there will be UI to change pages.
23
+
24
+ ### Game
25
+
26
+ ruby game.rb
27
+
28
+ then go to:
29
+ http://localhost:4567/park
30
+
31
+ Follow links to wander around the game world. Yes, that is all there is right now.
32
+
33
+
34
+ ## Pie Contributors
35
+
36
+ Core team
37
+ * Sarah Allen
38
+ * Sarah Mei
39
+
40
+ Contributors
41
+ * Dan Steinicke
42
+ * Akira Matsuda
43
+ * Chad Fowler
data/lib/pie.rb ADDED
@@ -0,0 +1,171 @@
1
+ require 'sinatra/base'
2
+ require 'player'
3
+
4
+ #puts "----------------- Ruby version = #{RUBY_VERSION}"
5
+ #raise ScriptError, "Pie requires Ruby 1.9 or higher" if RUBY_VERSION < "1.9.0"
6
+ NO_WAY_BACK = ""
7
+ class Pie
8
+
9
+
10
+ attr_accessor :places
11
+ attr_accessor :images
12
+ attr_accessor :default_template
13
+
14
+ def initialize
15
+ @default_template = :image_page
16
+ @places = Places.new
17
+ @map = Map.new(@places)
18
+ end
19
+
20
+ class WebApp < Sinatra::Base
21
+ set :root, File.join(File.expand_path(File.dirname(__FILE__)), "..")
22
+
23
+ get '/' do
24
+ "hello"
25
+ end
26
+
27
+ get '/:place_name' do
28
+ name = params[:place_name].to_sym
29
+ $current = name unless name.nil?
30
+ puts "current place name is #{$current}"
31
+ puts "current place is #{$pie.places[$current]}"
32
+ puts "--- skip out"; return if $pie.places[$current].nil?
33
+ puts "current links are #{$pie.places[$current].links.inspect}"
34
+ puts "displaying template: #{$pie.default_template.inspect}"
35
+ erb $pie.default_template
36
+ end
37
+ end
38
+
39
+ at_exit { WebApp.run! if !$0.include?("spec")}
40
+
41
+ class Map
42
+
43
+ def initialize places
44
+ @places = places
45
+ end
46
+
47
+ def path endpoints
48
+ puts "---> path #{endpoints.inspect}"
49
+ puts @places.inspect
50
+ #if h.size != 2
51
+ # return puts "path must have two and only two endpoints."
52
+ #end
53
+ start_place_key, end_place_key = endpoints.keys
54
+ label_for_end, label_for_start = endpoints.values
55
+
56
+ start_place = @places[start_place_key]
57
+ end_place = @places[end_place_key]
58
+ raise ArgumentError, "there is no place named '#{start_place_key}'" if start_place.nil?
59
+ raise ArgumentError, "there is no place named '#{end_place_key}'" if end_place.nil?
60
+
61
+ start_place[:links][end_place_key] = label_for_end unless label_for_end.empty?
62
+ end_place[:links][start_place_key] = label_for_start unless label_for_start.empty?
63
+ end
64
+ end
65
+
66
+ class Place < Hash
67
+ def initialize
68
+ self[:links] = {}
69
+ end
70
+ def links
71
+ result = self[:links]
72
+ end
73
+
74
+ end
75
+
76
+ class Places < Hash
77
+ def method_missing name, options = {}
78
+ unless options.is_a? Hash
79
+ puts "options for creating a place must have key and value"
80
+ return
81
+ end
82
+ puts "making a #{name} with #{options.inspect}"
83
+ place = Place.new
84
+ place.merge! options
85
+ self[name.to_sym] = place
86
+ end
87
+
88
+ def [] string_or_symbol
89
+ super string_or_symbol.to_sym
90
+ end
91
+
92
+ def after(place_name)
93
+ index = keys.index(place_name.to_sym)
94
+ next_place_name = keys[index + 1]
95
+ self[next_place_name] unless next_place_name.nil?
96
+ end
97
+
98
+ def before(place_name)
99
+ index = keys.index(place_name.to_sym)
100
+ index = index - 1
101
+ if index < 0
102
+ nil
103
+ else
104
+ prev_place_name = keys[index]
105
+ self[prev_place_name]
106
+ end
107
+ end
108
+ end
109
+
110
+ def template(template_name)
111
+ puts "--> set default template #{template_name.to_sym}"
112
+ @default_template = template_name.to_sym
113
+ end
114
+
115
+ def create_places(&block)
116
+ @places.instance_eval(&block)
117
+ end
118
+
119
+ def map(&block)
120
+ puts "-------- creating map --------"
121
+ @map.instance_eval(&block)
122
+ end
123
+
124
+ def image(image_hash)
125
+ @images ||= {}
126
+ puts "--- set image"
127
+ puts image_hash.inspect
128
+ @images.merge!(image_hash)
129
+ end
130
+
131
+ def current
132
+ @current ||= @places.keys.first
133
+ end
134
+
135
+ def move_to(new_place_key)
136
+ @current = new_place_key
137
+ end
138
+
139
+ def current_image
140
+ puts "------- current_image"
141
+ puts $current.inspect
142
+ puts @images.inspect
143
+ @images[$current.to_sym]
144
+ end
145
+
146
+ def current_description
147
+ puts "------- current_description"
148
+ puts $current.inspect
149
+ place = @places[$current.to_sym]
150
+ puts @place.inspect
151
+ place[:description] unless place.nil?
152
+ end
153
+ end
154
+
155
+ def make_pie(&block)
156
+ foo = 1
157
+ puts "-------------------------- making pie ---------------------------- "
158
+ $pie = Pie.new
159
+ $pie.instance_eval(&block)
160
+ puts "-------------------------- pie complete ---------------------------- "
161
+ end
162
+
163
+ def more_pie(&block)
164
+ puts "-------------------------- more pie ---------------------------- "
165
+ if $pie.nil?
166
+ puts "How can you make more pie when you haven't made any pie yet?"
167
+ return
168
+ end
169
+ $pie.instance_eval(&block)
170
+ puts "-------------------------- pie complete ---------------------------- "
171
+ end
data/lib/player.rb ADDED
@@ -0,0 +1,13 @@
1
+ class Pie
2
+ class Player
3
+ def description
4
+ "You are an egg."
5
+ end
6
+ end
7
+
8
+ def player
9
+ @player ||= Player.new
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pie
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors: []
11
+
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-09-11 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description:
21
+ email:
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/pie.rb
30
+ - lib/player.rb
31
+ - README.md
32
+ - MIT-LICENSE.txt
33
+ has_rdoc: true
34
+ homepage:
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.7
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Pie, a language for developing games and books
65
+ test_files: []
66
+