Commit 39954c1f authored by Peter Xin's avatar Peter Xin

Add language split

Git fix
GameCode Fix
SQL fix fix
parent 4131a978
......@@ -4,4 +4,5 @@ MagicSetEditor
ygopro-images/*
ygopro-images-raw/*.jpg
*.mse-set
*.log
\ No newline at end of file
*.log
*.cdb
\ No newline at end of file
......@@ -16,26 +16,37 @@ module Commands
end
def generate_all
Log.logger.info "Generate all the card images."
Log.logger.info "Generate all the card images with language #{Global.language}."
self.clear_mse
data = Sqlite.split Sqlite.load
MSETranslator.generate_mse_all(data)
MSETranslator.export_mse_all
end
def generate_delta
def generate_delta(languages = nil)
Log.logger.info "Generate delta card image(s)"
self.clear_mse
data = Sqlite.load
changes = HashJudger.compare data
generates = changes[0] + changes[2]
removes = changes[1]
data = Sqlite.split generates
if languages == nil
process(removes, data)
else
for language in languages
Global.language = language
process(removes, data)
end
end
end
def process(removes, data)
for card in removes
id = YGOCoreJudgers.get_id card
path = Global.full_image_name id
path = File.join Global.full_answer_path, id.to_s + Global.image_type
File.delete path if File.exist? path
end
data = Sqlite.split generates
MSETranslator.generate_mse_all(data)
MSETranslator.export_mse_all
end
......@@ -51,4 +62,11 @@ module Commands
Log.logger.info "Clearing MSE Path"
Dir.glob("#{Global.mse_set_path}/*.mse-set") {|set| File.delete set}
end
def get_languages
names = Dir.glob("#{Global.full_image_path}/cards-*.cdb")
languages = names.map {|name| File.basename(name)}.map {|name| name[6, name.length - 10]}
languages
end
end
\ No newline at end of file
......@@ -6,14 +6,14 @@ module Git
module_function
def pull
return `cd #{global.git_path} && git pull`
return `cd #{Global.git_path} && git pull`
end
def push
return `cd #{global.answer_path} && git push`
return `cd #{Global.answer_path} && git push`
end
def commit(message = "")
return `cd #{global.answer_path} && git add . && git commit -a -m \"Update card images\"`
return `cd #{Global.answer_path} && git add . && git commit -a -m \"Update card images\"`
end
end
\ No newline at end of file
......@@ -6,6 +6,7 @@ module Global
attr_accessor :git_path
attr_accessor :git_uri
attr_accessor :database_name
attr_accessor :temp_database_name
attr_accessor :image_type
attr_accessor :records_name
attr_accessor :answer_path
......@@ -18,9 +19,10 @@ module Global
self.git_path = 'ygopro-images-raw'
self.git_uri = 'https://github.com/mycard/ygopro-images-raw.git'
self.database_name = 'cards-%s.cdb'
self.temp_database_name = "working-cards.cdb"
self.image_type = '.jpg'
self.records_name = "records.json"
self.answer_path = "ygopro-images"
self.answer_path = "ygopro-images-%s"
self.answer_uri = "https://github.com/mycard/ygo-images.git"
self.mse_path = "MagicSetEditor2"
self.sql_fix_name = "fix.sql"
......@@ -35,7 +37,12 @@ module Global
end
def full_answer_path
return self.answer_path
name = sprintf(self.answer_path, self.language)
unless Dir.exist? name
File.delete name if !(File.directory? name) and File.exist? name
Dir.mkdir name
end
return name
end
def full_image_name(id)
......@@ -46,4 +53,7 @@ module Global
def full_mse_path
return File.join self.mse_path, 'mse.com'
end
end
\ No newline at end of file
end
# 建立 mse-sets 文件夹
Dir.mkdir Global.mse_set_path unless File.directory? Global.mse_set_path
\ No newline at end of file
......@@ -48,7 +48,7 @@ module MSETranslator
end
file.write self.generate_line MSEConstants::MSETags::TagAtk, YGOCoreJudgers.get_attack(card)
file.write self.generate_line MSEConstants::MSETags::TagDef, YGOCoreJudgers.get_defense(card)
file.write self.generate_line MSEConstants::MSETags::TagCode, YGOCoreJudgers.get_id_str(card)
file.write self.generate_line MSEConstants::MSETags::TagCode, YGOCoreJudgers.get_id(card).to_s
end
def write_spell(file, card)
......@@ -59,7 +59,7 @@ module MSETranslator
file.write self.generate_line MSEConstants::MSETags::TagLevel, YGOCoreJudgers.get_level_str(card)
file.write self.generate_line MSEConstants::MSETags::TagImage, YGOCoreJudgers.get_image_str(card)
file.write self.generate_text MSEConstants::MSETags::TagText, YGOCoreJudgers.get_desc(card)
file.write self.generate_line MSEConstants::MSETags::TagCode, YGOCoreJudgers.get_id_str(card)
file.write self.generate_line MSEConstants::MSETags::TagCode, YGOCoreJudgers.get_id(card).to_s
end
LineHead = "\t"#" "
......
......@@ -10,7 +10,7 @@ end
post '/hook' do
Git.pull
Commands.generate_delta
Commands.generate_delta(Commands.get_languages)
Git.commit
Git.push
end
require 'sqlite3'
require 'fileutils'
require File.dirname(__FILE__) + '/Git.rb'
require File.dirname(__FILE__) + '/Global.rb'
require File.dirname(__FILE__) + '/Log.rb'
......@@ -6,8 +7,15 @@ require File.dirname(__FILE__) + '/MSEConstants.rb'
module Sqlite
def self.load(id = -1)
path = Global.full_database_path
if File.exist? path
FileUtils.cp path, Global.temp_database_name
else
Log.logger.error "No sql databse named #{path}"
return nil
end
begin
db = SQLite3::Database.new Global.full_database_path
db = SQLite3::Database.new Global.temp_database_name
self.run_fix(db)
command = "select * from datas join texts on datas.id == texts.id"
command += " where datas.id == #{id}" if id > 0
......
......@@ -13,7 +13,7 @@ def unit_test2
require './Sqlite.rb'
Global.language = 'jp'
data = Sqlite.split Sqlite.load
data = [data[12]]
data = [data[1]]
require './MSETranslator.rb'
MSETranslator.generate_mse_all(data)
end
......@@ -23,5 +23,10 @@ def unit_test3
MSETranslator.export_mse_all
end
unit_test2
unit_test3
\ No newline at end of file
def unit_test_god
require './Commands.rb'
Global.language = 'jp'
Commands.generate_single(10000040)
end
unit_test_god
\ No newline at end of file
......@@ -75,4 +75,5 @@ module YGOCoreConstants
PendulumLeftMod = 65536
PendulumRightMod = 16777216
QuestionMark = -2
end
......@@ -155,11 +155,15 @@ module YGOCoreJudgers
end
def get_attack(card)
return card[ColumnAtk].to_i
value = card[ColumnAtk].to_i
return "?" if value == YGOCoreConstants::QuestionMark
value
end
def get_defense(card)
return card[ColumnDef].to_i
value = card[ColumnDef].to_i
return "?" if value == YGOCoreConstants::QuestionMark
value
end
def get_level(card)
......
This diff is collapsed.
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