jruby_art 0.2.6.pre → 0.3.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/k9 +2 -2
- data/lib/jruby_art.rb +18 -23
- data/lib/jruby_art/app.rb +118 -130
- data/lib/jruby_art/config.rb +7 -9
- data/lib/jruby_art/creators/creator.rb +189 -0
- data/lib/jruby_art/helper_methods.rb +41 -31
- data/lib/jruby_art/helpers/camel_string.rb +2 -1
- data/lib/jruby_art/helpers/numeric.rb +1 -2
- data/lib/jruby_art/helpers/range.rb +3 -7
- data/lib/jruby_art/helpers/string_extra.rb +1 -1
- data/lib/jruby_art/library_loader.rb +127 -96
- data/lib/jruby_art/runner.rb +208 -63
- data/lib/jruby_art/runners/base.rb +51 -0
- data/lib/jruby_art/runners/run.rb +6 -0
- data/lib/jruby_art/runners/watch.rb +59 -0
- data/lib/jruby_art/version.rb +1 -2
- data/lib/rpextras.jar +0 -0
- data/library/library_proxy/README.md +97 -0
- data/library/library_proxy/library_proxy.rb +8 -1
- data/library/video_event/video_event.rb +4 -0
- data/vendors/Rakefile +33 -78
- metadata +54 -60
- data/CHANGELOG.md +0 -60
- data/LICENSE.md +0 -39
- data/README.md +0 -91
- data/Rakefile +0 -85
- data/lib/core.jar +0 -0
- data/lib/gluegen-rt-natives-linux-amd64.jar +0 -0
- data/lib/gluegen-rt-natives-linux-armv6hf.jar +0 -0
- data/lib/gluegen-rt-natives-linux-i586.jar +0 -0
- data/lib/gluegen-rt-natives-macosx-universal.jar +0 -0
- data/lib/gluegen-rt-natives-windows-amd64.jar +0 -0
- data/lib/gluegen-rt-natives-windows-i586.jar +0 -0
- data/lib/gluegen-rt.jar +0 -0
- data/lib/jogl-all-natives-linux-amd64.jar +0 -0
- data/lib/jogl-all-natives-linux-armv6hf.jar +0 -0
- data/lib/jogl-all-natives-linux-i586.jar +0 -0
- data/lib/jogl-all-natives-macosx-universal.jar +0 -0
- data/lib/jogl-all-natives-windows-amd64.jar +0 -0
- data/lib/jogl-all-natives-windows-i586.jar +0 -0
- data/lib/jogl-all.jar +0 -0
- data/lib/jruby_art/creator.rb +0 -100
- data/lib/jruby_art/parse.rb +0 -59
- data/lib/jruby_art/writer.rb +0 -40
- data/library/file_chooser/file_chooser.rb +0 -82
- data/library/grammar/grammar.rb +0 -31
- data/library/video/lib/export.txt +0 -1
- data/library/video/lib/macosx64.txt +0 -1
- data/library/video/lib/windows.txt +0 -3
- data/library/video/video.rb +0 -12
- data/spec/app_spec.rb +0 -208
- data/spec/deglut_spec.rb +0 -25
- data/spec/library_loader_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -96
- data/spec/vecmath_spec.rb +0 -483
- data/vendors/config.tar.gz +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2f18112ba5aae2c2dfdd271945d91c157242dce
|
4
|
+
data.tar.gz: c917b6420da85b1e4c45b71de2a84b57dbc2712b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 094e0e81bc65c61753fd6fb6b2c5bb2260496effb480670e6d8c75d818f36e0410abdba62899e7dcbc85f7d460cedd82e2696ac708c15a47450dc161aaddc430
|
7
|
+
data.tar.gz: 5c673af5d1e65b84327be0fc5983cfea3d4ce4a0963e0082230b8755bb12aa4caf1fae516f4e6f01dc2bdf84f4c7f5df71d5d6789890334079cfd15c004379ca
|
data/bin/k9
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
file = __FILE__
|
4
4
|
if test(?l, file)
|
5
|
-
require
|
5
|
+
require "pathname"
|
6
6
|
file = Pathname.new(file).realpath
|
7
7
|
end
|
8
8
|
|
9
|
-
require File.expand_path(File.dirname(file) +
|
9
|
+
require File.expand_path(File.dirname(file) + "/../lib/jruby_art")
|
10
10
|
Processing::Runner.execute
|
data/lib/jruby_art.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
unless defined? K9_ROOT
|
1
|
+
# Ruby-Processing is for Code Art.
|
2
|
+
# Send suggestions, ideas, and hate-mail to mamba2928 [at] gmail.com
|
3
|
+
# Also, send samples and libraries.
|
4
|
+
unless defined? RP5_ROOT
|
6
5
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
|
7
|
-
|
6
|
+
RP5_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
if RUBY_PLATFORM == 'java'
|
12
|
-
working_directory = File.join(File.dirname(__FILE__))
|
13
|
-
$LOAD_PATH << working_directory unless $LOAD_PATH.include?(working_directory)
|
14
|
-
Dir[File.join(working_directory, '*.jar')].each do |jar|
|
15
|
-
# require_relative jar unless jar =~ /native/ (breaks netbeans)
|
16
|
-
require jar unless jar =~ /native/
|
17
|
-
end
|
18
|
-
Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
|
19
|
-
Java::ProcessingVecmathVec2::Vec2Library.new.load(JRuby.runtime, false)
|
20
|
-
Java::ProcessingVecmathVec3::Vec3Library.new.load(JRuby.runtime, false)
|
21
|
-
AppRender = Java::ProcessingVecmath::AppRender
|
22
|
-
ShapeRender = Java::ProcessingVecmath::ShapeRender
|
23
|
-
require 'jruby_art/app'
|
24
|
-
require 'jruby_art/helper_methods'
|
25
|
-
end
|
9
|
+
SKETCH_ROOT ||= Dir.pwd
|
26
10
|
|
27
11
|
require 'jruby_art/version'
|
28
12
|
require 'jruby_art/helpers/numeric'
|
29
13
|
require 'jruby_art/helpers/range'
|
30
|
-
|
14
|
+
|
15
|
+
# The top-level namespace, a home for all Ruby-Processing classes.
|
16
|
+
module Processing
|
17
|
+
|
18
|
+
# Autoload a number of path/constants that we may end up using.
|
19
|
+
# mri ruby does not understand ** require 'java' ** and we may otherwise call
|
20
|
+
# it from mri ruby without lazy path loading of autoload
|
21
|
+
# NB: autoload was slated for possible removal by ruby-2.2 never happened
|
22
|
+
autoload :App, 'jruby_art/app'
|
23
|
+
autoload :Runner, 'jruby_art/runner'
|
24
|
+
autoload :Watcher, 'jruby_art/runners/watch'
|
25
|
+
end
|
data/lib/jruby_art/app.rb
CHANGED
@@ -1,69 +1,25 @@
|
|
1
|
-
|
2
|
-
require_relative '
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'java'
|
2
|
+
require_relative '../rpextras'
|
3
|
+
require_relative '../jruby_art/helper_methods'
|
4
|
+
require_relative '../jruby_art/helpers/string_extra'
|
5
|
+
require_relative '../jruby_art/library_loader'
|
6
|
+
require_relative '../jruby_art/config'
|
7
|
+
|
8
|
+
# A wrapper module for the processing App
|
6
9
|
module Processing
|
7
|
-
|
8
|
-
include_package 'processing.
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# def draw
|
17
|
-
# background rand(255)
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
module Common
|
23
|
-
# This method provides the possibility of adding and using
|
24
|
-
# new runtime options in sketches no need to re-define initialize
|
25
|
-
#
|
26
|
-
def post_initialize(_opts = {})
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
# This method configures the sketch title and and presentation mode.
|
31
|
-
#
|
32
|
-
def configure_sketch
|
33
|
-
presentation_mode
|
34
|
-
sketch_title
|
35
|
-
end
|
36
|
-
|
37
|
-
# This method sets the sketch presentation mode.
|
38
|
-
#
|
39
|
-
def presentation_mode
|
40
|
-
return unless opts[:fullscreen]
|
41
|
-
args << '--full-screen'
|
42
|
-
args << "--bgcolor=#{opts[:bgcolor]}" if opts[:bgcolor]
|
43
|
-
end
|
10
|
+
# Include some core processing classes that we'd like to use:
|
11
|
+
include_package 'processing.core'
|
12
|
+
# Load vecmath and fastmath modules
|
13
|
+
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
|
14
|
+
Java::ProcessingVecmathVec2::Vec2Library.new.load(JRuby.runtime, false)
|
15
|
+
Java::ProcessingVecmathVec3::Vec3Library.new.load(JRuby.runtime, false)
|
16
|
+
Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
|
17
|
+
AppRender ||= Java::ProcessingVecmath::AppRender
|
18
|
+
ShapeRender ||= Java::ProcessingVecmath::ShapeRender
|
44
19
|
|
45
|
-
# This method is the main draw loop of the sketch. This is usually
|
46
|
-
# overridden by the user.
|
47
|
-
#
|
48
|
-
def draw
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
|
52
|
-
# This method runs the processing sketch.
|
53
|
-
#
|
54
|
-
def run_sketch
|
55
|
-
PApplet.run_sketch(args.to_java(:string), self)
|
56
|
-
end
|
57
|
-
|
58
|
-
# This method sets the sketch title.
|
59
|
-
#
|
60
|
-
def sketch_title
|
61
|
-
args << opts.fetch(:title, 'Sketch')
|
62
|
-
end
|
63
|
-
end
|
64
20
|
# Watch the definition of these methods, to make sure
|
65
21
|
# that Processing is able to call them during events.
|
66
|
-
METHODS_TO_ALIAS
|
22
|
+
METHODS_TO_ALIAS ||= {
|
67
23
|
mouse_pressed: :mousePressed,
|
68
24
|
mouse_dragged: :mouseDragged,
|
69
25
|
mouse_clicked: :mouseClicked,
|
@@ -73,11 +29,28 @@ module Processing
|
|
73
29
|
key_released: :keyReleased,
|
74
30
|
key_typed: :keyTyped
|
75
31
|
}
|
76
|
-
|
77
|
-
# This class is for default (Java2D) sketches only
|
32
|
+
# All sketches extend this class
|
78
33
|
class App < PApplet
|
79
|
-
include Math
|
80
|
-
|
34
|
+
include Math
|
35
|
+
include HelperMethods
|
36
|
+
# Alias some methods for familiarity for Shoes coders.
|
37
|
+
# surface replaces :frame, but needs field_reader for access
|
38
|
+
alias_method :oval, :ellipse
|
39
|
+
alias_method :stroke_width, :stroke_weight
|
40
|
+
alias_method :rgb, :color
|
41
|
+
alias_method :gray, :color
|
42
|
+
field_reader :surface
|
43
|
+
|
44
|
+
def sketch_class
|
45
|
+
self.class.sketch_class
|
46
|
+
end
|
47
|
+
|
48
|
+
# Keep track of what inherits from the Processing::App, because we're
|
49
|
+
# going to want to instantiate one.
|
50
|
+
def self.inherited(subclass)
|
51
|
+
super(subclass)
|
52
|
+
@sketch_class = subclass
|
53
|
+
end
|
81
54
|
|
82
55
|
class << self
|
83
56
|
# Handy getters and setters on the class go here:
|
@@ -85,10 +58,22 @@ module Processing
|
|
85
58
|
|
86
59
|
def load_libraries(*args)
|
87
60
|
library_loader ||= LibraryLoader.new
|
88
|
-
library_loader.
|
61
|
+
library_loader.load_library(*args)
|
89
62
|
end
|
90
63
|
alias_method :load_library, :load_libraries
|
91
64
|
|
65
|
+
def library_loaded?(library_name)
|
66
|
+
library_loader.library_loaded?(library_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_ruby_library(*args)
|
70
|
+
library_loader.load_ruby_library(*args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_java_library(*args)
|
74
|
+
library_loader.load_java_library(*args)
|
75
|
+
end
|
76
|
+
|
92
77
|
# When certain special methods get added to the sketch, we need to let
|
93
78
|
# Processing call them by their expected Java names.
|
94
79
|
def method_added(method_name) #:nodoc:
|
@@ -97,84 +82,86 @@ module Processing
|
|
97
82
|
end
|
98
83
|
end
|
99
84
|
|
100
|
-
def
|
101
|
-
self.class.
|
85
|
+
def library_loaded?(library_name)
|
86
|
+
self.class.library_loaded?(library_name)
|
102
87
|
end
|
103
88
|
|
104
|
-
#
|
105
|
-
# and
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
|
89
|
+
# Since processing-3.0 you should prefer setting the sketch width and
|
90
|
+
# height and renderer using the size method in the settings loop of the
|
91
|
+
# sketch (as with vanilla processing) but is hidden see created java.
|
92
|
+
# Options are no longer relevant, define post_initialize method to use
|
93
|
+
# custom options (see Sandi Metz POODR)
|
94
|
+
|
95
|
+
def initialize(options = {})
|
110
96
|
super()
|
111
|
-
|
112
|
-
post_initialize(opts)
|
113
|
-
@args = args
|
114
|
-
@opts = opts
|
97
|
+
post_initialize(options) # for anyone wishing to pass options
|
115
98
|
$app = self
|
116
|
-
|
99
|
+
proxy_java_fields
|
100
|
+
mix_proxy_into_inner_classes
|
101
|
+
java.lang.Thread.default_uncaught_exception_handler = proc do |_thread_, exception|
|
102
|
+
puts(exception.class.to_s)
|
103
|
+
puts(exception.message)
|
104
|
+
puts(exception.backtrace.map { |trace| "\t#{trace}" })
|
105
|
+
close
|
106
|
+
end
|
107
|
+
# NB: this is the processing runSketch() method as used by processing.py
|
117
108
|
run_sketch
|
118
109
|
end
|
119
110
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
111
|
+
def size(*args)
|
112
|
+
w, h, mode = *args
|
113
|
+
@width ||= w
|
114
|
+
@height ||= h
|
115
|
+
@render_mode ||= mode
|
116
|
+
import_opengl if /opengl/ =~ mode
|
117
|
+
super(*args)
|
125
118
|
end
|
126
|
-
end
|
127
119
|
|
128
|
-
|
129
|
-
|
130
|
-
include Math, Processing, Common
|
131
|
-
include_package 'processing.opengl' # imports the processing.opengl package.
|
132
|
-
include HelperMethods
|
133
|
-
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
|
134
|
-
attr_reader :title, :args, :opts
|
135
|
-
|
136
|
-
# App should be instantiated with an optional list of opts
|
137
|
-
# and array of args.
|
138
|
-
#
|
139
|
-
# App.new(title: 'My Simple App', fullscreen: true)
|
140
|
-
#
|
141
|
-
def initialize(opts = {}, args = [])
|
142
|
-
super()
|
143
|
-
proxy_java_fields
|
144
|
-
post_initialize(opts)
|
145
|
-
@args = args
|
146
|
-
@opts = opts
|
147
|
-
$app = self
|
148
|
-
configure_sketch
|
149
|
-
run_sketch
|
120
|
+
def sketch_title(title)
|
121
|
+
surface.setTitle(title)
|
150
122
|
end
|
151
123
|
|
152
|
-
|
153
|
-
|
154
|
-
#
|
155
|
-
def setup
|
156
|
-
size(width, height, mode = P3D)
|
157
|
-
fail unless /opengl/ =~ mode
|
124
|
+
def post_initialize(_args)
|
125
|
+
nil
|
158
126
|
end
|
159
127
|
|
160
|
-
|
161
|
-
|
162
|
-
|
128
|
+
# Close and shutter a running sketch. But don't exit.
|
129
|
+
# @HACK seems to work with watch until we find a better
|
130
|
+
# way of disposing of sketch window...
|
131
|
+
def close
|
132
|
+
control_panel.remove if respond_to?(:control_panel)
|
133
|
+
surface.stopThread
|
134
|
+
surface.setVisible(false) if surface.isStopped()
|
135
|
+
dispose
|
136
|
+
end
|
163
137
|
|
164
|
-
|
165
|
-
|
166
|
-
|
138
|
+
def exit
|
139
|
+
control_panel.remove if respond_to?(:control_panel)
|
140
|
+
super()
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# Mix the Processing::Proxy into any inner classes defined for the
|
146
|
+
# sketch, attempting to mimic the behavior of Java's inner classes.
|
147
|
+
def mix_proxy_into_inner_classes
|
148
|
+
klass = Processing::App.sketch_class
|
149
|
+
klass.constants.each do |name|
|
150
|
+
const = klass.const_get name
|
151
|
+
next if const.class != Class || const.to_s.match(/^Java::/)
|
152
|
+
const.class_eval 'include Processing::Proxy'
|
167
153
|
end
|
168
|
-
|
154
|
+
end
|
169
155
|
|
170
|
-
|
171
|
-
#
|
172
|
-
|
173
|
-
|
174
|
-
|
156
|
+
def import_opengl
|
157
|
+
# Include processing opengl classes that we'd like to use:
|
158
|
+
%w(FontTexture FrameBuffer LinePath LineStroker PGL
|
159
|
+
PGraphics2D PGraphics3D PGraphicsOpenGL PShader
|
160
|
+
PShapeOpenGL Texture).each do |klass|
|
161
|
+
java_import format('processing.opengl.%s', klass)
|
175
162
|
end
|
176
163
|
end
|
177
|
-
end
|
164
|
+
end # Processing::App
|
178
165
|
|
179
166
|
# Importing PConstants to access to processing constants,
|
180
167
|
# to keep namespace clean use PConstants::TRIANGLE (for example)
|
@@ -183,11 +170,12 @@ module Processing
|
|
183
170
|
# @HACK you should consider using 'forwardable' to avoid this
|
184
171
|
# egregious hack...
|
185
172
|
module Proxy
|
173
|
+
include Math
|
186
174
|
java_import 'processing.core.PConstants'
|
187
|
-
|
175
|
+
|
188
176
|
def method_missing(name, *args)
|
189
177
|
return $app.send(name, *args) if $app && $app.respond_to?(name)
|
190
178
|
super
|
191
179
|
end
|
192
|
-
end
|
193
|
-
end
|
180
|
+
end # Processing::Proxy
|
181
|
+
end # Processing
|
data/lib/jruby_art/config.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
#
|
1
|
+
require 'psych'
|
2
|
+
|
3
|
+
# The wrapper module
|
4
4
|
module Processing
|
5
5
|
unless defined? RP_CONFIG
|
6
|
+
config_path = '~/.jruby_art/config.yml'
|
6
7
|
begin
|
7
|
-
CONFIG_FILE_PATH = File.expand_path(
|
8
|
-
RP_CONFIG =
|
8
|
+
CONFIG_FILE_PATH = File.expand_path(config_path)
|
9
|
+
RP_CONFIG = (Psych.load_file(CONFIG_FILE_PATH))
|
9
10
|
rescue
|
10
|
-
warn('
|
11
|
+
warn(format('WARN: you need to set PROCESSING_ROOT in %s', config_path))
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
@@ -0,0 +1,189 @@
|
|
1
|
+
BASIC = <<-CODE
|
2
|
+
def setup
|
3
|
+
sketch_title '%s'
|
4
|
+
end
|
5
|
+
|
6
|
+
def draw
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def settings
|
11
|
+
size %s, %s, FX2D
|
12
|
+
# smooth # here
|
13
|
+
end
|
14
|
+
|
15
|
+
CODE
|
16
|
+
|
17
|
+
BASIC_MODE = <<-CODE
|
18
|
+
def setup
|
19
|
+
sketch_title '%s'
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def settings
|
27
|
+
size %s, %s, %s
|
28
|
+
# smooth # here
|
29
|
+
end
|
30
|
+
|
31
|
+
CODE
|
32
|
+
|
33
|
+
CLASS_BASIC = <<-CODE
|
34
|
+
class %s < Processing::App
|
35
|
+
def setup
|
36
|
+
sketch_title '%s'
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def settings
|
44
|
+
size %s, %s, FX2D
|
45
|
+
# smooth # here
|
46
|
+
end
|
47
|
+
end
|
48
|
+
CODE
|
49
|
+
|
50
|
+
CLASS_MODE = <<-CODE
|
51
|
+
class %s < Processing::App
|
52
|
+
def setup
|
53
|
+
sketch_title '%s'
|
54
|
+
end
|
55
|
+
|
56
|
+
def draw
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def settings
|
61
|
+
size %s, %s, %s
|
62
|
+
# smooth # here
|
63
|
+
end
|
64
|
+
end
|
65
|
+
CODE
|
66
|
+
|
67
|
+
INNER = <<-CODE
|
68
|
+
class %s
|
69
|
+
include Processing::Proxy
|
70
|
+
|
71
|
+
end
|
72
|
+
CODE
|
73
|
+
|
74
|
+
# processing wrapper module
|
75
|
+
module Processing
|
76
|
+
require_relative '../helpers/string_extra'
|
77
|
+
require_relative '../helpers/camel_string'
|
78
|
+
# Write file to disk
|
79
|
+
class SketchWriter
|
80
|
+
attr_reader :file
|
81
|
+
def initialize(path)
|
82
|
+
underscore = StringExtra.new(path).underscore
|
83
|
+
@file = "#{File.dirname(path)}/#{underscore}.rb"
|
84
|
+
end
|
85
|
+
|
86
|
+
def save(template)
|
87
|
+
File.open(file, 'w+') do |f|
|
88
|
+
f.write(template)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# An abstract class providing common methods for real creators
|
94
|
+
class Creator
|
95
|
+
ALL_DIGITS = /\A\d+\Z/
|
96
|
+
|
97
|
+
def already_exist(path)
|
98
|
+
underscore = StringExtra.new(path).underscore
|
99
|
+
new_file = "#{File.dirname(path)}/#{underscore}.rb"
|
100
|
+
return if !FileTest.exist?(path) && !FileTest.exist?(new_file)
|
101
|
+
puts 'That file already exists!'
|
102
|
+
exit
|
103
|
+
end
|
104
|
+
|
105
|
+
# Show the help/usage message for create.
|
106
|
+
def usage
|
107
|
+
puts <<-USAGE
|
108
|
+
|
109
|
+
Usage: k9 create <sketch_to_generate> <width> <height> <mode>
|
110
|
+
mode can be P2D / P3D.
|
111
|
+
Use --wrap for a sketch wrapped as a class
|
112
|
+
Use --inner to generated a ruby version of 'java' Inner class
|
113
|
+
Examples: k9 create app 800 600
|
114
|
+
k9 create app 800 600 p3d --wrap
|
115
|
+
k9 create inner_class --inner
|
116
|
+
|
117
|
+
USAGE
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# This class creates bare sketches, with an optional render mode
|
122
|
+
class BasicSketch < Creator
|
123
|
+
# Create a blank sketch, given a path.
|
124
|
+
def basic_template
|
125
|
+
format(BASIC, @title, @width, @height)
|
126
|
+
end
|
127
|
+
|
128
|
+
def basic_template_mode
|
129
|
+
format(BASIC_MODE, @title, @width, @height, @mode)
|
130
|
+
end
|
131
|
+
|
132
|
+
def create!(path, args)
|
133
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
134
|
+
# Check to make sure that the main file doesn't exist already
|
135
|
+
already_exist(path)
|
136
|
+
main_file = File.basename(path, '.rb') # allow uneeded extension input
|
137
|
+
writer = SketchWriter.new(main_file)
|
138
|
+
@title = StringExtra.new(main_file).titleize
|
139
|
+
@width = args[0]
|
140
|
+
@height = args[1]
|
141
|
+
@mode = args[2].upcase unless args[2].nil?
|
142
|
+
template = @mode.nil? ? basic_template : basic_template_mode
|
143
|
+
writer.save(template)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# This class creates class wrapped sketches, with an optional render mode
|
148
|
+
class ClassSketch < Creator
|
149
|
+
def class_template
|
150
|
+
format(CLASS_BASIC, @name, @title, @width, @height)
|
151
|
+
end
|
152
|
+
|
153
|
+
def class_template_mode
|
154
|
+
format(CLASS_MODE, @name, @title, @width, @height, @mode)
|
155
|
+
end
|
156
|
+
# Create a class wrapped sketch, given a path.
|
157
|
+
def create!(path, args)
|
158
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
159
|
+
main_file = File.basename(path, '.rb') # allow uneeded extension input
|
160
|
+
# Check to make sure that the main file doesn't exist already
|
161
|
+
already_exist(path)
|
162
|
+
@name = CamelString.new(main_file).camelize
|
163
|
+
writer = SketchWriter.new(main_file)
|
164
|
+
@title = StringExtra.new(main_file).titleize
|
165
|
+
@width, @height = args[0], args[1]
|
166
|
+
@mode = args[2].upcase unless args[2].nil?
|
167
|
+
template = @mode.nil? ? class_template : class_template_mode
|
168
|
+
writer.save(template)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# This class creates a pseudo 'java inner class' of the sketch
|
173
|
+
class Inner < Creator
|
174
|
+
def inner_class_template
|
175
|
+
format(INNER, @name)
|
176
|
+
end
|
177
|
+
# Create a pseudo inner class, given a path.
|
178
|
+
def create!(path, _args_)
|
179
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
180
|
+
main_file = File.basename(path, '.rb') # allow uneeded extension input
|
181
|
+
# Check to make sure that the main file doesn't exist already
|
182
|
+
already_exist(path)
|
183
|
+
@name = main_file.camelize
|
184
|
+
writer = SketchWriter.new(main_file)
|
185
|
+
template = inner_class_template
|
186
|
+
writer.save(template)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|