Commit 5f588e30 authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.6.3 LP

0.6.4 快速启动(浏览器接口)
parent 88c8c5e4
...@@ -24,7 +24,7 @@ end ...@@ -24,7 +24,7 @@ end
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'mycard' s.name = 'mycard'
s.version = '0.6.2' s.version = '0.6.4'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt'] s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game' s.summary = 'a card game'
s.description = s.summary s.description = s.summary
......
...@@ -50,4 +50,7 @@ module Dialog ...@@ -50,4 +50,7 @@ module Dialog
def web(url) def web(url)
Shell.ShellExecute url Shell.ShellExecute url
end end
def uac(command, *args)
Shell.ShellExecute File.expand_path(command), args.join(' '), Dir.pwd, "runas"
end
end end
\ No newline at end of file
#!/usr/bin/env ruby #!/usr/bin/env ruby
begin begin
#定义全局方法 #定义全局方法
def load_config(file="config.yml") def load_config(file="config.yml")
...@@ -14,6 +13,16 @@ begin ...@@ -14,6 +13,16 @@ begin
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
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
require 'win32/registry'
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard'){|reg|reg['URL Protocol'] = path unless (reg['URL Protocol'] == path rescue false)}
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command'){|reg|reg[nil] = command unless (reg[nil] == command rescue false)}
end
end
Thread.abort_on_exception = true Thread.abort_on_exception = true
require_relative 'announcement' require_relative 'announcement'
#读取配置文件 #读取配置文件
...@@ -32,63 +41,70 @@ begin ...@@ -32,63 +41,70 @@ begin
log_level.replace $1 log_level.replace $1
when /--profile=(.*)/ when /--profile=(.*)/
profile = $1 profile = $1
when /mycard:.*/
require_relative 'quickstart'
$scene = false
when /register_web_protocol/
register_url_protocol
$scene = false
end end
end end
unless $scene == false
#初始化SDL #初始化SDL
require 'sdl' require 'sdl'
include SDL include SDL
SDL::Event::APPMOUSEFOCUS = 1 SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2 SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4 SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1"); SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO | INIT_AUDIO) SDL.init(INIT_VIDEO | INIT_AUDIO)
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
#初始化日志 #初始化日志
require 'logger' require 'logger'
if log == "STDOUT" #调试用 if log == "STDOUT" #调试用
log = STDOUT log = STDOUT
STDOUT.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"] STDOUT.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
end end
$log = Logger.new(log) $log = Logger.new(log)
$log.level = Logger.const_get log_level $log.level = Logger.const_get log_level
#性能分析 #性能分析
if profile if profile
if profile == "STDOUT" if profile == "STDOUT"
profile = STDOUT profile = STDOUT
else else
profile = open(profile, 'w') profile = open(profile, 'w')
end
require 'profiler'
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:specialized_instruction => false
}
Profiler__::start_profile
end end
require 'profiler'
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:specialized_instruction => false
}
Profiler__::start_profile
end
#初始化标题场景 #初始化标题场景
require_relative 'scene_title' require_relative 'scene_title'
$scene = Scene_Title.new $scene = Scene_Title.new
#自动更新 #自动更新
require_relative 'update' require_relative 'update'
Update.start Update.start
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")
$log.info("main"){"初始化成功"} $log.info("main"){"初始化成功"}
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")}
exit(1) $scene = false
end end
#主循环 #主循环
...@@ -106,5 +122,5 @@ ensure ...@@ -106,5 +122,5 @@ ensure
Profiler__::print_profile(profile) Profiler__::print_profile(profile)
profile.close profile.close
end end
$log.close $log.close rescue nil
end end
\ No newline at end of file
require 'json'
require_relative 'game'
require_relative 'user'
require_relative 'room'
require_relative 'ygocore/game'
$game = Ygocore.new
args = JSON.parse ARGV.first[7, ARGV.first.size-7].unpack('m').first
$game.user = User.new(args["username"].to_sym, args["username"])
$game.password = args["password"]
$game.server = args['server_ip']
$game.port = args['server_port']
Ygocore.run_ygocore Room.new(0, args['room_name']), true
\ No newline at end of file
...@@ -13,7 +13,6 @@ class Scene_Login < Scene ...@@ -13,7 +13,6 @@ class Scene_Login < Scene
def start def start
WM::set_caption("MyCard v#{Update::Version}", "MyCard") WM::set_caption("MyCard v#{Update::Version}", "MyCard")
@background = Surface.load("graphics/login/background.png").display_format @background = Surface.load("graphics/login/background.png").display_format
$config['game'] = 'iDuel' if $config['game'] == '局域网' #临时修补点击过一次局域网之后无限进入局域网的问题
@gameselect_window = Window_GameSelect.new(117,269) @gameselect_window = Window_GameSelect.new(117,269)
super super
end end
......
...@@ -2,7 +2,7 @@ require 'open-uri' ...@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils" require "fileutils"
require_relative 'card' require_relative 'card'
module Update module Update
Version = '0.6.2' Version = '0.6.4'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}" URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self class <<self
attr_reader :thumbnails, :images, :status attr_reader :thumbnails, :images, :status
......
...@@ -11,8 +11,9 @@ class Window_Host < Window ...@@ -11,8 +11,9 @@ class Window_Host < Window
@color = [0x04, 0x47, 0x7c] @color = [0x04, 0x47, 0x7c]
@roomname_inputbox = Widget_InputBox.new(@x+96, @y+41, 165, WLH) @roomname_inputbox = Widget_InputBox.new(@x+96, @y+41, 165, WLH)
@password_inputbox = Widget_InputBox.new(@x+96, @y+41+WLH, 165, WLH) @password_inputbox = Widget_InputBox.new(@x+96, @y+41+WLH, 165, WLH)
@lp_inputbox = Widget_InputBox.new(@x+96, @y+41+WLH*6+4, 64, WLH)
@pvp = Widget_Checkbox.new(self, 33+@x,@y+41+WLH*2,120,24,false,"竞技场") {|checked|(@ocg.checked = true; @tcg.checked = @tag.checked = false) if checked} @pvp = Widget_Checkbox.new(self, 33+@x,@y+41+WLH*2,120,24,false,"竞技场") {|checked|(@ocg.checked = true; @tcg.checked = @tag.checked = false; @lp_inputbox.value = "8000") if checked}
@pvp.background = @background.copy_rect(33,70,120,24) @pvp.background = @background.copy_rect(33,70,120,24)
@match = Widget_Checkbox.new(self, 120+@x,@y+41+WLH*2,120,24,true,"三回决斗"){|checked|@tag.checked = false if checked} @match = Widget_Checkbox.new(self, 120+@x,@y+41+WLH*2,120,24,true,"三回决斗"){|checked|@tag.checked = false if checked}
@match.background = @background.copy_rect(120,70,120,24) @match.background = @background.copy_rect(120,70,120,24)
...@@ -24,6 +25,7 @@ class Window_Host < Window ...@@ -24,6 +25,7 @@ class Window_Host < Window
@tcg.background = @background.copy_rect(120,70,120,24) @tcg.background = @background.copy_rect(120,70,120,24)
@roomname_inputbox.value = rand(1000).to_s @roomname_inputbox.value = rand(1000).to_s
@lp_inputbox.value = 8000.to_s
@password_inputbox.refresh @password_inputbox.refresh
@pvp.refresh @pvp.refresh
@match.refresh @match.refresh
...@@ -34,11 +36,12 @@ class Window_Host < Window ...@@ -34,11 +36,12 @@ class Window_Host < Window
end end
def refresh def refresh
clear clear
@font.draw_blended_utf8(@contents, "新房间", (@width-@font.text_size("新房间")[0])/2, 2, *@title_color) @font.draw_blended_utf8(@contents, "建立房间", (@width-@font.text_size("建立房间")[0])/2, 2, *@title_color)
@font.draw_blended_utf8(@contents, "房间名", 33,43, *@color) @font.draw_blended_utf8(@contents, "房间名", 33,43, *@color)
@font.draw_blended_utf8(@contents, "房间密码", 33,43+WLH, *@color) @font.draw_blended_utf8(@contents, "房间密码", 33,43+WLH, *@color)
@contents.fill_rect(4,43+WLH*3,@contents.w-8, 2, 0xAA0A7AC5) @contents.fill_rect(4,43+WLH*3,@contents.w-8, 2, 0xAA0A7AC5)
@font.draw_blended_utf8(@contents, "自定义模式", 20,43+WLH*3+4, *@color) @font.draw_blended_utf8(@contents, "自定义模式", 20,43+WLH*3+4, *@color)
@font.draw_blended_utf8(@contents, "初始LP", 33,44+WLH*6+4, *@color)
@items.each_key do |index| @items.each_key do |index|
draw_item(index, self.index==index ? 1 : 0) draw_item(index, self.index==index ? 1 : 0)
end end
...@@ -82,10 +85,12 @@ class Window_Host < Window ...@@ -82,10 +85,12 @@ class Window_Host < Window
Widget_Msgbox.new("建立房间", "请输入房间名", ok: "确定" ) Widget_Msgbox.new("建立房间", "请输入房间名", ok: "确定" )
elsif !name_check elsif !name_check
Widget_Msgbox.new("建立房间", "房间名/房间密码超过长度上限", ok: "确定") Widget_Msgbox.new("建立房间", "房间名/房间密码超过长度上限", ok: "确定")
elsif @lp_inputbox.value.to_i >= 99999
Widget_Msgbox.new("建立房间", "初始LP超过上限", ok: "确定")
else else
Widget_Msgbox.new("建立房间", "正在建立房间") Widget_Msgbox.new("建立房间", "正在建立房间")
destroy destroy
$game.host(@roomname_inputbox.value, password: @password_inputbox.value, pvp: @pvp.checked?, match: @match.checked?, tag: @tag.checked?, ot: @tcg.checked? ? @ocg.checked? ? 2 : 1 : 0) $game.host(@roomname_inputbox.value, password: @password_inputbox.value, pvp: @pvp.checked?, match: @match.checked?, tag: @tag.checked?, ot: @tcg.checked? ? @ocg.checked? ? 2 : 1 : 0, lp: @lp_inputbox.value.to_i)
end end
when :cancel when :cancel
destroy destroy
...@@ -94,6 +99,7 @@ class Window_Host < Window ...@@ -94,6 +99,7 @@ class Window_Host < Window
def destroy def destroy
@roomname_inputbox.destroy @roomname_inputbox.destroy
@password_inputbox.destroy @password_inputbox.destroy
@lp_inputbox.destroy
@pvp.destroy @pvp.destroy
@match.destroy @match.destroy
@tag.destroy @tag.destroy
...@@ -104,6 +110,7 @@ class Window_Host < Window ...@@ -104,6 +110,7 @@ class Window_Host < Window
def update def update
@roomname_inputbox.update @roomname_inputbox.update
@password_inputbox.update @password_inputbox.update
@lp_inputbox.update
end end
def name_check def name_check
name = @roomname_inputbox.value name = @roomname_inputbox.value
...@@ -124,6 +131,7 @@ class Window_Host < Window ...@@ -124,6 +131,7 @@ class Window_Host < Window
max = 20 max = 20
max -= 1 if name.ascii_only? max -= 1 if name.ascii_only?
end end
max -= @lp_inputbox.value.size - 4
if !@password_inputbox.value.empty? if !@password_inputbox.value.empty?
max -= 1 max -= 1
max -= @password_inputbox.value.encode("GBK").bytesize max -= @password_inputbox.value.encode("GBK").bytesize
......
...@@ -29,7 +29,7 @@ class Window_LobbyButtons < Window_List ...@@ -29,7 +29,7 @@ class Window_LobbyButtons < Window_List
case @index case @index
when 0 #常见问题 when 0 #常见问题
require_relative 'dialog' require_relative 'dialog'
Dialog.web "http://card.touhou.cc/login?user[name]=#{CGI.escape $game.username}&user[password]=#{CGI.escape $game.password}&continue=/topics/1453" Dialog.web "http://card.touhou.cc/login?user[name]=#{CGI.escape $game.user.name}&user[password]=#{CGI.escape $game.password}&continue=/topics/1453"
when 1 #卡组编辑 when 1 #卡组编辑
$game.class.deck_edit $game.class.deck_edit
when 2 #建立房间 when 2 #建立房间
......
...@@ -48,6 +48,7 @@ class Game_Event ...@@ -48,6 +48,7 @@ class Game_Event
result.tag = room[:tag] result.tag = room[:tag]
result.ot = room[:ot] result.ot = room[:ot]
result.status = room[:status] result.status = room[:status]
result.lp = room[:lp]
result result
end end
def self.parse_user(user) def self.parse_user(user)
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
load 'lib/ygocore/window_login.rb' load 'lib/ygocore/window_login.rb'
require 'eventmachine' require 'eventmachine'
require 'open-uri' require 'open-uri'
require 'yaml'
class Ygocore < Game class Ygocore < Game
attr_reader :username attr_reader :username
attr_reader :password attr_accessor :password
@@config = YAML.load_file("lib/ygocore/server.yml") @@config = YAML.load_file("lib/ygocore/server.yml")
def initialize def initialize
super super
...@@ -45,6 +46,7 @@ class Ygocore < Game ...@@ -45,6 +46,7 @@ class Ygocore < Game
room.tag = room_config[:tag] room.tag = room_config[:tag]
room.password = room_config[:password] room.password = room_config[:password]
room.ot = room_config[:ot] room.ot = room_config[:ot]
room.lp = room_config[:lp]
if $game.rooms.any?{|game_room|game_room.name == room_name} if $game.rooms.any?{|game_room|game_room.name == room_name}
Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定") Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定")
else else
...@@ -80,21 +82,26 @@ class Ygocore < Game ...@@ -80,21 +82,26 @@ class Ygocore < Game
def port def port
@@config['port'] @@config['port']
end end
def server=(server)
@@config['server'] = server
end
def port=(port)
@@config['port'] = port
end
def self.run_ygocore(option, image_downloading=false) def self.run_ygocore(option, image_downloading=false)
if !image_downloading and !Update.images.empty? if !image_downloading and !Update.images.empty?
return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定"){run_ygocore(option, true)} return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定"){run_ygocore(option, true)}
end end
path = 'ygocore/ygopro_vs.exe' path = 'ygocore/ygopro_vs.exe'
Widget_Msgbox.new("ygocore", "正在启动ygocore") Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil
#写入配置文件并运行ygocore #写入配置文件并运行ygocore
Dir.chdir(File.dirname(path)) do Dir.chdir(File.dirname(path)) do
$log.info('当前目录'){Dir.pwd.encode("UTF-8")}
case option case option
when Room when Room
room = option room = option
room_name = if room.ot != 0 room_name = if room.ot != 0 or room.lp != 8000
mode = case when room.match? then 1; when room.tag? then 2 else 0 end mode = case when room.match? then 1; when room.tag? then 2 else 0 end
room_name = "#{room.ot}#{mode}FFF8000,5,1,#{room.name}" room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
elsif room.tag? elsif room.tag?
"T#" + room.name "T#" + room.name
elsif room.pvp? and room.match? elsif room.pvp? and room.match?
...@@ -121,8 +128,6 @@ class Ygocore < Game ...@@ -121,8 +128,6 @@ class Ygocore < Game
system_conf['antialias'] = 2 system_conf['antialias'] = 2
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14' system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf' system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
$log.error('找不到system.conf')
$log.info(Dir.foreach('.').to_a.inspect)
end end
system_conf['nickname'] = "#{$game.user.name}#{"$" unless $game.password.nil? or $game.password.empty?}#{$game.password}" system_conf['nickname'] = "#{$game.user.name}#{"$" unless $game.password.nil? or $game.password.empty?}#{$game.password}"
system_conf['lastip'] = $game.server system_conf['lastip'] = $game.server
...@@ -135,11 +140,10 @@ class Ygocore < Game ...@@ -135,11 +140,10 @@ class Ygocore < Game
when :deck when :deck
args = '-d' args = '-d'
end end
$log.info('ygocore参数') {args}
IO.popen("ygopro_vs.exe #{args}") IO.popen("ygopro_vs.exe #{args}")
WM.iconify WM.iconify rescue nil
end end
Widget_Msgbox.destroy Widget_Msgbox.destroy rescue nil
end end
def self.deck_edit def self.deck_edit
Widget_Msgbox.new("编辑卡组", "\"导入\"导入已有卡组,\"编辑\"启动ygocore", :import => "导入", :edit => "编辑") do |button| Widget_Msgbox.new("编辑卡组", "\"导入\"导入已有卡组,\"编辑\"启动ygocore", :import => "导入", :edit => "编辑") do |button|
......
...@@ -3,11 +3,14 @@ class Room ...@@ -3,11 +3,14 @@ class Room
attr_accessor :match attr_accessor :match
attr_accessor :tag attr_accessor :tag
attr_accessor :ot attr_accessor :ot
attr_accessor :lp
attr_accessor :status attr_accessor :status
alias pvp? pvp alias pvp? pvp
alias match? match alias match? match
alias tag? tag alias tag? tag
def lp
@lp ||= 8000
end
def ot def ot
@ot ||= 0 @ot ||= 0
end end
...@@ -29,6 +32,9 @@ class Room ...@@ -29,6 +32,9 @@ class Room
elsif ot == 2 elsif ot == 2
result["[O/T混]"] = [255,0,0] result["[O/T混]"] = [255,0,0]
end end
if lp != 8000
result["[LP: #{lp}]"] = [255,0,0]
end
result result
end end
end end
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