Commit 2a2cbaa9 authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.8.2

parent cd38339e
#encoding: UTF-8 #encoding: UTF-8
require 'rubygems' require 'rubygems'
require 'rake' require 'rake'
require 'rake/clean' require 'rake/clean'
require 'rubygems/package_task' require 'rubygems/package_task'
require 'rdoc/task' require 'rdoc/task'
#require 'rake/testtask' #require 'rake/testtask'
Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"] Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"]
#在windows上UTF-8脚本编码环境中 Dir.glob无法列出中文目录下的文件 所以自己写个递归 #在windows上UTF-8脚本编码环境中 Dir.glob无法列出中文目录下的文件 所以自己写个递归
def list(path) def list(path)
result = [] result = []
Dir.foreach(path) do |file| Dir.foreach(path) do |file|
next if file == "." or file == ".." next if file == "." or file == ".."
result << "#{path}/#{file}" result << "#{path}/#{file}"
result.concat list(result.last) if File.directory? result.last result.concat list(result.last) if File.directory? result.last
end end rescue p $!
result result
end end
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'mycard' s.name = 'mycard'
s.version = '0.7.4' s.version = '0.8.2'
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
s.author = 'zh99998' s.author = 'zh99998'
s.email = 'zh99998@gmail.com' s.email = 'zh99998@gmail.com'
s.homepage = 'http://card.touhou,cc' s.homepage = 'http://my-card.in'
# s.executables = ['your_executable_here'] # s.executables = ['your_executable_here']
s.files = %w(LICENSE.txt README.txt replay) s.files = %w(LICENSE.txt README.txt config.yml replay)
%w{lib audio data fonts graphics ygocore}.each{|dir|s.files.concat list(dir)} %w{lib audio data fonts locales graphics ygocore}.each{|dir|s.files.concat list(dir)}
if Windows if Windows
s.files += %w(mycard.exe) + list("ruby") s.files += %w(mycard.exe) + list("ruby")
else else
s.files += %w(install.sh) s.files += %w(install.sh)
end end
s.require_path = "lib" s.require_path = "lib"
#s.bindir = "bin" #s.bindir = "bin"
end end
Gem::PackageTask.new(spec) do |p| Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec p.gem_spec = spec
if Windows if Windows
p.need_zip = true p.need_zip = true
p.zip_command = '../7z.exe a' p.zip_command = '7z a'
def p.zip_file def p.zip_file
"#{package_name}-win32.7z" "#{package_name}-win32.7z"
end end
else else
p.need_tar = true p.need_tar = true
end end
end end
Rake::RDocTask.new do |rdoc| Rake::RDocTask.new do |rdoc|
files =['README.txt', 'LICENSE.txt', 'lib/**/*.rb'] files =['README.txt', 'LICENSE.txt', 'lib/**/*.rb']
rdoc.rdoc_files.add(files) rdoc.rdoc_files.add(files)
rdoc.main = "README.txt" # page to start on rdoc.main = "README.txt" # page to start on
rdoc.title = "Mycard Docs" rdoc.title = "Mycard Docs"
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
rdoc.options << '--line-numbers' rdoc.options << '--line-numbers'
end end
CLOBBER.include %w(error-程序出错请到论坛反馈.txt log.log profile.log config.yml doc ygocore/pics) + list('replay') + list('ygocore/replay') + list('.').keep_if{|file|File.basename(file) == "Thumbs.db"} + list("graphics/avatars").keep_if{|file|File.basename(file) =~ /.*_(?:small|middle|large)\.png/} + list("ygocore/deck").keep_if{|file|File.basename(file) != 'sample.ydk'} CLOBBER.include %w(error-程序出错请到论坛反馈.txt log.log profile.log config.yml doc ygocore/pics) + list('replay') + list('ygocore/replay') + list('.').keep_if{|file|File.basename(file) == "Thumbs.db"} + list("graphics/avatars").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/} + list("ygocore/deck").keep_if{|file|File.basename(file) != 'sample.ydk'}
...@@ -16,23 +16,26 @@ class Scene_Lobby < Scene ...@@ -16,23 +16,26 @@ class Scene_Lobby < Scene
require_relative 'chatmessage' require_relative 'chatmessage'
require_relative 'scene_duel' require_relative 'scene_duel'
attr_reader :chat_window attr_reader :chat_window
def start def start
WM::set_caption("MyCard v#{Update::Version} - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard") WM::set_caption("MyCard v#{Update::Version} - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard")
$game.refresh $game.refresh
@background = Graphics.load('lobby', 'background', false) @background = Graphics.load('lobby', 'background', false)
Surface.blit(@background,0,0,0,0,$screen,0,0) Surface.blit(@background, 0, 0, 0, 0, $screen, 0, 0)
@userlist = Window_UserList.new(24,204,$game.users) @userlist = Window_UserList.new(24, 204, $game.users)
@roomlist = Window_RoomList.new(320,50,$game.rooms) @roomlist = Window_RoomList.new(320, 50, $game.rooms)
@userinfo = Window_UserInfo.new(24,24, $game.user) @userinfo = Window_UserInfo.new(24, 24, $game.user)
@host_window = Window_LobbyButtons.new(678,18) @host_window = Window_LobbyButtons.new(678, 18)
@active_window = @roomlist @active_window = @roomlist
@chat_window = Window_Chat.new(313,$config['screen']['height'] - 225,698,212) @chat_window = Window_Chat.new(313, $config['screen']['height'] - 225, 698, 212)
@count = 0 @count = 0
super super
end end
def bgm def bgm
"lobby.ogg" "lobby.ogg"
end end
def handle(event) def handle(event)
case event case event
when Event::KeyDown when Event::KeyDown
...@@ -62,10 +65,12 @@ class Scene_Lobby < Scene ...@@ -62,10 +65,12 @@ class Scene_Lobby < Scene
case event case event
when Game_Event::AllUsers when Game_Event::AllUsers
@userlist.items = $game.users @userlist.items = $game.users
when Game_Event::AllRooms when Game_Event::AllRooms, Game_Event::AllServers
@roomlist.items = $game.rooms.find_all{|room|$game.filter[:servers].collect{|server|server.id}.include?(room.server_id)} @roomlist.items = $game.rooms.find_all { |room|
when Game_Event::AllServers $game.filter[:servers].collect { |server| server.id }.include?(room.server_id) and
@roomlist.items = $game.rooms.find_all{|room|$game.filter[:servers].collect{|server|server.id}.include?(room.server_id)} $game.filter[:waiting_only] ? (room.status == :wait) : true and
$game.filter[:normal_only] ? (!room.tag? && (room.ot == 0) && (room.lp = 8000)) : true
}
when Game_Event::Join when Game_Event::Join
join(event.room) join(event.room)
when Game_Event::Watch when Game_Event::Watch
...@@ -77,9 +82,11 @@ class Scene_Lobby < Scene ...@@ -77,9 +82,11 @@ class Scene_Lobby < Scene
super super
end end
end end
def join(room) def join(room)
$scene = Scene_Duel.new(room) $scene = Scene_Duel.new(room)
end end
def update def update
@chat_window.update @chat_window.update
@host_window.update @host_window.update
...@@ -91,6 +98,7 @@ class Scene_Lobby < Scene ...@@ -91,6 +98,7 @@ class Scene_Lobby < Scene
@count += 1 @count += 1
super super
end end
def terminate def terminate
unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel
$game.exit $game.exit
......
require 'open-uri' require 'open-uri'
require "fileutils" require "fileutils"
require_relative 'card' require_relative 'card'
module Update module Update
Version = '0.8.1' Version = '0.8.2'
URL = "http://my-card.in/mycard/update.json?version=#{Version}" URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self class <<self
attr_reader :thumbnails, :images, :status attr_reader :thumbnails, :images, :status
def start def start
Dir.glob("mycard-update-*-*.zip") do |file| Dir.glob("mycard-update-*-*.zip") do |file|
file =~ /mycard-update-(.+?)-(.+?)\.zip/ file =~ /mycard-update-(.+?)-(.+?)\.zip/
if $1 <= Version and $2 > Version if $1 <= Version and $2 > Version
$log.info('安装更新'){file} $log.info('安装更新'){file}
WM::set_caption("MyCard - 正在更新 #{Version} -> #{$2}", "MyCard") WM::set_caption("MyCard - 正在更新 #{Version} -> #{$2}", "MyCard")
require 'zip/zip' require 'zip/zip'
Zip::ZipFile::open(file) do |zip| Zip::ZipFile::open(file) do |zip|
zip.each do |f| zip.each do |f|
if !File.directory?(f.name) if !File.directory?(f.name)
FileUtils.mkdir_p(File.dirname(f.name)) FileUtils.mkdir_p(File.dirname(f.name))
end end
f.extract{true} f.extract{true}
end end
end rescue $log.error('安装更新出错'){file+$!.inspect+$!.backtrace.inspect} end rescue $log.error('安装更新出错'){file+$!.inspect+$!.backtrace.inspect}
Version.replace $2 Version.replace $2
File.delete file File.delete file
@updated = true @updated = true
end end
end end
if @updated if @updated
IO.popen('./mycard') IO.popen('./mycard')
$scene = nil $scene = nil
end end
@images = [] @images = []
@thumbnails = [] @thumbnails = []
@status = '正在检查更新' @status = '正在检查更新'
@updated = false @updated = false
Thread.new do Thread.new do
open(URL) do |file| open(URL) do |file|
require 'json' require 'json'
reply = file.read reply = file.read
$log.info('下载更新-服务器回传'){reply} $log.info('下载更新-服务器回传'){reply}
reply = JSON.parse(reply) reply = JSON.parse(reply)
$log.info('下载更新-解析后'){reply.inspect} $log.info('下载更新-解析后'){reply.inspect}
reply.each do |fil| reply.each do |fil|
name = File.basename fil name = File.basename fil
@status.replace "正在下载更新#{name}" @status.replace "正在下载更新#{name}"
open(fil, 'rb') do |fi| open(fil, 'rb') do |fi|
$log.info('下载完毕'){name} $log.info('下载完毕'){name}
@updated = true @updated = true
open(name, 'wb') do |f| open(name, 'wb') do |f|
f.write fi.read f.write fi.read
end end
end rescue $log.error('下载更新'){'下载更新失败'} end rescue $log.error('下载更新'){'下载更新失败'}
end end
end rescue $log.error('检查更新'){'检查更新失败'} end rescue $log.error('检查更新'){'检查更新失败'}
if @updated if @updated
require_relative 'widget_msgbox' require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定"){IO.popen('./mycard'); $scene = nil} Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定"){IO.popen('./mycard'); $scene = nil}
end end
if File.file? "ygocore/cards.cdb" if File.file? "ygocore/cards.cdb"
require 'sqlite3' require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" ) db = SQLite3::Database.new( "ygocore/cards.cdb" )
db.execute( "select id from datas" ) do |row| db.execute( "select id from datas" ) do |row|
@thumbnails << row[0] @thumbnails << row[0]
end end
@images.replace @thumbnails @images.replace @thumbnails
if !File.directory?('ygocore/pics/thumbnail') if !File.directory?('ygocore/pics/thumbnail')
FileUtils.mkdir_p('ygocore/pics/thumbnail') FileUtils.mkdir_p('ygocore/pics/thumbnail')
end end
existed_thumbnails = [] existed_thumbnails = []
Dir.foreach("ygocore/pics/thumbnail") do |file| Dir.foreach("ygocore/pics/thumbnail") do |file|
if file =~ /(\d+)\.jpg/ if file =~ /(\d+)\.jpg/
existed_thumbnails << $1.to_i existed_thumbnails << $1.to_i
end end
end end
@thumbnails -= existed_thumbnails @thumbnails -= existed_thumbnails
existed_images = [] existed_images = []
Dir.foreach("ygocore/pics") do |file| Dir.foreach("ygocore/pics") do |file|
if file =~ /(\d+)\.jpg/ if file =~ /(\d+)\.jpg/
existed_images << $1.to_i existed_images << $1.to_i
end end
end end
@images -= existed_images @images -= existed_images
existed_images = [] existed_images = []
if (!@images.empty? or !@thumbnails.empty?) and File.file?("#{Card::PicPath}/1.jpg") if (!@images.empty? or !@thumbnails.empty?) and File.file?("#{Card::PicPath}/1.jpg")
db_mycard = SQLite3::Database.new( "data/data.sqlite" ) db_mycard = SQLite3::Database.new( "data/data.sqlite" )
db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect{|number|"'%08d'" % number}.join(',')})" ) do |row| db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect{|number|"'%08d'" % number}.join(',')})" ) do |row|
id = row[0] id = row[0]
number = row[1].to_i number = row[1].to_i
src = "#{Card::PicPath}/#{id}.jpg" src = "#{Card::PicPath}/#{id}.jpg"
dest = "ygocore/pics/#{number}.jpg" dest = "ygocore/pics/#{number}.jpg"
dest_thumb = "ygocore/pics/thumbnail/#{number}.jpg" dest_thumb = "ygocore/pics/thumbnail/#{number}.jpg"
if File.file?(src) if File.file?(src)
@status.replace "检测到存在iDuel卡图 正在导入 #{id}.jpg" @status.replace "检测到存在iDuel卡图 正在导入 #{id}.jpg"
existed_images << number existed_images << number
if !File.exist?(dest) if !File.exist?(dest)
FileUtils.copy_file(src, dest) FileUtils.copy_file(src, dest)
FileUtils.copy_file(src, dest_thumb) FileUtils.copy_file(src, dest_thumb)
end end
end end
end end
end end
@images -= existed_images @images -= existed_images
@thumbnails -= existed_images @thumbnails -= existed_images
@thumbnails = (@thumbnails & @images) + (@thumbnails - @images) @thumbnails = (@thumbnails & @images) + (@thumbnails - @images)
unless @thumbnails.empty? and @images.empty? unless @thumbnails.empty? and @images.empty?
$log.info('待下载的完整卡图'){@images.inspect} $log.info('待下载的完整卡图'){@images.inspect}
$log.info('待下载的缩略卡图'){@thumbnails.inspect} $log.info('待下载的缩略卡图'){@thumbnails.inspect}
threads = 5.times.collect do threads = 5.times.collect do
thread = Thread.new do thread = Thread.new do
while number = @thumbnails.pop while number = @thumbnails.pop
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)" @status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)"
open("http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote| open("http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg" next if File.file? "ygocore/pics/thumbnail/#{number}.jpg"
#$log.debug('下载缩略卡图'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" } #$log.debug('下载缩略卡图'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local| open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local|
local.write remote.read local.write remote.read
end end
end rescue $log.error('下载缩略出错'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" } end rescue $log.error('下载缩略出错'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
end end
while number = @images.pop while number = @images.pop
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)" @status.replace "正在下载完整卡图 (剩余#{@images.size}张)"
#$log.debug('下载完整卡图'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" } #$log.debug('下载完整卡图'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
open("http://my-card.in/images/cards/ygocore/#{number}.jpg", 'rb') do |remote| open("http://my-card.in/images/cards/ygocore/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/#{number}.jpg" next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local| open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read local.write remote.read
end end
end rescue $log.error('下载完整卡图出错'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" } end rescue $log.error('下载完整卡图出错'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
end end
end end
thread.priority = -1 thread.priority = -1
thread thread
end end
threads.each{|thread|thread.join} threads.each{|thread|thread.join}
end end
end rescue $log.error('卡图更新'){'找不到ygocore卡片数据库'} end rescue $log.error('卡图更新'){'找不到ygocore卡片数据库'}
@status = nil @status = nil
end.priority = -1 end.priority = -1
end end
end end
end end
...@@ -77,7 +77,7 @@ class Ygocore < Game ...@@ -77,7 +77,7 @@ class Ygocore < Game
def connect def connect
@recv = Thread.new do @recv = Thread.new do
EventMachine::run { EventMachine::run {
EventMachine::connect "localhost", 9997, Client EventMachine::connect "mycard-server.my-card.in", 9997, Client
} }
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