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