diff --git a/source/Prebuild.hx b/source/Prebuild.hx index 6856c414c..0dc6dd406 100644 --- a/source/Prebuild.hx +++ b/source/Prebuild.hx @@ -9,10 +9,23 @@ class Prebuild { static inline final BUILD_TIME_FILE:String = '.build_time'; + static final NG_CREDS_PATH:String = './source/funkin/api/newgrounds/NewgroundsCredentials.hx'; + + static final NG_CREDS_TEMPLATE:String = "package funkin.api.newgrounds; + +class NewgroundsCredentials +{ + public static final APP_ID:String = #if API_NG_APP_ID haxe.macro.Compiler.getDefine(\"API_NG_APP_ID\") #else 'INSERT APP ID HERE' #end; + public static final ENCRYPTION_KEY:String = #if API_NG_ENC_KEY haxe.macro.Compiler.getDefine(\"API_NG_ENC_KEY\") #else 'INSERT ENCRYPTION KEY HERE' #end; +}"; + static function main():Void { - saveBuildTime(); trace('Building...'); + + saveBuildTime(); + + buildCredsFile(); } static function saveBuildTime():Void @@ -22,4 +35,22 @@ class Prebuild fo.writeDouble(now); fo.close(); } + + static function buildCredsFile():Void + { + #if sys + if (sys.FileSystem.exists(NG_CREDS_PATH)) + { + trace('NewgroundsCredentials.hx already exists, skipping.'); + } + else + { + trace('Creating NewgroundsCredentials.hx...'); + + var fileContents:String = NG_CREDS_TEMPLATE; + + sys.io.File.saveContent(NG_CREDS_PATH, fileContents); + } + #end + } } diff --git a/source/funkin/api/newgrounds/NewgroundsClient.hx b/source/funkin/api/newgrounds/NewgroundsClient.hx index 513d1c564..c631bbb73 100644 --- a/source/funkin/api/newgrounds/NewgroundsClient.hx +++ b/source/funkin/api/newgrounds/NewgroundsClient.hx @@ -36,14 +36,13 @@ class NewgroundsClient private function new() { - if (NewgroundsCredentials.ENCRYPTION_KEY.contains(' ')) - { - trace('[NEWGROUNDS] Encryption key not valid, disabling...'); - return; - } - trace('[NEWGROUNDS] Initializing client...'); + #if FEATURE_NEWGROUNDS_DEBUG + trace('[NEWGROUNDS] App ID: ${NewgroundsCredentials.APP_ID}'); + trace('[NEWGROUNDS] Encryption Key: ${NewgroundsCredentials.ENCRYPTION_KEY}'); + #end + if (!hasValidCredentials()) { FlxG.log.warn("Tried to initialize Newgrounds client, but credentials are invalid!");