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}"))
......
...@@ -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,29 +20,36 @@ begin ...@@ -19,29 +20,36 @@ 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")
arg.force_encoding("GBK") unless arg.valid_encoding?
case arg
when /--log=(.*)/ when /--log=(.*)/
log.replace $1 log.replace $1
when /--log-level=(.*)/ when /--log-level=(.*)/
log_level.replace $1 log_level.replace $1
when /--profile=(.*)/ when /--profile=(.*)/
profile = $1 profile = $1
when /mycard:.*/ when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart' require_relative 'quickstart'
$scene = false $scene = false
when /register_web_protocol/ when /register_web_protocol/
...@@ -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
...@@ -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,27 +4,48 @@ require_relative 'room' ...@@ -4,27 +4,48 @@ 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)
else
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' require 'open-uri'
open("http://"+ URI.escape($1), 'rb') { |src| #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
}
Ygocore.replay('replay/' + File.basename($1), true)
when /^(.*\.ydk)$/
require 'open-uri' require 'open-uri'
open("http://" + URI.escape($1), 'rb') { |src| #fix File.basename
$1 =~ /(.*)(?:\\|\/)(.*?)\.ydk/
src = open(uri, 'rb') { |src| src.read }
Dir.mkdir('ygocore/deck') unless File.directory?("ygocore/deck")
open('ygocore/deck/' + $2 + '.ydk', 'wb') { |dest| dest.write src }
Ygocore.run_ygocore($2, true)
when /^(.*)(\.txt|\.deck)$/i
require_relative 'deck'
d = $1
deck = Deck.load($&)
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| d =~ /^(.*)(?:\\|\/)(.*?)$/
dest.write src.read open('ygocore/deck/' + $2 + '.ydk', 'w') do |dest|
} dest.puts("#main")
} deck.main.each { |card| dest.puts card.number }
Ygocore.run_ygocore(File.basename($1, '.ydk'), true) dest.puts("#extra")
when /^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/ 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' require 'uri'
$game.user = User.new($1.to_sym, $1) if $1 $game.user = User.new($1.to_sym, $1) if $1
$game.password = $2 if $2 $game.password = $2 if $2
......
...@@ -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