mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-05-05 04:45:52 -05:00
error handling and bugfix for mii editor
This commit is contained in:
parent
684a447a28
commit
314fcf9be5
|
|
@ -1,4 +1,11 @@
|
||||||
// This file gets automatically bundled with browserify when running the start script. This also means that after any update you're gonna need to restart the server to see any changes.
|
/**
|
||||||
|
* Compilation note:
|
||||||
|
* This file gets automatically bundled with browserify when running the start script.
|
||||||
|
* This also means that after any update you're gonna need to restart the server to see any changes.
|
||||||
|
*
|
||||||
|
* browserify is needed for the use of require() in the browser
|
||||||
|
*/
|
||||||
|
const Mii = require('mii-js');
|
||||||
|
|
||||||
// Prevent the user from reloading or leaving the page
|
// Prevent the user from reloading or leaving the page
|
||||||
window.onbeforeunload = function (e) {
|
window.onbeforeunload = function (e) {
|
||||||
|
|
@ -32,21 +39,26 @@ window.addEventListener('resize', () => {
|
||||||
setCanvasScale();
|
setCanvasScale();
|
||||||
});
|
});
|
||||||
|
|
||||||
// MII RENDERER
|
let mii; // global mii object
|
||||||
|
|
||||||
const Mii = require('mii-js');
|
// this initalizes a mii for editing
|
||||||
|
// returns if mii data was parsed successfully
|
||||||
// The Mii data is stored in a script tag in the HTML, so we can just grab it and then remove the element
|
function initializeMiiData(encodedUserMiiData) {
|
||||||
const encodedUserMiiData = document.querySelector(
|
console.group('Initalizing Mii data');
|
||||||
'script#encodedUserMiiData'
|
console.log('encoded mii data:', encodedUserMiiData);
|
||||||
).textContent;
|
|
||||||
document.querySelector('script#encodedUserMiiData').remove();
|
|
||||||
console.log('encodedMiiData', encodedUserMiiData);
|
|
||||||
|
|
||||||
// We initialize the Mii object
|
// We initialize the Mii object
|
||||||
const mii = new Mii(Buffer.from(encodedUserMiiData, 'base64'));
|
try {
|
||||||
|
console.log('Attempting to parse mii data');
|
||||||
|
mii = new Mii(Buffer.from(encodedUserMiiData, 'base64'));
|
||||||
|
} catch (err) {
|
||||||
|
console.error('failed to decode mii data', err);
|
||||||
|
console.groupEnd();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// We set the img sources for the unedited miis in the save animation
|
// We set the img sources for the unedited miis in the save animation
|
||||||
|
console.log('grabbing rendered miis for later use');
|
||||||
const miiStudioNeutralUrl = mii.studioUrl({
|
const miiStudioNeutralUrl = mii.studioUrl({
|
||||||
width: 512,
|
width: 512,
|
||||||
bgColor: '13173300',
|
bgColor: '13173300',
|
||||||
|
|
@ -57,8 +69,27 @@ const miiStudioSorrowUrl = mii.studioUrl({
|
||||||
expression: 'sorrow',
|
expression: 'sorrow',
|
||||||
});
|
});
|
||||||
document.querySelector('.mii-comparison img.old-mii').src = miiStudioNeutralUrl;
|
document.querySelector('.mii-comparison img.old-mii').src = miiStudioNeutralUrl;
|
||||||
document.querySelector('.mii-comparison.confirmed img.old-mii').src =
|
document.querySelector('.mii-comparison.confirmed img.old-mii').src = miiStudioSorrowUrl;
|
||||||
miiStudioSorrowUrl;
|
console.log('initialization complete');
|
||||||
|
console.groupEnd();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Mii data is stored in a script tag in the HTML, so we can just grab it and then remove the element
|
||||||
|
const encodedUserMiiData = document.querySelector(
|
||||||
|
'script#encodedUserMiiData'
|
||||||
|
).textContent;
|
||||||
|
document.querySelector('script#encodedUserMiiData').remove();
|
||||||
|
|
||||||
|
// is valid mii data
|
||||||
|
const validMiiData = initializeMiiData(encodedUserMiiData);
|
||||||
|
if (!validMiiData) {
|
||||||
|
const shouldContinue = window.confirm('Found corrupted mii data, want to continue with a new Mii?');
|
||||||
|
if (!shouldContinue)
|
||||||
|
window.location.assign('/account');
|
||||||
|
const newMii = 'AAEAQCpE2oVAJPDA1/vMZJrD1O74rwAAqWFCAEIAAAAAAAAAAAAAAAAAAAAAAGZfBABgAbFGYxYkFEUSwRITZg8ACCUwSqNYYQBzAGgAbQAAAAAAAAAAAAAAAAAAAKCF';
|
||||||
|
initializeMiiData(newMii);
|
||||||
|
}
|
||||||
|
|
||||||
// we keeep the images here so we can cache them when we need to change the build/height
|
// we keeep the images here so we can cache them when we need to change the build/height
|
||||||
const miiFaceImg = new Image();
|
const miiFaceImg = new Image();
|
||||||
|
|
@ -445,7 +476,7 @@ document
|
||||||
const tokenType = document.cookie.split('; ').find(row => row.startsWith('token_type=')).split('=')[1];
|
const tokenType = document.cookie.split('; ').find(row => row.startsWith('token_type=')).split('=')[1];
|
||||||
const accessToken = document.cookie.split('; ').find(row => row.startsWith('access_token=')).split('=')[1];
|
const accessToken = document.cookie.split('; ').find(row => row.startsWith('access_token=')).split('=')[1];
|
||||||
|
|
||||||
fetch('http://api.pretendo.cc/v1/user', {
|
fetch('https://api.pretendo.cc/v1/user', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user