Skip to content

Commit 0d8640c

Browse files
committed
Add mod loading and error modals
1 parent 85a2449 commit 0d8640c

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

API/GDApi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ GDAPI.currentScene = null;
5050
GDAPI.game = null;
5151

5252
/**
53-
* This is a function overriden by the loader that lets you send
53+
* This is a function overriden by the loader that lets you send updates to the UI.
54+
* Receiving and handling messages from the UI is handled by the loader.
5455
* @function
5556
* @param {string} id - The Identifier, aka the main message. This tells the IDE what you want to do.
5657
* @param {any} extraData - An object to pass to the UI with the message.

API/GDMod.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ GDAPI.loadZipMod = function(modAsZip) {
162162
)
163163
}
164164
return Promise.all(promises);
165-
});
165+
})
166+
.then(() => GDAPI.messageUI("modLoaded"));
166167
});
167168
}).catch((error) => {
168169
console.error("Error while loading mod file: " + error.toString());
170+
GDAPI.messageUI("modLoadError", error);
169171
});
170172
};
171173

Loader/gdmodext/html/menu.html

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ <h1 class="uk-heading-medium" id="connecting">Connecting to game...</h1>
1818
<h2 class="uk-heading-small">Overview</h2>
1919
<p class="uk-text-lead">
2020
Welcome to the dashboard! Here you can control the game like you want.
21-
Keep in mind that this tool is for modding, and the other tools are made for
21+
Keep in mind that this tool is for <br>modding</br>, and the other tools are made for
2222
<b>debugging mods</b>. You can use them for other purpose but
2323
while using them keep in mind that their main purpose is modding.
2424
</p>
2525
</li>
2626
<li id="mods">
27-
<h2 class="uk-heading-small">Mod Loader</h2>
27+
<h2 class="uk-heading-small">Mod Manager</h2>
2828
<button class="uk-button-primary" id="selectMod">Load Mod</button>
2929
<input type="file" id="fileInput" hidden></input>
30-
<a href="#" uk-switcher-item="next">Go to Scene Switcher</a>
3130
</li>
3231
<li id="scenes">
3332
<h2 class="uk-heading-small">Scene switcher</h2>
@@ -42,6 +41,38 @@ <h2 class="uk-heading-small">Settings</h2>
4241
<a href="#" uk-switcher-item="previous">Go to Scene Switcher</a>
4342
</li>
4443
</ul>
44+
45+
<!-- Modals For Modloading -->
46+
<div id="modload-modal" class="uk-modal-full uk-background-muted" esc-close="false" bg-close="false" uk-modal>
47+
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical">
48+
<div class="uk-grid-collapse uk-child-width-1-2@s uk-flex-middle" uk-grid>
49+
<div class="uk-padding-large">
50+
<h1>Mod Loading...</h1>
51+
<p id="modload-currentAction" class="uk-center">Loading mod...</p>
52+
<progress id="modload-progress" class="uk-progress" value="0" max="3"></progress>
53+
</div>
54+
</div>
55+
</div>
56+
</div>
57+
58+
<div id="modload-error-modal" class="uk-modal-full uk-background-muted" uk-modal>
59+
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical">
60+
<div class="uk-grid-collapse uk-child-width-1-2@s uk-flex-middle" uk-grid>
61+
<div class="uk-padding-large">
62+
<h2>Error While Loding Mod</h2>
63+
<ul uk-accordion>
64+
<li>
65+
<a class="uk-accordion-title" href="#">Show Error</a>
66+
<div class="uk-accordion-content">
67+
<p id="modload-error">Error.</p>
68+
</div>
69+
</li>
70+
</ul>
71+
<button class="uk-modal-close">Ok</button>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
4576

4677
<!-- Additional Scripts -->
4778
<script src="../vendor/uikit.min.js"></script>

Loader/gdmodext/js/injected.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const debug = false;
1111
/**
1212
* The CDN to fetch the GDAPI files from
1313
*/
14-
const CDN = "https://cdn.jsdelivr.net/gh/arthuro555/gdmod@0.0.1-preview/API/";
15-
//const CDN = "http://localhost:5000/";
14+
//const CDN = "https://cdn.jsdelivr.net/gh/arthuro555/gdmod@0.0.1-preview/API/";
15+
const CDN = "http://localhost:5000/";
1616

1717
/**
1818
* Flag telling if that page got patched already.
@@ -150,6 +150,7 @@ if(window.gdjs !== undefined) {
150150
GDAPI.currentScene.getGame()._sceneStack.replace(event.data.scene, true);
151151
} else if(event.data["message"] === "loadMod") {
152152
const mod = dataURItoBlob(event.data["mod"]);
153+
postToPopup("modReceived");
153154
GDAPI.loadZipMod(mod);
154155
}
155156
}

Loader/gdmodext/js/menu.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,31 @@ chrome.tabs.query({active: true, currentWindow: false}, function(tabs) {
4949
document.title = "GDmod Scene Selector";
5050
document.getElementById("connecting").innerHTML = "Dashboard for GD game " + event.payload.name;
5151
chrome.tabs.sendMessage(tabs[0].id, {message: "listScenes"}); // Get list of scenes (will be moved)
52+
} else if(event["id"] === "modReceived") {
53+
document.getElementById("modload-currentAction").innerText = "Loading Mod...";
54+
document.getElementById("modload-progress").setAttribute("value","2");
55+
}
56+
} else if(event["origin"] === "GDAPI") {
57+
if(event["id"] === "modLoaded") {
58+
document.getElementById("modload-progress").setAttribute("value","3");
59+
UIkit.modal(document.getElementById("modload-modal")).hide();
60+
} else if(event["id"] === "modLoadError") {
61+
UIkit.modal(document.getElementById("modload-modal")).hide();
62+
document.getElementById("modload-error").innerText = event.payload;
63+
UIkit.modal(document.getElementById("modload-error-modal")).show();
5264
}
5365
}
5466
}
5567
});
5668

5769
const fileElement = document.getElementById("fileInput");
5870
fileElement.addEventListener('change', function () {
71+
UIkit.modal(document.getElementById("modload-modal")).show();
72+
5973
var reader = new FileReader();
6074
reader.onloadend = function() {
75+
document.getElementById("modload-currentAction").innerText = "Uploading Mod to the game...";
76+
document.getElementById("modload-progress").setAttribute("value","1");
6177
chrome.tabs.sendMessage(tabs[0].id, {message: "loadMod", mod: reader.result});
6278
}
6379
reader.readAsDataURL(fileElement.files[0]);

0 commit comments

Comments
 (0)