A lot of things.
This commit is contained in:
114
resources/js/RomPatcher.js
Normal file
114
resources/js/RomPatcher.js
Normal file
@@ -0,0 +1,114 @@
|
||||
export function RomPatcher( initialPatches = {} ) {
|
||||
|
||||
let patchesArray = [];
|
||||
if (initialPatches) {
|
||||
patchesArray = Array.isArray(initialPatches) ? initialPatches : [initialPatches];
|
||||
}
|
||||
patchesArray = patchesArray.filter(p => p && p.file);
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
romFileName: '',
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
patchFileName: '',
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
isRomDragOver: false,
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
isPatchDragOver: false,
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
showStatusBox: false,
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
patchesData: patchesArray,
|
||||
hasEmbedded: patchesArray.length > 0,
|
||||
|
||||
init() {
|
||||
|
||||
const CONFIG = {language: 'en', requireValidation: false};
|
||||
|
||||
if (!RomPatcherWeb.isInitialized()){
|
||||
if (this.hasEmbedded) {
|
||||
RomPatcherWeb.initialize(CONFIG, ...this.patchesData);
|
||||
} else {
|
||||
RomPatcherWeb.initialize(CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
const STAT_BOX = document.getElementById('patcher-status');
|
||||
const OBSERVER = new MutationObserver(() => {
|
||||
const CRC = document.getElementById('rom-patcher-span-crc32').textContent;
|
||||
const DESC = document.getElementById('rom-patcher-patch-description').textContent;
|
||||
const PATCH = document.getElementById('rom-patcher-patch-requirements-value').textContent;
|
||||
|
||||
this.showStatusBox = CRC.trim().length > 0 || DESC.trim().length > 0 || PATCH.trim().length > 0;
|
||||
});
|
||||
|
||||
OBSERVER.observe(STAT_BOX, { childList: true, subtree: true, characterData: true });
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} id
|
||||
*/
|
||||
triggerFileInput(id){
|
||||
const I = document.getElementById(id);
|
||||
if( !I.disabled )
|
||||
I.click();
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Event} e
|
||||
* @param {string} type
|
||||
*/
|
||||
handleInputChange(e, type){
|
||||
const file = e.target.files[0];
|
||||
if(file){
|
||||
if( type === 'rom' ) this.romFileName = file.name;
|
||||
if( type === 'patch' ) this.patchFileName = file.name;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Event} e
|
||||
* @param {string} type
|
||||
*/
|
||||
handleDrop(e, type ){
|
||||
|
||||
const file = e.dataTransfer.files[0];
|
||||
if( !file )
|
||||
return;
|
||||
|
||||
const ID = type === 'rom' ? 'rom-patcher-input-file-rom' : 'rom-patcher-input-file-patch';
|
||||
const I = document.getElementById(ID);
|
||||
|
||||
if( I.disabled )
|
||||
return;
|
||||
|
||||
I.files = e.dataTransfer.files;
|
||||
|
||||
if( type === 'rom' ) this.romFileName = file.name;
|
||||
if( type === 'patch' ) this.patchFileName = file.name;
|
||||
|
||||
I.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,16 @@ export function FSFileData(name, totalChunks, rawFile ) {
|
||||
*/
|
||||
state: 'public',
|
||||
|
||||
/**
|
||||
* If the online patcher is enabled
|
||||
*/
|
||||
meta_online_patcher: false,
|
||||
|
||||
/**
|
||||
* If this patch is a secondary patch.
|
||||
*/
|
||||
meta_secondary_online_patcher: false,
|
||||
|
||||
/**
|
||||
* Look if this file is currently uploading.
|
||||
* @returns {boolean}
|
||||
|
||||
@@ -7,6 +7,7 @@ import hovercard from "./hovercard.js";
|
||||
import notifications from "./notifications.js";
|
||||
import conversations from "./conversations.js";
|
||||
import settings from "./settings.js";
|
||||
import {RomPatcher} from "./RomPatcher.js";
|
||||
|
||||
/**
|
||||
* Get config defined in meta.blade.php
|
||||
@@ -43,3 +44,6 @@ Alpine.store('conversations', conversations() );
|
||||
|
||||
// Settings
|
||||
Alpine.store('settings', settings() );
|
||||
|
||||
// ROMPatcher
|
||||
window.RomPatcher = RomPatcher;
|
||||
|
||||
@@ -372,6 +372,12 @@ window.Submission = function(){
|
||||
this.errorKey = null; // Reset.
|
||||
this.duringSubmissionProcess = true;
|
||||
|
||||
const STATE = document.querySelector('select[name="submit-state"]')?.value;
|
||||
if( STATE === 'draft' ){
|
||||
e.target.submit();
|
||||
return;
|
||||
}
|
||||
|
||||
if( !this.verifyForm() ){
|
||||
|
||||
this.scrollToError();
|
||||
|
||||
Reference in New Issue
Block a user