Commit 17ae1837 authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.8.1

parent 1e26242c
......@@ -9,6 +9,9 @@ module Config
config['bgm'] = true if config['bgm'].nil?
config['screen'] ||= {}
config['screen']['width'], config['screen']['height'] = Resolution.default unless Resolution.all.include? [config['screen']['width'], config['screen']['height']]
config['i18n'] ||= {}
config['i18n']['locale'] ||= "#{Locale.current.language}-#{Locale.current.region}"
I18n.locale = config['i18n']['locale']
config
end
def save(config=$config, file="config.yml")
......
#游戏事件的抽象类
class Game_Event
@queue = []
def self.push(event)
@queue << event
end
def self.poll
@queue.shift
end
def self.parse(info, *args)
#适配器定义
end
......@@ -14,6 +17,7 @@ class Game_Event
class Login < Game_Event
attr_reader :user
def initialize(user)
@user = user
$game.user = @user
......@@ -22,6 +26,7 @@ class Game_Event
class AllUsers < Game_Event
attr_reader :users
def initialize(users)
@users = []
users.each do |user|
......@@ -37,6 +42,7 @@ class Game_Event
class NewUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
unless $game.users.include? @user
......@@ -51,6 +57,7 @@ class Game_Event
class MissingUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
$game.users.delete @user
......@@ -59,14 +66,27 @@ class Game_Event
class AllRooms < Game_Event
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace @rooms
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end
end
class RoomsUpdate < AllRooms
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace $game.rooms | @rooms
$game.rooms.delete_if { |room| room._deleted }
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end
end
class NewRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
unless $game.rooms.include? @room
......@@ -80,6 +100,7 @@ class Game_Event
end
class MissingRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
$game.rooms.delete @room
......@@ -87,9 +108,9 @@ class Game_Event
end
class Chat < Game_Event
attr_reader :chatmessage
def initialize(chatmessage)
@chatmessage = chatmessage
end
......@@ -97,6 +118,7 @@ class Game_Event
class Join < Game_Event
attr_reader :room
def initialize(room)
@room = room
$game.room = @room
......@@ -106,6 +128,7 @@ class Game_Event
end
class Watch < Game_Event
attr_reader :room
def initialize(room)
@room = room
$game.room = @room
......@@ -117,6 +140,7 @@ class Game_Event
end
class PlayerJoin < Game_Event
attr_reader :user
def initialize(user)
@user = user
$game.room.player2 = @user
......@@ -130,6 +154,7 @@ class Game_Event
class Action < Game_Event
attr_reader :action, :str
def initialize(action, str=action.escape)
@action = action
@str = str
......@@ -139,11 +164,12 @@ class Game_Event
class Error < Game_Event
attr_reader :title, :message, :fatal
def initialize(title, message, fatal=true)
@title = title
@message = message
@fatal = fatal
$log.error(@fatal ? "致命错误" : "一般错误"){"#{@title}: #{@message} #{caller}"}
$log.error(@fatal ? "致命错误" : "一般错误") { "#{@title}: #{@message} #{caller}" }
end
end
class Unknown < Error
......
......@@ -21,12 +21,12 @@ class User
end
def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif")
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene
if block_given?
yield result
Thread.new do
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/noavatar_#{size}.gif"
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png"
(yield Surface.load(cache) if scene == $scene) rescue nil
end
else
......
......@@ -2,6 +2,7 @@
begin
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
Dir.glob('post_update_*.rb').sort.each { |file| load file }
Thread.abort_on_exception = true
require_relative 'resolution'
......@@ -9,6 +10,12 @@ begin
require_relative 'config'
require_relative 'association'
#i18n
require 'i18n'
require 'locale'
I18n.load_path += Dir['locales/*.yml']
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
#读取配置文件
$config = Config.load
Config.save
......
......@@ -49,7 +49,9 @@ case file
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
room = Room.new(0, $5)
room.server_ip = $3
room.server_port = $4.to_i
room.server_auth = true if $2
Ygocore.run_ygocore room, true
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ require_relative 'cacheable'
class Room
Color = [[0,0,0], [255,0,0], [0,128,0], [0,0,255], [255, 165, 0]]
extend Cacheable
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid, :_deleted
attr_accessor :password
def initialize(id, name="等待更新", player1=nil, player2=nil, private=false, color=[0,0,0], session = nil, forbid = nil)
@id = id
......@@ -30,6 +30,9 @@ class Room
def extra
{}
end
def status
player2 ? :start : :wait
end
alias full? player2
alias private? private
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.7.4'
Version = '0.8.1'
URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
......
......@@ -4,7 +4,7 @@ class Widget_Msgbox < Window
class <<self
alias old_new new
def new(title, message, buttons={}, &proc)
if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?}
if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?} rescue nil
instance.set(title, message, buttons, &proc)
instance
else
......
......@@ -2,6 +2,7 @@ class Window
WLH = 24
attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background
alias visible? visible
def initialize(x, y, width, height, z=200)
@x = x
@y = y
......@@ -27,66 +28,85 @@ class Window
end == true
$scene.windows << self
end
end
def center_margin(text, width, font=@font)
(width - font.text_size(text)[0]) /2
end
def draw_stroked_text(text,x,y,size=1,font=@font,color=@color,color_stroke=@color_stroke)
[[x-size,y-size], [x-size,y], [x-size,y+size],
[x,y-size], [x,y+size],
[x+size,y-size], [x+size,y], [x+size,y+size],
].each{|pos|font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color)}
def draw_stroked_text(text, x, y, size=1, font=@font, color=@color, color_stroke=@color_stroke)
[[x-size, y-size], [x-size, y], [x-size, y+size],
[x, y-size], [x, y+size],
[x+size, y-size], [x+size, y], [x+size, y+size],
].each { |pos| font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color) }
font.draw_blended_utf8(@contents, text, x, y, *color_stroke)
end
def include?(x,y)
def include?(x, y)
x >= @x && x < @x + @width && y >= @y && y < @y + @height
end
def destroy
@destroyed = true
@contents.destroy if @contents
$scene.windows.delete self if $scene
end
def destroyed?
@destroyed
end
def draw(screen)
return unless self.contents && self.visible? && !self.destroyed?
Surface.blit(self.contents, *self.viewport, screen, self.x, self.y)
end
def clear(x=0, y=0, width=@width, height=@height)
if @background
Surface.blit(@background,x,y,width,height,@contents,x,y)
Surface.blit(@background, x, y, width, height, @contents, x, y)
elsif $scene and $scene.background
Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y)
Surface.blit($scene.background, @x+x, @y+y, width, height, @contents, x, y)
else
@contents.fill_rect(x,y,width,height,0xFF000000)
@contents.fill_rect(x, y, width, height, 0xFF000000)
end
end
def update
#子类定义
end
def refresh
#子类定义
end
def mousemoved(x,y)
def mousemoved(x, y)
#子类定义
end
def clicked
#子类定义
end
def mouseleftbuttonup
#子类定义
end
def lostfocus(active_window=nil)
#子类定义
end
def cursor_up(wrap=false)
#子类定义
end
def cursor_down(wrap=false)
#子类定义
end
def scroll_up
cursor_up
end
def scroll_down
cursor_down
end
......
......@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
if !@chat_input.value.empty?
chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel)
$game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage) if $game.show_chat_self
Game_Event.push Game_Event::Chat.new(chatmessage)# if $game.show_chat_self
true
end
end
......
......@@ -42,7 +42,7 @@ class Window_Config < Window
when :avatar_cache
size = 0
count = 0
Dir.glob("graphics/avatars/*_*.png") do |file|
Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
count += 1
size += File.size(file)
end
......@@ -105,7 +105,7 @@ class Window_Config < Window
draw_item(@index, 1)
when :avatar_cache
#clear(*item_rect(@index))
Dir.glob("graphics/avatars/*_*.png") do |file|
Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
File.delete file
end
refresh
......
require_relative 'window_host'
class Window_LobbyButtons < Window_List
def initialize(x, y)
@items = ["常见问题", "卡组编辑", "建立房间"]
@items = [I18n.t('lobby.faq'), I18n.t('lobby.editdeck'), I18n.t('lobby.newroom')]
@button = Surface.load("graphics/lobby/button.png")
super(x, y, @items.size*@button.w/3+@items.size*4, 30)
@font = TTF.open("fonts/wqy-microhei.ttc", 15)
......@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List
end
def draw_item(index, status=0)
x, y=item_rect(index)
x, y, width=item_rect(index)
Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y)
draw_stroked_text(@items[index], x+8, y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59])
draw_stroked_text(@items[index], x+center_margin(@items[index],width,@font), y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59])
end
def item_rect(index)
......
......@@ -45,23 +45,23 @@ class Window_Login < Window
:replay => [378,200,@button.w/3,@button.h]
}
@items_text = {
:login => "登录",
:register => "注册",
:replay => "录像"
:login => I18n.t("login.login"),
:register => I18n.t("login.register"),
:replay => I18n.t("login.replay"),
}
#self.index = nil
@remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,"记住密码")
@remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,I18n.t('login.remember'))
refresh
end
def refresh
clear
@items.each_pair{|index, rect|draw_item(index, rect)}
draw_stroked_text("用户名", 105,80+2,1)
draw_stroked_text("密码", 105,125+2,1)
draw_stroked_text(I18n.t('login.name'), 105,80+2,1)
draw_stroked_text(I18n.t('login.password'), 105,125+2,1)
end
def draw_item(index, rect, status=0)
Surface.blit(@button,rect[2]*status,0,rect[2],rect[3],@contents,rect[0],rect[1])
draw_stroked_text(@items_text[index], rect[0]+24, rect[1]+9,1,@font_button)
draw_stroked_text(@items_text[index], rect[0] + center_margin(@items_text[index], rect[2], @font_button), rect[1]+9,1,@font_button)
end
def mousemoved(x,y)
self.index = @items.each_pair{|index, rect|break index if (x-@x >= rect[0] and x-@x < rect[0]+rect[2] and y-@y >= rect[1] and y-@y < rect[1]+rect[3])}
......
......@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable
y = item_rect(index)[1]
room = @items[index]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color) unless room.id.to_s.empty?
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
$log.error('标题过长') {room.name} if room.name.size > 100
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.nil? or room.name.empty? or room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty?
@font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty?
room.extra.each_with_index do |extra, index|
......
......@@ -7,20 +7,10 @@ class Game_Event
else
Error.new('登录', '用户名或密码错误')
end
#when :users
# AllUsers.new data.collect{|user|parse_user(user)}
when :rooms
rooms_wait = []
rooms_start = []
data.each do |room|
room = parse_room(room)
if room.full?
rooms_start << room
else
rooms_wait << room
end
end
AllRooms.new rooms_wait + rooms_start
AllRooms.new data.collect{|room|parse_room(room)}
when :rooms_update
RoomsUpdate.new data.collect{|room|parse_room(room)}
#when :newuser
#NewUser.new parse_user data
#when :missinguser
......@@ -29,13 +19,13 @@ class Game_Event
NewRoom.new parse_room data
when :missingroom
MissingRoom.new parse_room data
#when :chat
# case data[:channel]
# when :lobby
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
# else
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
# end
when :chat
case data[:channel]
when :lobby
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
else
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
end
end
end
def self.parse_room(room)
......@@ -49,6 +39,11 @@ class Game_Event
result.ot = room[:ot]
result.status = room[:status]
result.lp = room[:lp]
result._deleted = room[:_deleted]
result.server_id = room[:server_id]
result.server_ip = room[:server_ip]
result.server_port = room[:server_port]
result.server_auth = room[:server_auth]
result
end
def self.parse_user(user)
......
This diff is collapsed.
......@@ -5,6 +5,7 @@ class Room
attr_accessor :ot
attr_accessor :lp
attr_accessor :status
attr_accessor :server_id, :server_ip, :server_port, :server_auth
alias pvp? pvp
alias match? match
alias tag? tag
......
register: http://my-card.in/register
api: http://122.0.65.71:7922/
api: http://master.smdcn.net:7922/
index: http://my-card.in/
server: 122.0.65.71
server: 122.0.65.70
port: 7911
\ No newline at end of file
......@@ -22,13 +22,13 @@ class User
end
def avatar(size = :small)
cache = "graphics/avatars/mycard_#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif")
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene
if block_given?
yield result
Thread.new do
require 'cgi'
open("http://my-card.in/users/#{CGI.escape @id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/noavatar_#{size}.gif"
open("http://my-card.in/users/#{CGI.escape @id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png"
(yield Surface.load(cache) if scene == $scene) rescue nil
end
else
......
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