Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joaorb64 committed Jun 13, 2024
1 parent aab64ec commit aec3ba4
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 160 deletions.
11 changes: 9 additions & 2 deletions layout/include/assetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,22 @@ async function updateCharacterContainer(e, event) {
}

await Promise.allSettled(loads);
gsap.fromTo($(e).children(".tsh_character"), anim_out, anim_in);

if($(e) && $(e).children(".tsh_character").length > 0){
gsap.fromTo($(e).children(".tsh_character"), anim_out, anim_in);
}
};

if (firstRun) {
// No need to fade out
await callback();
} else {
// Fade out, then change data and fade in
gsap.to($(e).children(".tsh_character"), anim_out).then(callback);
if($(e) && $(e).children(".tsh_character").length > 0){
gsap.to($(e).children(".tsh_character"), anim_out).then(callback);
} else {
await callback();
}
}
}
}
Expand Down
100 changes: 47 additions & 53 deletions layout/include/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ async function UpdateWrapper(event) {
// If initialization wasn't done yet, call Start()
// We use gsap.globalTimeline.timeScale as 0 for animation to not play before this
if (gsap.globalTimeline.timeScale() == 0) {
gsap.globalTimeline.timeScale(1);
window.requestAnimationFrame(() => {
$(document).waitForImages(() => {
$("body").fadeTo(1, 1, () => {
Start();
gsap.globalTimeline.timeScale(1);
});
});
});
Expand Down Expand Up @@ -199,10 +199,11 @@ async function InitAll() {
} else {
// Call program_state.json load just in case it takes
// a bit to start the websocket
// await UpdateData();
await UpdateData_SocketIO();
}

// await UpdateData();

console.log("== Init complete ==");
document.dispatchEvent(new CustomEvent("tsh_init"));

Expand Down Expand Up @@ -329,77 +330,70 @@ async function Transcript(text) {
// Sequence: runs anim_out > changes content > runs anim_in
// Uses FitText to scale div contents to fit
async function SetInnerHtml(element, html, settings = {}) {
let force = undefined;
let fadeTime = 0.5;
let middleFunction = undefined;
// Extract settings
let { force, fadeTime = 0.5, middleFunction } = settings;

if (element == null) return;
if (force == false) return;
if (force === false) return;

// Fade out/in animations
let anim_in = { autoAlpha: 1, duration: fadeTime, stagger: 0.1 };

if (settings.anim_in) {
anim_in = settings.anim_in;
}

let anim_out = { autoAlpha: 0, duration: fadeTime, stagger: 0.1 };

if (settings.anim_out) {
anim_out = settings.anim_out;
}
let anim_in = { autoAlpha: 1, duration: fadeTime, stagger: 0.1, ...settings.anim_in };
let anim_out = { autoAlpha: 0, duration: fadeTime, stagger: 0.1, overwrite: true, ...settings.anim_out };

anim_out.overwrite = true;

if (html == null || html == undefined) html = "";
if (html == null || html === undefined) html = "";

html = String(html);

let firstRun = false;
let firstRun = element.find(".text").length === 0;

// First run, no need of smooth fade out
if (element.find(".text").length == 0) {
// First run, no need for smooth fade out
if (firstRun) {
// Put any text inside the div just so the font loading is triggered
element.html("<div class='text' style='opacity: 0;'>&nbsp;</div>");
firstRun = true;
}

// Wait for font to load before calculating sizes
document.fonts.ready.then(() => {
if (
force == true ||
he.decode(String(element.find(".text").html()).replace(/'/g, '"')) !=
he.decode(String(html).replace(/'/g, '"'))
) {
const callback = () => {
element.find(".text").html(html);
if (html.trim().length == 0) {
element.find(".text").addClass("text_empty");
element.addClass("text_empty");
} else {
element.find(".text").removeClass("text_empty");
element.removeClass("text_empty");
}
FitText(element);
if (middleFunction != undefined) {
middleFunction();
}
$(element).ready((e) => {
gsap.fromTo(element.find(".text"), anim_out, anim_in);
});
};
await document.fonts.ready;

// Decode the HTML content to compare
const currentText = he.decode(String(element.find(".text").html()).replace(/'/g, '"'));
const newText = he.decode(String(html).replace(/'/g, '"'));

if (force === true || currentText !== newText) {
const updateElement = () => {
element.find(".text").html(html);

if (!firstRun) {
gsap.to(element.find(".text"), anim_out).then(() => callback());
if (html.trim().length === 0) {
element.find(".text").addClass("text_empty");
element.addClass("text_empty");
} else {
let newAnimOut = Object.assign({}, anim_out);
newAnimOut.duration = 0;
gsap.to(element.find(".text"), anim_out).then(() => callback());
element.find(".text").removeClass("text_empty");
element.removeClass("text_empty");
}

FitText(element);

if (middleFunction) {
middleFunction();
}

if (firstRun) {
gsap.set(element.find(".text"), anim_in);
} else {
gsap.fromTo(element.find(".text"), anim_out, anim_in);
}
};

if (!firstRun) {
await gsap.to(element.find(".text"), anim_out).then(updateElement);
} else {
anim_out.duration = 1;
await gsap.to(element.find(".text"), anim_out).then(updateElement);
}
});
}
}


const degrees_to_radians = (deg) => (deg * Math.PI) / 180.0;

// Given a number of characters, returns an array os positions (0-1) for their eyesights
Expand Down
4 changes: 2 additions & 2 deletions layout/stream_queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ LoadEverything().then(() => {
${ player.pronoun ?
` <div class = "pronoun"> ${ wrap_text((!isTeams && true) ? String(player.pronoun) : "") } </div>` : ''
}
${ team.seed ?
`<div class = "seed"> ${wrap_text("Seed " + team.seed)} </div> ` : ''
${ player.seed ?
`<div class = "seed"> ${wrap_text("Seed " + player.seed)} </div> ` : ''
}
Expand Down
2 changes: 1 addition & 1 deletion layout/stream_queue/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"default": {}
},
"stream": "",
"default_stream" : "vgbootcamp",
"default_stream" : "",
"force_multistream" : false,
"display_stream_name" : "multistream",
"sets_displayed" : -1,
Expand Down
4 changes: 2 additions & 2 deletions layout/stream_queue_simple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ LoadEverything().then(() => {
${ player.pronoun ?
` <div class = "pronoun"> ${ wrap_text((!isTeams && true) ? String(player.pronoun) : "") } </div>` : ''
}
${ team.seed ?
`<div class = "seed"> ${wrap_text("Seed " + team.seed)} </div> ` : ''
${ player.seed ?
`<div class = "seed"> ${wrap_text("Seed " + player.seed)} </div> ` : ''
}
Expand Down
2 changes: 1 addition & 1 deletion layout/versus_screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ LoadEverything().then(() => {
SetInnerHtml($(`.p${t + 1} .flagcountry`), "");
SetInnerHtml($(`.p${t + 1} .flagstate`), "");
SetInnerHtml($(`.p${t + 1} .pronoun`), "");
SetInnerHtml($(`.p${t + 1} .seed`), team.seed ? `Seed ${team.seed}` : "");
SetInnerHtml($(`.p${t + 1} .seed`), _.get(team, "player.1.seed") ? `Seed ${_.get(team, "player.1.seed")}` : "");

let characterNames = [];

Expand Down
2 changes: 1 addition & 1 deletion layout/versus_screen_pokken/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ LoadEverything().then(() => {

SetInnerHtml($(`.p${t + 1} .pronoun`), "");

SetInnerHtml($(`.p${t + 1} .seed`), team.seed ? `Seed ${team.seed}` : "");
SetInnerHtml($(`.p${t + 1} .seed`), _.get(team, "player.1.seed") ? `Seed ${_.get(team, "player.1.seed")}` : "");

let characterNames = [];

Expand Down
1 change: 0 additions & 1 deletion layout/versus_screen_tekken8/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ body {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-image: url(./bg.png);
filter: blur(5px) contrast(1.6) saturate(0.5) brightness(0.8);
}

Expand Down
2 changes: 1 addition & 1 deletion layout/versus_screen_tekken8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ LoadEverything().then(() => {

SetInnerHtml($(`.p${t + 1} .pronoun`), "");

SetInnerHtml($(`.p${t + 1} .seed`), team.seed ? `<div class="unskew">Seed ${team.seed}</div>` : "");
SetInnerHtml($(`.p${t + 1} .seed`), _.get(team, "player.1.seed") ? `<div class="unskew">Seed ${_.get(team, "player.1.seed")}</div>` : "");

let characterNames = [];

Expand Down
10 changes: 6 additions & 4 deletions src/TSHAssetDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def DownloadAssets(self):
self.select.setEditable(True)
self.select.completer().setFilterMode(Qt.MatchFlag.MatchContains)
self.select.completer().setCompletionMode(QCompleter.PopupCompletion)
self.font_small = QFont("./assets/font/RobotoCondensed.ttf", pointSize=8)
self.font_small = QFont(
"./assets/font/RobotoCondensed.ttf", pointSize=8)
self.select.setFont(self.font_small)
self.select.setModel(QStandardItemModel())
self.preDownloadDialogue.layout().addWidget(self.select)
Expand Down Expand Up @@ -331,7 +332,7 @@ def DownloadAssetsFetch(self):
messagebox.exec()
return assets

def DownloadGameIcon(self, game_code, index, progress_callback):
def DownloadGameIcon(self, game_code, index, progress_callback, cancel_event):
try:
response = urllib.request.urlopen(
f"https://raw.githubusercontent.com/joaorb64/StreamHelperAssets/main/games/{game_code}/base_files/logo.png")
Expand All @@ -355,7 +356,7 @@ def DownloadGameIconComplete(self, result):
logger.error(traceback.format_exc())
return (None)

def DownloadAssetsWorker(self, files, progress_callback):
def DownloadAssetsWorker(self, files, progress_callback, cancel_event):
totalSize = sum(sum(f["size"] for f in fileList) for fileList in files)
downloaded = 0

Expand Down Expand Up @@ -450,7 +451,8 @@ def f(assets):
for fileToDownload in filesToDownload:
fileToDownload[
"path"] = f'https://github.com/joaorb64/StreamHelperAssets/releases/latest/download/{fileToDownload["name"]}'
fileToDownload["extractpath"] = f'./user_data/games/{game}'
fileToDownload["extractpath"] = f'./user_data/games/{
game}'
allFilesToDownload.append(filesToDownload)

TSHAssetDownloader.instance.downloadDialogue = QProgressDialog(
Expand Down
13 changes: 8 additions & 5 deletions src/TSHGameAssetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def UpdateStageModel(self):
except:
logger.error(traceback.format_exc())

def LoadStageImage(self, stage, item, progress_callback):
def LoadStageImage(self, stage, item, progress_callback, cancel_event):
try:
if stage.get("path") and os.path.exists(stage.get("path")):
img = Image.open(stage.get("path"))
Expand Down Expand Up @@ -664,7 +664,7 @@ def UpdateSkinModel(self):
for w in self.workers:
self.threadpool.start(w)

def LoadSkinImages(self, allAssetData, allItem, skinModel, progress_callback):
def LoadSkinImages(self, allAssetData, allItem, skinModel, progress_callback, cancel_event):
try:
icons = []

Expand Down Expand Up @@ -939,16 +939,19 @@ def GetCharacterAssets(self, characterCodename: str, skin: int, assetpack: str =
else:
metadata_title_locale = asset.get("metadata", {})[
key].get("title", '')
charFiles[assetKey]['metadata'][f"{key}"]["title"] = metadata_title_locale
charFiles[assetKey]['metadata'][f"{key}"][f"value_en"] = metadata[key]
charFiles[assetKey]['metadata'][f"{
key}"]["title"] = metadata_title_locale
charFiles[assetKey]['metadata'][f"{
key}"][f"value_en"] = metadata[key]
if TSHLocaleHelper.exportLocale in asset.get("metadata", {})[key]["values"].get(characterCodename, {}).get("locale", {}).keys() or TSHLocaleHelper.exportLocale.split('-')[0] in asset.get("metadata", {})[key]["values"].get(characterCodename, {}).get("locale", {}).keys():
try:
metadata[key] = asset.get("metadata", {})[key]["values"].get(
characterCodename, {}).get("locale", {})[TSHLocaleHelper.exportLocale]
except KeyError:
metadata[key] = asset.get("metadata", {})[key]["values"].get(
characterCodename, {}).get("locale", {})[TSHLocaleHelper.exportLocale.split('-')[0]]
charFiles[assetKey]['metadata'][f"{key}"][f"value"] = metadata[key]
charFiles[assetKey]['metadata'][f"{
key}"][f"value"] = metadata[key]

# if len(metadata.keys()) > 0:
# if str(skin) in metadata:
Expand Down
Loading

0 comments on commit aec3ba4

Please sign in to comment.