Commit 194e405d authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.7.0

parent bf1cafa6
...@@ -15,11 +15,10 @@ class Card ...@@ -15,11 +15,10 @@ class Card
else else
'' #其他操作系统卡图存放位置标准尚未制定。 '' #其他操作系统卡图存放位置标准尚未制定。
end end
CardBack = Surface.load("graphics/field/card.jpg").display_format CardBack = Surface.load("graphics/field/card.jpg").display_format rescue nil
CardBack_Small = Surface.load("graphics/field/card_small.gif").display_format CardBack_Small = Surface.load("graphics/field/card_small.gif").display_format rescue nil
class << self class << self
def find(id, order_by=nil) def find(id, order_by=nil)
$log.debug('查找卡片'){id.inspect}
case id case id
when Integer when Integer
@all[id] || old_new(@db.get_first_row("select * from `yu-gi-oh` where id = #{id}")) @all[id] || old_new(@db.get_first_row("select * from `yu-gi-oh` where id = #{id}"))
...@@ -64,7 +63,7 @@ class Card ...@@ -64,7 +63,7 @@ class Card
stats = records.GetRows.first stats = records.GetRows.first
stats.unshift nil stats.unshift nil
records.close records.close
records = WIN32OLE.new('ADODB.Recordset') records = WIN32OLE.new('ADODB.Recordset')
records.open("YGODATA", conn) records.open("YGODATA", conn)
records.MoveNext #跳过首行那个空白卡 records.MoveNext #跳过首行那个空白卡
...@@ -154,7 +153,7 @@ class Card ...@@ -154,7 +153,7 @@ class Card
@mediums = hash['mediums'].split("\t").collect{|medium|medium.to_sym} @mediums = hash['mediums'].split("\t").collect{|medium|medium.to_sym}
@tokens = hash['tokens'].to_i @tokens = hash['tokens'].to_i
@token = hash['token'] @token = hash['token']
Card.cache[@id] = self Card.cache[@id] = self
end end
def create_image def create_image
...@@ -178,16 +177,16 @@ class Card ...@@ -178,16 +177,16 @@ class Card
@id == 1 @id == 1
end end
def monster? def monster?
[:融合怪兽, :同调怪兽, :超量怪兽, :通常怪兽, :效果怪兽, :调整怪兽, :仪式怪兽].include? card_type [:融合怪兽, :同调怪兽, :超量怪兽, :通常怪兽, :效果怪兽, :调整怪兽, :仪式怪兽].include? card_type
end end
def trap? def trap?
[:通常陷阱, :反击陷阱, :永续陷阱].include? card_type [:通常陷阱, :反击陷阱, :永续陷阱].include? card_type
end end
def spell? def spell?
[:通常魔法, :速攻魔法, :装备魔法, :场地魔法, :仪式魔法, :永续魔法].include? card_type [:通常魔法, :速攻魔法, :装备魔法, :场地魔法, :仪式魔法, :永续魔法].include? card_type
end end
def extra? def extra?
[:融合怪兽, :同调怪兽, :超量怪兽].include? card_type [:融合怪兽, :同调怪兽, :超量怪兽].include? card_type
end end
def token? def token?
@token @token
......
...@@ -10,8 +10,9 @@ begin ...@@ -10,8 +10,9 @@ begin
$config['screen']['width'] ||= 1024 $config['screen']['width'] ||= 1024
$config['screen']['height'] ||= 768 $config['screen']['height'] ||= 768
end end
def save_config(file="config.yml") def save_config(file="config.yml")
File.open(file,"w"){|file| YAML.dump($config, file)} File.open(file, "w") { |file| YAML.dump($config, file) }
end end
def register_url_protocol def register_url_protocol
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"] if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
...@@ -19,34 +20,41 @@ begin ...@@ -19,34 +20,41 @@ begin
pwd = Dir.pwd.gsub('/', '\\') pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb' path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"' command = path + ' "%1"'
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard'){|reg|reg['URL Protocol'] = path.ljust path.bytesize unless (reg['URL Protocol'] == path rescue false)} icon = '"' + pwd + '\mycard.exe", 0'
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command'){|reg|reg[nil] = command.ljust command.bytesize unless (reg[nil] == command rescue false)} Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize unless (reg['URL Protocol'] == path rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize unless (reg[nil] == command rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize unless (reg[nil] == icon rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
end end
end end
Thread.abort_on_exception = true Thread.abort_on_exception = true
require_relative 'announcement' require_relative 'announcement'
#读取配置文件 #读取配置文件
load_config load_config
save_config save_config
#读取命令行参数 #读取命令行参数
log = "log.log" log = "log.log"
log_level = "INFO" log_level = "INFO"
profile = nil profile = nil
ARGV.each do |arg| ARGV.each do |arg|
case arg.dup.force_encoding("UTF-8") arg = arg.dup.force_encoding("UTF-8")
when /--log=(.*)/ arg.force_encoding("GBK") unless arg.valid_encoding?
log.replace $1 case arg
when /--log-level=(.*)/ when /--log=(.*)/
log_level.replace $1 log.replace $1
when /--profile=(.*)/ when /--log-level=(.*)/
profile = $1 log_level.replace $1
when /mycard:.*/ when /--profile=(.*)/
require_relative 'quickstart' profile = $1
$scene = false when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
when /register_web_protocol/ require_relative 'quickstart'
register_url_protocol $scene = false
$scene = false when /register_web_protocol/
register_url_protocol
$scene = false
end end
end end
unless $scene == false unless $scene == false
...@@ -61,7 +69,7 @@ begin ...@@ -61,7 +69,7 @@ begin
WM::set_caption("MyCard", "MyCard") WM::set_caption("MyCard", "MyCard")
WM::icon = Surface.load("graphics/system/icon.gif") WM::icon = Surface.load("graphics/system/icon.gif")
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0)) $screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,1024) Mixer.open(Mixer::DEFAULT_FREQUENCY, Mixer::DEFAULT_FORMAT, Mixer::DEFAULT_CHANNELS, 1024)
Mixer.set_volume_music(60) Mixer.set_volume_music(60)
TTF.init TTF.init
Thread.abort_on_exception = true Thread.abort_on_exception = true
...@@ -82,8 +90,8 @@ begin ...@@ -82,8 +90,8 @@ begin
end end
require 'profiler' require 'profiler'
RubyVM::InstructionSequence.compile_option = { RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true, :trace_instruction => true,
:specialized_instruction => false :specialized_instruction => false
} }
Profiler__::start_profile Profiler__::start_profile
end end
...@@ -99,10 +107,10 @@ begin ...@@ -99,10 +107,10 @@ begin
WM::set_caption("MyCard v#{Update::Version}", "MyCard") WM::set_caption("MyCard v#{Update::Version}", "MyCard")
require_relative 'dialog' require_relative 'dialog'
register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol") register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol")
$log.info("main"){"初始化成功"} $log.info("main") { "初始化成功" }
end end
rescue Exception => exception rescue Exception => exception
open('error-程序出错请到论坛反馈.txt', 'w'){|f|f.write [exception.inspect, *exception.backtrace].join("\n")} open('error-程序出错请到论坛反馈.txt', 'w') { |f| f.write [exception.inspect, *exception.backtrace].join("\n") }
$scene = false $scene = false
end end
...@@ -110,8 +118,8 @@ end ...@@ -110,8 +118,8 @@ end
begin begin
$scene.main while $scene $scene.main while $scene
rescue Exception => exception rescue Exception => exception
exception.backtrace.each{|backtrace|break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/} #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件 exception.backtrace.each { |backtrace| break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/ } #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log.fatal($1){[exception.inspect, *exception.backtrace].collect{|str|str.force_encoding("UTF-8")}.join("\n")} $log.fatal($1) { [exception.inspect, *exception.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
$game.exit if $game $game.exit if $game
require_relative 'scene_error' require_relative 'scene_error'
$scene = Scene_Error.new $scene = Scene_Error.new
......
...@@ -4,31 +4,52 @@ require_relative 'room' ...@@ -4,31 +4,52 @@ require_relative 'room'
require_relative 'ygocore/game' require_relative 'ygocore/game'
$game = Ygocore.new $game = Ygocore.new
uri = URI.unescape URI.unescape ARGV.first[9, ARGV.first.size-9] if ARGV.first[0, 9] == 'mycard://'
case uri file = URI.unescape URI.unescape ARGV.first[9, ARGV.first.size-9]
when /^(.*\.yrp)$/ uri = "http://" + URI.escape(file)
require 'open-uri' else
open("http://"+ URI.escape($1), 'rb') { |src| file = ARGV.first.dup.force_encoding("UTF-8")
file.force_encoding("GBK") unless file.valid_encoding?
file.encode!("UTF-8")
uri = file
end
case file
when /^(.*\.yrp)$/i
require 'open-uri'
#fix File.basename
$1 =~ /(.*)(?:\\|\/)(.*?\.yrp)/
src = open(uri, 'rb') { |src| src.read }
Dir.mkdir("replay") unless File.directory?("replay") Dir.mkdir("replay") unless File.directory?("replay")
open('replay/' + File.basename($1), 'wb'){|dest| open('replay/' + $2, 'wb') { |dest| dest.write src }
dest.write src.read Ygocore.replay('replay/' + $2, true)
} when /^(.*\.ydk)$/i
} require 'open-uri'
Ygocore.replay('replay/' + File.basename($1), true) #fix File.basename
when /^(.*\.ydk)$/ $1 =~ /(.*)(?:\\|\/)(.*?)\.ydk/
require 'open-uri' src = open(uri, 'rb') { |src| src.read }
open("http://" + URI.escape($1), 'rb') { |src|
Dir.mkdir('ygocore/deck') unless File.directory?("ygocore/deck") Dir.mkdir('ygocore/deck') unless File.directory?("ygocore/deck")
open('ygocore/deck/' + File.basename($1), 'wb'){|dest| open('ygocore/deck/' + $2 + '.ydk', 'wb') { |dest| dest.write src }
dest.write src.read Ygocore.run_ygocore($2, true)
} when /^(.*)(\.txt|\.deck)$/i
} require_relative 'deck'
Ygocore.run_ygocore(File.basename($1, '.ydk'), true) d = $1
when /^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/ deck = Deck.load($&)
require 'uri' Dir.mkdir('ygocore/deck') unless File.directory?("ygocore/deck")
$game.user = User.new($1.to_sym, $1) if $1 d =~ /^(.*)(?:\\|\/)(.*?)$/
$game.password = $2 if $2 open('ygocore/deck/' + $2 + '.ydk', 'w') do |dest|
$game.server = $3 dest.puts("#main")
$game.port = $4.to_i deck.main.each { |card| dest.puts card.number }
Ygocore.run_ygocore Room.new(0, $5), true dest.puts("#extra")
deck.extra.each { |card| dest.puts card.number }
dest.puts("!side")
deck.side.each { |card| dest.puts card.number }
end
Ygocore.run_ygocore($2, true)
when /^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/
require 'uri'
$game.user = User.new($1.to_sym, $1) if $1
$game.password = $2 if $2
$game.server = $3
$game.port = $4.to_i
Ygocore.run_ygocore Room.new(0, $5), true
end end
\ No newline at end of file
...@@ -3,6 +3,7 @@ class Window_Deck < Window ...@@ -3,6 +3,7 @@ class Window_Deck < Window
def initialize def initialize
@items = Dir.glob("ygocore/deck/*.ydk")[0, 10] @items = Dir.glob("ygocore/deck/*.ydk")[0, 10]
p @items
@background = Surface.load(@items.size > 4 ? 'graphics/lobby/host.png' : 'graphics/system/msgbox.png').display_format @background = Surface.load(@items.size > 4 ? 'graphics/lobby/host.png' : 'graphics/system/msgbox.png').display_format
super((1024-@background.w)/2, 230, @background.w, @background.h, 300) super((1024-@background.w)/2, 230, @background.w, @background.h, 300)
...@@ -61,6 +62,8 @@ class Window_Deck < Window ...@@ -61,6 +62,8 @@ class Window_Deck < Window
i = (x - @x - (@width - @items_buttons.size * @items_button.w / 3)) / (@items_button.w/3) i = (x - @x - (@width - @items_buttons.size * @items_button.w / 3)) / (@items_button.w/3)
if i >= 0 if i >= 0
new_index = [line, @items_buttons.keys[i]] new_index = [line, @items_buttons.keys[i]]
else
new_index = [line, :edit]
end end
else else
@buttons_pos.each_key do |index| @buttons_pos.each_key do |index|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment