Mirror for Friday Night Funkin
at main 91 lines 2.8 kB view raw
1package funkin.modding; 2 3import polymod.Polymod; 4 5class PolymodErrorHandler 6{ 7 /** 8 * Show a popup with the given text. 9 * This displays a system popup, it WILL interrupt the game. 10 * Make sure to only use this when it's important, like when there's a script error. 11 * 12 * @param name The name at the top of the popup. 13 * @param desc The body text of the popup. 14 */ 15 public static function showAlert(name:String, desc:String):Void 16 { 17 lime.app.Application.current.window.alert(desc, name); 18 } 19 20 public static function onPolymodError(error:PolymodError):Void 21 { 22 // Perform an action based on the error code. 23 switch (error.code) 24 { 25 case FRAMEWORK_INIT, FRAMEWORK_AUTODETECT, SCRIPT_PARSING: 26 // Unimportant. 27 return; 28 29 case MOD_LOAD_PREPARE, MOD_LOAD_DONE: 30 logInfo('LOADING MOD - ${error.message}'); 31 32 case MISSING_ICON: 33 logWarn('A mod is missing an icon. Please add one.'); 34 35 case SCRIPT_PARSE_ERROR: 36 // A syntax error when parsing a script. 37 logError(error.message); 38 // Notify the user via popup. 39 showAlert('Polymod Script Parsing Error', error.message); 40 case SCRIPT_RUNTIME_EXCEPTION: 41 // A runtime error when running a script. 42 logError(error.message); 43 // Notify the user via popup. 44 showAlert('Polymod Script Exception', error.message); 45 case SCRIPT_CLASS_MODULE_NOT_FOUND: 46 // A scripted class tried to reference an unknown class or module. 47 logError(error.message); 48 49 // Last word is the class name. 50 var className:String = error.message.split(' ').pop(); 51 var msg:String = 'Import error in ${error.origin}'; 52 msg += '\nCould not import unknown class ${className}'; 53 msg += '\nCheck to ensure the class exists and is spelled correctly.'; 54 55 // Notify the user via popup. 56 showAlert('Polymod Script Import Error', msg); 57 case SCRIPT_CLASS_MODULE_BLACKLISTED: 58 // A scripted class tried to reference a blacklisted class or module. 59 logError(error.message); 60 // Notify the user via popup. 61 showAlert('Polymod Script Blacklist Violation', error.message); 62 63 default: 64 // Log the message based on its severity. 65 switch (error.severity) 66 { 67 case NOTICE: 68 logInfo(error.message); 69 case WARNING: 70 logWarn(error.message); 71 case ERROR: 72 logError(error.message); 73 } 74 } 75 } 76 77 static function logInfo(message:String):Void 78 { 79 trace('[INFO-] ${message}'); 80 } 81 82 static function logError(message:String):Void 83 { 84 trace('[ERROR] ${message}'); 85 } 86 87 static function logWarn(message:String):Void 88 { 89 trace('[WARN-] ${message}'); 90 } 91}