Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
mycard
Commits
5a87a77c
Commit
5a87a77c
authored
Jun 03, 2012
by
zh99998
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.6.6 URL protocol
parent
709a9dbb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
225 additions
and
237 deletions
+225
-237
.gitignore
.gitignore
+1
-0
Rakefile
Rakefile
+64
-68
lib/main.rb
lib/main.rb
+126
-129
lib/quickstart.rb
lib/quickstart.rb
+33
-39
lib/update.rb
lib/update.rb
+1
-1
No files found.
.gitignore
View file @
5a87a77c
/nbproject/
/nbproject/
/.idea/
/ruby/
/ruby/
/pkg/
/pkg/
/config.yml
/config.yml
...
...
Rakefile
View file @
5a87a77c
#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"
]
if
Windows
#在windows上UTF-8脚本编码环境中 Dir.glob无法列出中文目录下的文件 所以自己写个递归
STDOUT
.
set_encoding
"GBK"
,
"UTF-8"
def
list
(
path
)
STDERR
.
set_encoding
"GBK"
,
"UTF-8"
result
=
[]
end
Dir
.
foreach
(
path
)
do
|
file
|
#在windows上UTF-8脚本编码环境中 Dir.glob无法列出中文目录下的文件 所以自己写个递归
next
if
file
==
"."
or
file
==
".."
def
list
(
path
)
result
<<
"
#{
path
}
/
#{
file
}
"
result
=
[]
result
.
concat
list
(
result
.
last
)
if
File
.
directory?
result
.
last
Dir
.
foreach
(
path
)
do
|
file
|
end
next
if
file
==
"."
or
file
==
".."
result
result
<<
"
#{
path
}
/
#{
file
}
"
end
result
.
concat
list
(
result
.
last
)
if
File
.
directory?
result
.
last
end
spec
=
Gem
::
Specification
.
new
do
|
s
|
result
s
.
name
=
'mycard'
end
s
.
version
=
'0.6.6'
s
.
extra_rdoc_files
=
[
'README.txt'
,
'LICENSE.txt'
]
spec
=
Gem
::
Specification
.
new
do
|
s
|
s
.
summary
=
'a card game'
s
.
name
=
'mycard'
s
.
description
=
s
.
summary
s
.
version
=
'0.6.4'
s
.
author
=
'zh99998'
s
.
extra_rdoc_files
=
[
'README.txt'
,
'LICENSE.txt'
]
s
.
email
=
'zh99998@gmail.com'
s
.
summary
=
'a card game'
s
.
homepage
=
'http://card.touhou,cc'
s
.
description
=
s
.
summary
# s.executables = ['your_executable_here']
s
.
author
=
'zh99998'
s
.
files
=
%w(LICENSE.txt README.txt replay)
s
.
email
=
'zh99998@gmail.com'
%w{lib audio data fonts graphics ygocore}
.
each
{
|
dir
|
s
.
files
.
concat
list
(
dir
)}
s
.
homepage
=
'http://card.touhou,cc'
if
Windows
# s.executables = ['your_executable_here']
s
.
files
+=
%w(mycard.exe)
+
list
(
"ruby"
)
s
.
files
=
%w(LICENSE.txt README.txt replay)
else
%w{lib audio data fonts graphics ygocore}
.
each
{
|
dir
|
s
.
files
.
concat
list
(
dir
)}
s
.
files
+=
%w(install.sh)
if
Windows
end
s
.
files
+=
%w(mycard.exe)
+
list
(
"ruby"
)
s
.
require_path
=
"lib"
else
#s.bindir = "bin"
s
.
files
+=
%w(install.sh)
end
end
s
.
require_path
=
"lib"
Gem
::
PackageTask
.
new
(
spec
)
do
|
p
|
#s.bindir = "bin"
p
.
gem_spec
=
spec
end
if
Windows
p
.
need_zip
=
true
Gem
::
PackageTask
.
new
(
spec
)
do
|
p
|
p
.
zip_command
=
'../7z.exe a'
p
.
gem_spec
=
spec
def
p
.
zip_file
if
Windows
"
#{
package_name
}
-win32.7z"
p
.
need_zip
=
true
end
p
.
zip_command
=
'../7z.exe a'
else
def
p
.
zip_file
p
.
need_tar
=
true
"
#{
package_name
}
-win32.7z"
end
end
end
else
p
.
need_tar
=
true
Rake
::
RDocTask
.
new
do
|
rdoc
|
end
files
=
[
'README.txt'
,
'LICENSE.txt'
,
'lib/**/*.rb'
]
end
rdoc
.
rdoc_files
.
add
(
files
)
rdoc
.
main
=
"README.txt"
# page to start on
Rake
::
RDocTask
.
new
do
|
rdoc
|
rdoc
.
title
=
"Mycard Docs"
files
=
[
'README.txt'
,
'LICENSE.txt'
,
'lib/**/*.rb'
]
rdoc
.
rdoc_dir
=
'doc/rdoc'
# rdoc output folder
rdoc
.
rdoc_files
.
add
(
files
)
rdoc
.
options
<<
'--line-numbers'
rdoc
.
main
=
"README.txt"
# page to start on
end
rdoc
.
title
=
"Mycard Docs"
rdoc
.
rdoc_dir
=
'doc/rdoc'
# rdoc output folder
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'
}
rdoc
.
options
<<
'--line-numbers'
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'
}
lib/main.rb
View file @
5a87a77c
#!/usr/bin/env ruby
#!/usr/bin/env ruby
p
ARGV
begin
STDIN
.
gets
#定义全局方法
begin
def
load_config
(
file
=
"config.yml"
)
#定义全局方法
require
'yaml'
def
load_config
(
file
=
"config.yml"
)
$config
=
YAML
.
load_file
(
"config.yml"
)
rescue
{}
require
'yaml'
$config
=
{}
unless
$config
.
is_a?
Hash
$config
=
YAML
.
load_file
(
"config.yml"
)
rescue
{}
$config
[
'bgm'
]
=
true
if
$config
[
'bgm'
].
nil?
$config
=
{}
unless
$config
.
is_a?
Hash
$config
[
'screen'
]
||=
{}
$config
[
'bgm'
]
=
true
if
$config
[
'bgm'
].
nil?
$config
[
'screen'
][
'width'
]
||=
1024
$config
[
'screen'
]
||=
{}
$config
[
'screen'
][
'height'
]
||=
768
$config
[
'screen'
][
'width'
]
||=
1024
end
$config
[
'screen'
][
'height'
]
||=
768
def
save_config
(
file
=
"config.yml"
)
end
File
.
open
(
file
,
"w"
){
|
file
|
YAML
.
dump
(
$config
,
file
)}
def
save_config
(
file
=
"config.yml"
)
end
File
.
open
(
file
,
"w"
){
|
file
|
YAML
.
dump
(
$config
,
file
)}
def
register_url_protocol
end
if
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
def
register_url_protocol
require
'win32/registry'
if
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
pwd
=
Dir
.
pwd
.
gsub
(
'/'
,
'\\'
)
require
'win32/registry'
path
=
'"'
+
pwd
+
'\ruby\bin\rubyw.exe" -C"'
+
pwd
+
'" -KU lib/main.rb'
pwd
=
Dir
.
pwd
.
gsub
(
'/'
,
'\\'
)
command
=
path
+
' "%1"'
path
=
'"'
+
pwd
+
'\ruby\bin\ruby.exe" -C"'
+
pwd
+
'" -KU lib/main.rb'
path
.
replace
path
.
ljust
path
.
bytesize
command
=
path
+
' "%1"'
command
.
replace
command
.
ljust
command
.
bytesize
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'
){
|
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
)}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard\shell\open\command'
){
|
reg
|
reg
[
nil
]
=
command
unless
(
reg
[
nil
]
==
command
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
|
p
arg
case
arg
.
dup
.
force_encoding
(
"UTF-8"
)
STDIN
.
gets
when
/--log=(.*)/
case
arg
.
dup
.
force_encoding
(
"UTF-8"
)
log
.
replace
$1
when
/--log=(.*)/
when
/--log-level=(.*)/
log
.
replace
$1
log_level
.
replace
$1
when
/--log-level=(.*)/
when
/--profile=(.*)/
log_level
.
replace
$1
profile
=
$1
when
/--profile=(.*)/
when
/mycard:.*/
profile
=
$1
require_relative
'quickstart'
when
/mycard:.*/
$scene
=
false
require_relative
'quickstart'
when
/register_web_protocol/
$scene
=
false
register_url_protocol
when
/register_web_protocol/
$scene
=
false
register_url_protocol
end
$scene
=
false
end
end
unless
$scene
==
false
end
#初始化SDL
unless
$scene
==
false
require
'sdl'
#初始化SDL
include
SDL
require
'sdl'
SDL
::
Event
::
APPMOUSEFOCUS
=
1
include
SDL
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPACTIVE
=
4
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
::
Event
::
APPACTIVE
=
4
SDL
.
init
(
INIT_VIDEO
|
INIT_AUDIO
)
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
SDL
.
init
(
INIT_VIDEO
|
INIT_AUDIO
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1024
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
Mixer
.
set_volume_music
(
60
)
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1024
)
TTF
.
init
Mixer
.
set_volume_music
(
60
)
Thread
.
abort_on_exception
=
true
TTF
.
init
Thread
.
abort_on_exception
=
true
#初始化日志
require
'logger'
#初始化日志
if
log
==
"STDOUT"
#调试用
require
'logger'
log
=
STDOUT
if
log
==
"STDOUT"
#调试用
end
log
=
STDOUT
$log
=
Logger
.
new
(
log
)
STDOUT
.
set_encoding
"GBK"
,
"UTF-8"
,
:invalid
=>
:replace
,
:undef
=>
:replace
if
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
$log
.
level
=
Logger
.
const_get
log_level
end
#性能分析
$log
=
Logger
.
new
(
log
)
if
profile
$log
.
level
=
Logger
.
const_get
log_level
if
profile
==
"STDOUT"
#性能分析
profile
=
STDOUT
if
profile
else
if
profile
==
"STDOUT"
profile
=
open
(
profile
,
'w'
)
profile
=
STDOUT
end
else
require
'profiler'
profile
=
open
(
profile
,
'w'
)
RubyVM
::
InstructionSequence
.
compile_option
=
{
end
:trace_instruction
=>
true
,
require
'profiler'
:specialized_instruction
=>
false
RubyVM
::
InstructionSequence
.
compile_option
=
{
}
:trace_instruction
=>
true
,
Profiler__
::
start_profile
:specialized_instruction
=>
false
end
}
Profiler__
::
start_profile
end
#初始化标题场景
require_relative
'scene_title'
$scene
=
Scene_Title
.
new
#初始化标题场景
require_relative
'scene_title'
#自动更新
$scene
=
Scene_Title
.
new
require_relative
'update'
Update
.
start
#自动更新
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
require_relative
'update'
require_relative
'dialog'
Update
.
start
register_url_protocol
rescue
Dialog
.
uac
(
"ruby/bin/rubyw.exe"
,
"-KU lib/main.rb register_web_protocol"
)
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
$log
.
info
(
"main"
){
"初始化成功"
}
require_relative
'dialog'
end
register_url_protocol
rescue
Dialog
.
uac
(
"ruby/bin/rubyw.exe"
,
"-KU lib/main.rb register_web_protocol"
)
rescue
Exception
=>
exception
$log
.
info
(
"main"
){
"初始化成功"
}
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
){
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)}
end
$scene
=
false
rescue
Exception
=>
exception
end
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
){
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)}
$scene
=
false
#主循环
end
begin
$scene
.
main
while
$scene
#主循环
rescue
Exception
=>
exception
begin
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$scene
.
main
while
$scene
$log
.
fatal
(
$1
){[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)}.
join
(
"
\n
"
)}
rescue
Exception
=>
exception
$game
.
exit
if
$game
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
require_relative
'scene_error'
$log
.
fatal
(
$1
){[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)}.
join
(
"
\n
"
)}
$scene
=
Scene_Error
.
new
$game
.
exit
if
$game
retry
require_relative
'scene_error'
ensure
$scene
=
Scene_Error
.
new
if
profile
retry
Profiler__
::
print_profile
(
profile
)
ensure
profile
.
close
if
profile
end
Profiler__
::
print_profile
(
profile
)
$log
.
close
rescue
nil
profile
.
close
end
$log
.
close
rescue
nil
end
end
\ No newline at end of file
lib/quickstart.rb
View file @
5a87a77c
require_relative
'game'
require_relative
'game'
require_relative
'user'
require_relative
'user'
require_relative
'room'
require_relative
'room'
require_relative
'ygocore/game'
require_relative
'ygocore/game'
$game
=
Ygocore
.
new
$game
=
Ygocore
.
new
p
1
uri
=
URI
.
unescape
URI
.
unescape
ARGV
.
first
[
9
,
ARGV
.
first
.
size
-
9
]
STDIN
.
gets
case
uri
uri
=
URI
.
unescape
URI
.
unescape
ARGV
.
first
[
9
,
ARGV
.
first
.
size
-
9
]
when
/^(.*\.yrp)$/
p
uri
require
'open-uri'
STDIN
.
gets
open
(
"http://"
+
URI
.
escape
(
$1
),
'rb'
)
{
|
src
|
case
uri
Dir
.
mkdir
(
"replay"
)
unless
File
.
directory?
(
"replay"
)
when
/^(.*\.yrp)$/
open
(
'replay/'
+
File
.
basename
(
$1
),
'wb'
){
|
dest
|
require
'open-uri'
dest
.
write
src
.
read
open
(
"http://"
+
URI
.
escape
(
$1
),
'rb'
)
{
|
src
|
}
Dir
.
mkdir
(
"replay"
)
unless
File
.
directory?
(
"replay"
)
}
open
(
'replay/'
+
File
.
basename
(
$1
),
'wb'
){
|
dest
|
Ygocore
.
replay
(
'replay/'
+
File
.
basename
(
$1
),
true
)
dest
.
write
src
.
read
when
/^(.*\.ydk)$/
}
require
'open-uri'
}
open
(
"http://"
+
URI
.
escape
(
$1
),
'rb'
)
{
|
src
|
Ygocore
.
replay
(
'replay/'
+
File
.
basename
(
$1
),
true
)
Dir
.
mkdir
(
'ygocore/deck'
)
unless
File
.
directory?
(
"ygocore/deck"
)
when
/^(.*\.ydk)$/
open
(
'ygocore/deck/'
+
File
.
basename
(
$1
),
'wb'
){
|
dest
|
require
'open-uri'
dest
.
write
src
.
read
open
(
"http://"
+
URI
.
escape
(
$1
),
'rb'
)
{
|
src
|
}
Dir
.
mkdir
(
'ygocore/deck'
)
unless
File
.
directory?
(
"ygocore/deck"
)
}
open
(
'ygocore/deck/'
+
File
.
basename
(
$1
),
'wb'
){
|
dest
|
Ygocore
.
run_ygocore
(
File
.
basename
(
$1
,
'.ydk'
),
true
)
dest
.
write
src
.
read
when
/^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/
}
require
'uri'
}
$game
.
user
=
User
.
new
(
$1
.
to_sym
,
$1
)
if
$1
Ygocore
.
run_ygocore
(
File
.
basename
(
$1
,
'.ydk'
),
true
)
$game
.
password
=
$2
if
$2
when
/^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/
$game
.
server
=
$3
p
$1
$game
.
port
=
$4
.
to_i
STDIN
.
gets
Ygocore
.
run_ygocore
Room
.
new
(
0
,
$5
),
true
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
lib/update.rb
View file @
5a87a77c
...
@@ -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.
4
'
Version
=
'0.6.
6
'
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment