Expansion of Cheat.js which enables translators to better preview changes made in Text, Stage and Intro CSVs for Bondage College.

This commit is contained in:
Miisha 2023-02-15 20:08:51 +01:00
parent 4a1d8855d0
commit cbd10a248f
2 changed files with 66 additions and 3 deletions

View file

@ -1,11 +1,15 @@
var CheatAllow = false;
var TranslationCheatAllow = false;
var TranslationCacheCounter = 0; // used to bypass browser cache for CSV
var TranslationCurrentText = 0;
var TranslationCurrentStageFileLine = 0;
var TranslationSavedStage;
// Receives cheat keys
function CheatKey() {
// No cheats until the player has a name
if (Common_PlayerName != "") {
// In a fight or a race, the user can press * to win automatically
if (!FightEnded && (FightTimer > 0)) { if (KeyPress == 42) FightEnd(true); return; }
if (!DoubleFightEnded && (DoubleFightTimer > 0)) { if (KeyPress == 42) DoubleFightEnd(true); return; }
@ -19,7 +23,7 @@ function CheatKey() {
// Specific cheats by functions
if (CurrentActor != "") CheatActor();
if ((CurrentChapter == "C012_AfterClass") && (CurrentScreen == "Dorm")) CheatDorm();
CheatSkill();
if(TranslationCheatAllow) CheatTranslation(); else CheatSkill(); // skill modifiyng keys 5 - 9 are reused for translation related functions
CheatInventory();
}
@ -65,6 +69,64 @@ function CheatSkill() {
if (KeyPress == 57) PlayerAddSkill("Sports", 1);
}
// Cheats used for text editing a translation
function CheatTranslation(){
// Slash key (/) forces reload of current texts from CSV
// Stage buttons will be redrawn immediately, however the scene texts from Intro and Text files not
if(KeyPress == 47) {
let language = GetWorkingLanguage();
let texts = ["Intro","Stage","Text"];
for(var c in texts){
var cachePath = CurrentChapter + "/" + CurrentScreen + "/" + texts[c] + (language ? ("_" + language) : "") + ".csv"
if(CSVCache[cachePath]) delete CSVCache[cachePath];
}
TranslationCacheCounter++;
if(CurrentIntro !== null && CurrentStage !== null){
LoadInteractions();
} else if(CurrentText !== null){
LoadText();
}
}
// number 6 key loads to OverridenIntroText previous text from Text_LANG file, number 9 loads next text
if(KeyPress === 54 || KeyPress === 57){
let texts = CurrentText;
if(texts && texts.length > 1){
if(KeyPress === 57) TranslationCurrentText--; else TranslationCurrentText++;
TranslationCurrentText = Math.min(texts.length - 1, Math.max(1, TranslationCurrentText));
let displayText = texts[TranslationCurrentText][TextContent].trim();
if(displayText !== "") OverridenIntroText = displayText; else OverridenIntroText = "** Text is empty";
}
}
// number 5 key loads to OverridenIntroText previous text from Stage_LANG file, number 8 loads next text
if(KeyPress === 53 || KeyPress === 56){
if (!TranslationSavedStage || TranslationSavedStage.screen !== CurrentChapter + "_" + CurrentScreen) {
TranslationSavedStage = {
stage: window[CurrentChapter + "_" + CurrentScreen + "_CurrentStage"],
screen: CurrentChapter + "_" + CurrentScreen
};
TranslationCurrentStageFileLine = 1;
}
let texts = CurrentStage;
if(texts && texts.length > 1){
if(KeyPress === 56) TranslationCurrentStageFileLine--; else TranslationCurrentStageFileLine++;
TranslationCurrentStageFileLine = Math.min(texts.length - 1, Math.max(1, TranslationCurrentStageFileLine));
let displayText = texts[TranslationCurrentStageFileLine][StageInteractionResult].trim();
if(displayText !== "") OverridenIntroText = displayText; else OverridenIntroText = "** Stage has empty interaction result";
let currentStage = texts[TranslationCurrentStageFileLine][StageNumber];
window[CurrentChapter + "_" + CurrentScreen + "_CurrentStage"] = currentStage;
console.log("Stage: " + currentStage + " Line: " + TranslationCurrentStageFileLine + 1);
}
}
// number 7 returns non overriden intro text (if present)
if(KeyPress === 55){
OverridenIntroText = "";
if(TranslationSavedStage) {
window[CurrentChapter + "_" + CurrentScreen + "_CurrentStage"] = TranslationSavedStage.stage
TranslationSavedStage = undefined;
}
}
}
// Cheats to add inventory (each letter represent an item)
function CheatInventory() {
if ((KeyPress == 65) || (KeyPress == 97)) PlayerAddInventory("Armbinder", 1);

View file

@ -147,7 +147,7 @@ function ReadCSV(Array, ChapterOrPath, Screen, Type, Language) {
}
// Opens the file, parse it and returns the result in an array
Get(Path, function() {
Get(Path + (TranslationCheatAllow ? "?force_" + TranslationCacheCounter : ""), function() {
if (this.status == 200) {
CSVCache[Path] = ParseCSV(this.responseText);
window[Array] = CSVCache[Path];
@ -190,6 +190,7 @@ function GetWorkingLanguageForChapter(Chapter) {
if ((CurrentLanguageTag == "ES") && ["C000_Intro", "C001_BeforeClass", "C002_FirstClass", "C003_MorningDetention"].indexOf(Chapter) >= 0) return "ES";
if ((CurrentLanguageTag == "CN") && ["C000_Intro", "C001_BeforeClass", "C002_FirstClass", "C003_MorningDetention", "C004_ArtClass", "C005_GymClass", "C006_Isolation","C009_Library", "C010_Revenge", "C011_LiteratureClass","C013_BondageClub","C999_Common"].indexOf(Chapter) >= 0) return "CN";
if ((CurrentLanguageTag == "RU") && ["C000_Intro", "C001_BeforeClass"].indexOf(Chapter) >= 0) return "RU";
if ((CurrentLanguageTag == "CS") && ["C000_Intro", "C001_BeforeClass"].indexOf(Chapter) >= 0) return "CS";
return "EN";
//return CurrentLanguageTag;
}