mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 15:31:51 +08:00
Moved categories to its own object instead of allstrings and adjusted code in the other files in order to maintain multilangual support
This commit is contained in:
parent
dca4948548
commit
f66ef6417f
@ -151,7 +151,7 @@ var assets = {
|
|||||||
"sounds": {},
|
"sounds": {},
|
||||||
"image": {},
|
"image": {},
|
||||||
"pages": {},
|
"pages": {},
|
||||||
"categories": {}
|
"categories": []
|
||||||
}
|
}
|
||||||
|
|
||||||
var gameConfig = {}
|
var gameConfig = {}
|
||||||
|
@ -105,13 +105,18 @@ class Loader{
|
|||||||
}), url)
|
}), url)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.addPromise(this.ajax("/api/categories").then(categories => {
|
this.addPromise(this.ajax("/api/categories").then(cats => {
|
||||||
assets.categories = JSON.parse(categories)
|
let jsonCategories = JSON.parse(cats)
|
||||||
assets.categories.forEach(cat => {
|
|
||||||
|
for (var i in jsonCategories) { //rename the song_skin property and add category title to categories array
|
||||||
|
let cat = jsonCategories[i]
|
||||||
|
cat.songSkin = cat.song_Skin
|
||||||
|
delete cat.song_Skin
|
||||||
|
assets.categories.push(cat)
|
||||||
let title = cat.title
|
let title = cat.title
|
||||||
translations.categories[title] = cat.title_lang
|
categories[title] = cat.title_lang
|
||||||
});
|
}
|
||||||
separateStrings() //load categories into strings.js to handle multi language
|
|
||||||
assets.categories.push({
|
assets.categories.push({
|
||||||
title: "default",
|
title: "default",
|
||||||
songSkin: {
|
songSkin: {
|
||||||
@ -145,6 +150,7 @@ class Loader{
|
|||||||
if(this.error){
|
if(this.error){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
separateStrings() //iterate over strings and apply translations where required
|
||||||
|
|
||||||
assets.categories //load category backgrounds to DOM
|
assets.categories //load category backgrounds to DOM
|
||||||
.filter(cat=>cat.songSkin && cat.songSkin.bg_img)
|
.filter(cat=>cat.songSkin && cat.songSkin.bg_img)
|
||||||
|
@ -145,12 +145,9 @@ class Settings{
|
|||||||
}
|
}
|
||||||
return this.allLanguages[0]
|
return this.allLanguages[0]
|
||||||
}
|
}
|
||||||
setLang(lang, noEvent){
|
setLang(lang, noEvent, stringRepo){
|
||||||
strings = lang
|
stringRepo = lang
|
||||||
var boldFonts = strings.font === "Microsoft YaHei, sans-serif"
|
|
||||||
loader.screen.style.fontFamily = strings.font
|
|
||||||
loader.screen.style.fontWeight = boldFonts ? "bold" : ""
|
|
||||||
loader.screen.classList[boldFonts ? "add" : "remove"]("bold-fonts")
|
|
||||||
if(!noEvent){
|
if(!noEvent){
|
||||||
pageEvents.send("language-change", lang.id)
|
pageEvents.send("language-change", lang.id)
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,12 @@ class SongSelect{
|
|||||||
background: "#fab5d3",
|
background: "#fab5d3",
|
||||||
border: ["#ffe7ef", "#d36aa2"],
|
border: ["#ffe7ef", "#d36aa2"],
|
||||||
outline: "#d36aa2"
|
outline: "#d36aa2"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
background: "#ececec",
|
||||||
|
border: ["#fbfbfb", "#8b8b8b"],
|
||||||
|
outline: "#656565",
|
||||||
|
infoFill: "#656565"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,13 +923,11 @@ class SongSelect{
|
|||||||
|
|
||||||
this.nameplateCache.resize(274, 134, ratio + 0.2)
|
this.nameplateCache.resize(274, 134, ratio + 0.2)
|
||||||
|
|
||||||
var categories = 0
|
|
||||||
var lastCategory
|
var lastCategory
|
||||||
this.songs.forEach(song => {
|
this.songs.forEach(song => {
|
||||||
var cat = (song.category || "") + song.skin.outline
|
var cat = (song.category || "") + song.skin.outline
|
||||||
if(lastCategory !== cat){
|
if(lastCategory !== cat){
|
||||||
lastCategory = cat
|
lastCategory = cat
|
||||||
categories++
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.categoryCache.resize(280, this.songAsset.marginTop + 1 , ratio + 0.5)
|
this.categoryCache.resize(280, this.songAsset.marginTop + 1 , ratio + 0.5)
|
||||||
|
@ -45,9 +45,6 @@ var translations = {
|
|||||||
},
|
},
|
||||||
titleCopyright: {
|
titleCopyright: {
|
||||||
en: "Taiko no Tatsujin ©&™ 2011 BANDAI NAMCO Entertainment Inc."
|
en: "Taiko no Tatsujin ©&™ 2011 BANDAI NAMCO Entertainment Inc."
|
||||||
},
|
|
||||||
categories: {
|
|
||||||
|
|
||||||
},
|
},
|
||||||
selectSong: {
|
selectSong: {
|
||||||
ja: "曲をえらぶ",
|
ja: "曲をえらぶ",
|
||||||
@ -1076,14 +1073,20 @@ var translations = {
|
|||||||
ko: "가사가있는"
|
ko: "가사가있는"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var categories = {}
|
||||||
var allStrings = {}
|
var allStrings = {}
|
||||||
|
|
||||||
function separateStrings(){
|
function separateStrings(){
|
||||||
|
let categoriesTemp = Object.assign({}, categories);
|
||||||
|
categories = {}
|
||||||
|
|
||||||
for(var j in languageList){
|
for(var j in languageList){
|
||||||
var lang = languageList[j]
|
var lang = languageList[j]
|
||||||
allStrings[lang] = {
|
allStrings[lang] = {
|
||||||
id: lang
|
id: lang
|
||||||
}
|
}
|
||||||
var str = allStrings[lang]
|
var str = allStrings[lang]
|
||||||
|
|
||||||
var translateObj = function(obj, name, str){
|
var translateObj = function(obj, name, str){
|
||||||
if(obj != null && "en" in obj && obj["en"] != null){
|
if(obj != null && "en" in obj && obj["en"] != null){
|
||||||
for(var i in obj){
|
for(var i in obj){
|
||||||
@ -1094,11 +1097,21 @@ function separateStrings(){
|
|||||||
for(var i in obj){
|
for(var i in obj){
|
||||||
translateObj(obj[i], i, str[name])
|
translateObj(obj[i], i, str[name])
|
||||||
}
|
}
|
||||||
|
}else{ //key appears in string obj but has no language values, so just apply the key name to each language for consistency and as fallback
|
||||||
|
str[name] = name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i in translations){
|
for(var i in translations){
|
||||||
translateObj(translations[i], i, str)
|
translateObj(translations[i], i, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
categories[lang] = {
|
||||||
|
id: lang
|
||||||
|
}
|
||||||
|
var str = categories[lang]
|
||||||
|
for(var i in categoriesTemp){
|
||||||
|
translateObj(categoriesTemp[i], i, str)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
separateStrings()
|
|
||||||
|
@ -11,7 +11,7 @@ class Titlescreen{
|
|||||||
this.disclaimerCopyright = document.getElementById("title-disclaimer-copyright")
|
this.disclaimerCopyright = document.getElementById("title-disclaimer-copyright")
|
||||||
this.logo = new Logo()
|
this.logo = new Logo()
|
||||||
}
|
}
|
||||||
this.setLang(allStrings[settings.getItem("language")])
|
this.setLang()
|
||||||
|
|
||||||
if(songId){
|
if(songId){
|
||||||
if(localStorage.getItem("tutorial") === "true"){
|
if(localStorage.getItem("tutorial") === "true"){
|
||||||
@ -76,8 +76,21 @@ class Titlescreen{
|
|||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setLang(lang, noEvent){
|
setLang(){
|
||||||
settings.setLang(lang, true)
|
let stringLang = allStrings[settings.getItem("language")]
|
||||||
|
let categoryLang = categories[settings.getItem("language")]
|
||||||
|
|
||||||
|
strings = stringLang
|
||||||
|
strings.categories = categoryLang
|
||||||
|
|
||||||
|
settings.setLang(stringLang, true, allStrings)
|
||||||
|
settings.setLang(categoryLang, true, categories)
|
||||||
|
|
||||||
|
let boldFonts = strings.font === "Microsoft YaHei, sans-serif"
|
||||||
|
loader.screen.style.fontFamily = strings.font
|
||||||
|
loader.screen.style.fontWeight = boldFonts ? "bold" : ""
|
||||||
|
loader.screen.classList[boldFonts ? "add" : "remove"]("bold-fonts")
|
||||||
|
|
||||||
if(this.songId){
|
if(this.songId){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user