class WolfRpg::Command
Constants
- CID_TO_CLASS
Map
of CIDs to classes #
Attributes
args[R]
cid[R]
indent[R]
string_args[R]
Public Class Methods
create(coder)
click to toggle source
Load from the file and create the appropriate class object
# File lib/wolfrpg/command.rb, line 376 def self.create(coder) # Read all data for this command from file args = Array.new(coder.read_byte - 1) cid = coder.read_int args.each_index do |i| args[i] = coder.read_int end indent = coder.read_byte string_args = Array.new(coder.read_byte) string_args.each_index do |i| string_args[i] = coder.read_string end # Read the move list if necessary terminator = coder.read_byte if terminator == 0x01 return Command::Move.new(cid, args, string_args, indent, coder) elsif terminator != 0x00 raise "command terminator is an unexpected value (#{terminator})" end # Create command return CID_TO_CLASS[cid].new(cid, args, string_args, indent) end
new(cid, args, string_args, indent)
click to toggle source
# File lib/wolfrpg/command.rb, line 425 def initialize(cid, args, string_args, indent) @cid = cid @args = args @string_args = string_args @indent = indent end
Public Instance Methods
dump(coder)
click to toggle source
# File lib/wolfrpg/command.rb, line 401 def dump(coder) coder.write_byte(@args.size + 1) coder.write_int(@cid) @args.each do |arg| coder.write_int(arg) end coder.write_byte(indent) coder.write_byte(@string_args.size) @string_args.each do |arg| coder.write_string(arg) end dump_terminator(coder) end
each_filename() { |gsub('\\', '/')| ... }
click to toggle source
# File lib/wolfrpg/command.rb, line 416 def each_filename @string_args.each do |str| str.scan(/^[^ ]*?[\/\\].*?\.[a-zA-Z0-9]+$/).each do |filename| yield filename.gsub('\\', '/') end end end
Private Instance Methods
dump_terminator(coder)
click to toggle source
# File lib/wolfrpg/command.rb, line 432 def dump_terminator(coder) coder.write_byte(0) end