cryptopunks 1.3.0 → 2.0.0

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.
@@ -116,6 +116,9 @@ module Cryptopunks
116
116
  alias_method :sheet, :spritesheet
117
117
 
118
118
 
119
+ def records() @recs; end
120
+ alias_method :meta, :records
121
+
119
122
 
120
123
 
121
124
 
@@ -0,0 +1,264 @@
1
+ module Cryptopunks
2
+
3
+
4
+
5
+ class Tool
6
+ def run( args )
7
+ Toolii.run( args )
8
+ end
9
+ end
10
+
11
+
12
+
13
+ class Opts
14
+ def merge_gli_options!( options = {} )
15
+ # puts " update options:"
16
+ # puts options.inspect
17
+
18
+ @file = options[:file] if options[:file]
19
+ @outdir = options[:dir] if options[:dir]
20
+
21
+ @zoom = options[:zoom] if options[:zoom]
22
+ @offset = options[:offset] if options[:offset]
23
+
24
+ @verbose = true if options[:verbose] == true
25
+ end
26
+
27
+
28
+ def verbose=(boolean) # add: alias for debug ??
29
+ @verbose = boolean
30
+ end
31
+
32
+ def verbose?
33
+ return false if @verbose.nil? # default verbose/debug flag is false
34
+ @verbose == true
35
+ end
36
+
37
+ def file() @file || './punks.png'; end
38
+ def file?() @file; end ## note: let's you check if file is set (or "untouched")
39
+
40
+ def zoom() @zoom || 1; end
41
+ def zoom?() @zoom; end
42
+
43
+ def offset() @offset || 0; end
44
+ def offset?() @offset; end
45
+
46
+ def outdir() @outdir || '.'; end
47
+ def outdir?() @outdir; end
48
+ end # class Opts
49
+
50
+
51
+
52
+ ## note: use gli "dsl" inside a class / namespace
53
+ class Toolii
54
+ extend GLI::App
55
+
56
+ opts = Opts.new
57
+
58
+
59
+ program_desc 'punk (or cryptopunk) command line tool'
60
+
61
+ version Cryptopunks::VERSION
62
+
63
+
64
+ desc "Zoom factor x2, x4, x8, etc."
65
+ arg_name 'ZOOM'
66
+ default_value opts.zoom
67
+ flag [:z, :zoom], type: Integer
68
+
69
+ desc "Start counting at offset"
70
+ arg_name 'NUM'
71
+ default_value opts.offset
72
+ flag [:offset], type: Integer
73
+
74
+ desc "Output directory"
75
+ arg_name 'DIR'
76
+ default_value opts.outdir
77
+ flag [:d, :dir,
78
+ :o, :out, :outdir], type: String
79
+
80
+ ### todo/check: move option to -t/--tile command only - why? why not?
81
+ desc "True Official Genuine CryptoPunks™ all-in-one composite image"
82
+ arg_name 'FILE'
83
+ default_value opts.file
84
+ flag [:f, :file], type: String
85
+
86
+
87
+
88
+ ### global option (required)
89
+ ## todo: add check that path is valid?? possible?
90
+ desc '(Debug) Show debug messages'
91
+ switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
92
+
93
+
94
+
95
+ desc "Get punk characters via image tiles from all-in-one punk series composite (#{opts.file}) - for IDs use 0 to 9999"
96
+ command [:t, :tile] do |c|
97
+ c.action do |g,o,args|
98
+
99
+ # puts "opts:"
100
+ # puts opts.inspect
101
+
102
+ puts "==> reading >#{opts.file}<..."
103
+ punks = ImageComposite.read( opts.file )
104
+
105
+
106
+ puts " setting zoom to #{opts.zoom}x" if opts.zoom != 1
107
+
108
+ ## make sure outdir exits (default is current working dir e.g. .)
109
+ FileUtils.mkdir_p( opts.outdir ) unless Dir.exist?( opts.outdir )
110
+
111
+ args.each_with_index do |arg,index|
112
+ punk_index = arg.to_i( 10 ) ## assume base 10 decimal
113
+
114
+ punk = punks[ punk_index ]
115
+
116
+ punk_name = "punk-" + "%04d" % (punk_index + opts.offset)
117
+
118
+ ## if zoom - add x2,x4 or such
119
+ if opts.zoom != 1
120
+ punk = punk.zoom( opts.zoom )
121
+ punk_name << "@#{opts.zoom}x"
122
+ end
123
+
124
+ path = "#{opts.outdir}/#{punk_name}.png"
125
+ puts "==> (#{index+1}/#{args.size}) saving punk ##{punk_index+opts.offset} to >#{path}<..."
126
+
127
+ punk.save( path )
128
+ end
129
+ puts 'Done.'
130
+ end # action
131
+ end # command tile
132
+
133
+
134
+
135
+ desc 'Generate punk characters from text attributes (from scratch / zero) via builtin punk spritesheet'
136
+ command [:g, :gen, :generate] do |c|
137
+ c.action do |g,o,args|
138
+
139
+ puts "==> generating >#{args.join( ' + ' )}<..."
140
+ punk = Image.generate( *args )
141
+
142
+ puts " setting zoom to #{opts.zoom}x" if opts.zoom != 1
143
+
144
+ ## make sure outdir exits (default is current working dir e.g. .)
145
+ FileUtils.mkdir_p( opts.outdir ) unless Dir.exist?( opts.outdir )
146
+
147
+ punk_index = 0 ## assume base 10 decimal
148
+ punk_name = "punk-" + "%04d" % (punk_index + opts.offset)
149
+
150
+ ## if zoom - add x2,x4 or such
151
+ if opts.zoom != 1
152
+ punk = punk.zoom( opts.zoom )
153
+ punk_name << "@#{opts.zoom}x"
154
+ end
155
+
156
+ path = "#{opts.outdir}/#{punk_name}.png"
157
+ puts "==> saving punk ##{punk_index+opts.offset} to >#{path}<..."
158
+
159
+ punk.save( path )
160
+ puts 'Done.'
161
+ end # action
162
+ end # command generate
163
+
164
+
165
+ desc 'Query (builtin off-chain) punk contract for punk text attributes by IDs - use 0 to 9999'
166
+ command [:q, :query] do |c|
167
+ c.action do |g,o,args|
168
+
169
+ # puts "opts:"
170
+ # puts opts.inspect
171
+
172
+ args.each_with_index do |arg,index|
173
+ punk_index = arg.to_i( 10 ) ## assume base 10 decimal
174
+
175
+ puts "==> (#{index+1}/#{args.size}) punk ##{punk_index}..."
176
+
177
+ attribute_names = CryptopunksData.punk_attributes( punk_index )
178
+ ## downcase name and change spaces to underscore
179
+ attribute_names = attribute_names.map do |name|
180
+ name.downcase.gsub( ' ', '_' )
181
+ end
182
+
183
+ print " "
184
+ print attribute_names.join( ' ' )
185
+ print "\n"
186
+ end
187
+ puts 'Done.'
188
+ end
189
+ end
190
+
191
+
192
+
193
+ desc 'List all punk archetype and attribute names from builtin punk spritesheet'
194
+ command [:l, :ls, :list] do |c|
195
+ c.action do |g,o,args|
196
+
197
+ generator = Cryptopunks.generator
198
+
199
+ puts "==> Archetypes"
200
+ generator.meta.each do |rec|
201
+ next unless rec.archetype?
202
+
203
+ print " "
204
+ print "%-30s" % "#{rec.name} / (#{rec.gender})"
205
+ print " - #{rec.type}"
206
+ print "\n"
207
+ end
208
+
209
+ puts ""
210
+ puts "==> Attributes"
211
+ generator.meta.each do |rec|
212
+ next unless rec.attribute?
213
+
214
+ print " "
215
+ print "%-30s" % "#{rec.name} / (#{rec.gender})"
216
+ print " - #{rec.type}"
217
+ print "\n"
218
+ end
219
+
220
+ puts ""
221
+ puts " See github.com/cryptopunksnotdead/punks.spritesheet for more."
222
+ puts ""
223
+
224
+ puts 'Done.'
225
+ end # action
226
+ end # command list
227
+
228
+
229
+
230
+ pre do |g,c,o,args|
231
+ opts.merge_gli_options!( g )
232
+ opts.merge_gli_options!( o )
233
+
234
+ if opts.verbose?
235
+ ## LogUtils::Logger.root.level = :debug
236
+ end
237
+
238
+ ## logger.debug "Executing #{c.name}"
239
+ true
240
+ end
241
+
242
+ post do |global,c,o,args|
243
+ ## logger.debug "Executed #{c.name}"
244
+ true
245
+ end
246
+
247
+
248
+ on_error do |e|
249
+ puts
250
+ puts "*** error: #{e.message}"
251
+
252
+ if opts.verbose?
253
+ puts e.backtrace
254
+ end
255
+
256
+ false # skip default error handling
257
+ end
258
+
259
+
260
+ ### exit run(ARGV) ## note: use Toolii.run( ARGV ) outside of class
261
+ end # class Toolii
262
+ end # module Cryptopunks
263
+
264
+
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Cryptopunks
4
4
 
5
- MAJOR = 1
6
- MINOR = 3
5
+ MAJOR = 2
6
+ MINOR = 0
7
7
  PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
data/lib/cryptopunks.rb CHANGED
@@ -7,6 +7,7 @@ require 'csvreader'
7
7
  ## extra stdlibs
8
8
  require 'digest' ## move/add to pixelart upstream - why? why not?
9
9
  require 'optparse'
10
+ require 'gli' ## used for command line tool
10
11
 
11
12
 
12
13
 
@@ -71,100 +72,34 @@ end # module Cryptopunks
71
72
 
72
73
 
73
74
 
75
+ ####
76
+ # add CryptoPunksData (off-chain) contract
77
+ require 'cryptopunks/contract/punksdata-assets'
78
+ require 'cryptopunks/contract/punksdata-meta'
79
+ require 'cryptopunks/contract/punksdata-contract'
80
+ CryptoPunksData = CryptopunksData
81
+ PunksData = CryptopunksData
74
82
 
75
83
 
76
84
 
77
- module Cryptopunks
78
- class Tool
79
- def run( args )
80
- opts = { zoom: 1,
81
- outdir: '.',
82
- file: './punks.png',
83
- offset: 0,
84
- }
85
-
86
- parser = OptionParser.new do |cmd|
87
- cmd.banner = "Usage: punk (or cryptopunk) [options] IDs"
88
-
89
- cmd.separator " Mint punk characters from composite (#{opts[:file]}) - for IDs use 0 to 9999"
90
- cmd.separator ""
91
- cmd.separator " Options:"
92
-
93
- cmd.on("-z", "--zoom=ZOOM", "Zoom factor x2, x4, x8, etc. (default: #{opts[:zoom]})", Integer ) do |zoom|
94
- opts[:zoom] = zoom
95
- end
96
-
97
- cmd.on("-d", "--dir=DIR", "Output directory (default: #{opts[:outdir]})", String ) do |outdir|
98
- opts[:outdir] = outdir
99
- end
100
-
101
- cmd.on("-f", "--file=FILE", "True Official Genuine CryptoPunks™ composite image (default: #{opts[:file]})", String ) do |file|
102
- opts[:file] = file
103
- end
104
-
105
- cmd.on("--offset=NUM", "Start counting at offset (default: #{opts[:offset]})", Integer ) do |offset|
106
- opts[:offset] = offset
107
- end
108
-
109
- cmd.on("-h", "--help", "Prints this help") do
110
- puts cmd
111
- exit
112
- end
113
- end
114
-
115
- parser.parse!( args )
116
-
117
- puts "opts:"
118
- pp opts
119
-
120
- puts "==> reading >#{opts[:file]}<..."
121
- punks = ImageComposite.read( opts[:file] )
122
-
123
-
124
- puts " setting zoom to #{opts[:zoom]}x" if opts[:zoom] != 1
125
-
126
- ## make sure outdir exits (default is current working dir e.g. .)
127
- FileUtils.mkdir_p( opts[:outdir] ) unless Dir.exist?( opts[:outdir] )
128
-
129
- args.each_with_index do |arg,index|
130
- punk_index = arg.to_i
131
-
132
- punk = punks[ punk_index ]
133
85
 
134
- punk_name = "punk-" + "%04d" % (punk_index + opts[:offset])
135
86
 
136
- ## if zoom - add x2,x4 or such
137
- if opts[:zoom] != 1
138
- punk = punk.zoom( opts[:zoom] )
139
- punk_name << "x#{opts[:zoom]}"
140
- end
87
+ require 'cryptopunks/tool'
141
88
 
142
- path = "#{opts[:outdir]}/#{punk_name}.png"
143
- puts "==> (#{index+1}/#{args.size}) minting punk ##{punk_index+opts[:offset]}; writing to >#{path}<..."
144
-
145
- punk.save( path )
146
- end
147
-
148
- puts "done"
149
- end ## method run
150
- end # class Tool
151
-
152
-
153
- def self.main( args=ARGV )
154
- Tool.new.run( args )
155
- end
89
+ ### add tool convenience helper
90
+ module Cryptopunks
91
+ def self.main( args=ARGV ) Tool.new.run( args ); end
156
92
  end ## module Cryptopunks
157
93
 
158
94
 
159
95
 
160
96
 
97
+
161
98
  ### add some convenience shortcuts
162
99
  CryptoPunks = Cryptopunks
163
100
  Punks = Cryptopunks
164
101
 
165
102
 
166
-
167
-
168
103
  ###
169
104
  # note: for convenience auto include Pixelart namespace!!! - why? why not?
170
105
  include Pixelart
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptopunks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-11 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pixelart
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gli
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rdoc
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -97,10 +111,14 @@ files:
97
111
  - lib/cryptopunks/attributes.rb
98
112
  - lib/cryptopunks/colors.rb
99
113
  - lib/cryptopunks/composite.rb
114
+ - lib/cryptopunks/contract/punksdata-assets.rb
115
+ - lib/cryptopunks/contract/punksdata-contract.rb
116
+ - lib/cryptopunks/contract/punksdata-meta.rb
100
117
  - lib/cryptopunks/dataset.rb
101
118
  - lib/cryptopunks/generator.rb
102
119
  - lib/cryptopunks/image.rb
103
120
  - lib/cryptopunks/structs.rb
121
+ - lib/cryptopunks/tool.rb
104
122
  - lib/cryptopunks/version.rb
105
123
  homepage: https://github.com/cryptopunksnotdead/cryptopunks
106
124
  licenses: