ruby: tweak apis

develop
jj 2012-09-01 02:55:55 +02:00
parent ce608e4f6a
commit dcc9498dbc
2 changed files with 11 additions and 9 deletions

@ -46,6 +46,7 @@ module DFHack
raise "invalid building type #{type.inspect}" if not cls raise "invalid building type #{type.inspect}" if not cls
bld = cls.cpp_new bld = cls.cpp_new
bld.race = ui.race_id bld.race = ui.race_id
subtype = WorkshopType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Workshop
bld.setSubtype(subtype) if subtype != -1 bld.setSubtype(subtype) if subtype != -1
bld.setCustomType(custom) if custom != -1 bld.setCustomType(custom) if custom != -1
case type case type
@ -176,9 +177,10 @@ module DFHack
# set building at position, with optional width/height # set building at position, with optional width/height
def building_position(bld, pos, w=nil, h=nil) def building_position(bld, pos, w=nil, h=nil)
bld.x1 = pos.x x, y, z = (pos.respond_to?(:x) ? [pos.x, pos.y, pos.z] : pos)
bld.y1 = pos.y bld.x1 = x
bld.z = pos.z bld.y1 = y
bld.z = z
bld.x2 = bld.x1+w-1 if w bld.x2 = bld.x1+w-1 if w
bld.y2 = bld.y1+h-1 if h bld.y2 = bld.y1+h-1 if h
building_setsize(bld) building_setsize(bld)

@ -51,7 +51,7 @@ module DFHack
end end
SaplingToTreeAge = 120960 SaplingToTreeAge = 120960
def cuttrees(material=nil, count_max=100) def cuttrees(material=nil, count_max=100, quiet=false)
if !material if !material
# list trees # list trees
cnt = Hash.new(0) cnt = Hash.new(0)
@ -62,7 +62,7 @@ module DFHack
} }
cnt.sort_by { |mat, c| c }.each { |mat, c| cnt.sort_by { |mat, c| c }.each { |mat, c|
name = @raws_tree_name[mat] name = @raws_tree_name[mat]
puts " #{name} #{c}" puts " #{name} #{c}" unless quiet
} }
else else
cnt = 0 cnt = 0
@ -78,11 +78,11 @@ module DFHack
break if cnt == count_max break if cnt == count_max
end end
} }
puts "Updated #{cnt} plant designations" puts "Updated #{cnt} plant designations" unless quiet
end end
end end
def growtrees(material=nil, count_max=100) def growtrees(material=nil, count_max=100, quiet=false)
if !material if !material
# list plants # list plants
cnt = Hash.new(0) cnt = Hash.new(0)
@ -93,7 +93,7 @@ module DFHack
} }
cnt.sort_by { |mat, c| c }.each { |mat, c| cnt.sort_by { |mat, c| c }.each { |mat, c|
name = @raws_tree_name[mat] name = @raws_tree_name[mat]
puts " #{name} #{c}" puts " #{name} #{c}" unless quiet
} }
else else
cnt = 0 cnt = 0
@ -104,7 +104,7 @@ module DFHack
cnt += 1 cnt += 1
break if cnt == count_max break if cnt == count_max
} }
puts "Grown #{cnt} saplings" puts "Grown #{cnt} saplings" unless quiet
end end
end end
end end