Add proper configuration for AdMob ads

Co-Authored-By: sector-a <82838084+sector-a@users.noreply.github.com>
Co-Authored-By: Lily <egzozu.be.bas@gmail.com>
This commit is contained in:
KarimAkra
2025-04-15 21:37:00 +03:00
co-authored by sector-a Lily
parent 193d293dea
commit 7b1abe437f
6 changed files with 35 additions and 31 deletions
-1
View File
@@ -859,7 +859,6 @@ class Project extends HXProject {
if (isIOS())
{
// This ID is not from us, it's a test ID provided by AdMob. not really sure if it works.
setEnv("ADMOB_APPID", "");
}
}
+12 -7
View File
@@ -1,7 +1,7 @@
package funkin.mobile.util;
import extension.admob.Admob;
import extension.admob.AdmobEvent;
import admob.Admob;
import admob.util.AdmobEvent;
/**
* Utility class for managing AdMob advertisements in a mobile application.
@@ -15,12 +15,17 @@ class AdMobUtil
* Production ad unit IDs (to be set for actual ad campaigns).
*/
#if !TESTING_ADS
private static final BANNER_AD_UNIT_ID:String = "";
private static final INTERSTITIAL_AD_UNIT_ID:String = "";
private static final BANNER_AD_UNIT_ID:String = #if android "" #elseif ios "" #else "" #end;
private static final INTERSTITIAL_AD_UNIT_ID:String = #if android "" #elseif ios "" #else "" #end;
private static final INTERSTITIAL_VIDEO_AD_UNIT_ID:String = "";
private static final REWARDED_AD_UNIT_ID:String = "";
#else
#else
/**
* Test ad unit IDs for development and testing purposes.
* These IDs are provided by Google AdMob for testing ads without incurring costs.
* They should not be used in production applications.
*/
/**
* Test ad unit ID for banner ads, used during development.
*/
@@ -58,9 +63,9 @@ class AdMobUtil
* it loads either a video or a standard interstitial ad.
* @param forceVideo If true, forces loading an interstitial video ad. Otherwise, it uses a 50% chance.
*/
public static inline function loadInterstitial(forceVideo:Bool = false):Void
public static inline function loadInterstitial():Void
{
Admob.loadInterstitial((forceVideo || FlxG.random.bool(50)) ? AdMobUtil.INTERSTITIAL_VIDEO_AD_UNIT_ID : AdMobUtil.INTERSTITIAL_AD_UNIT_ID);
Admob.loadInterstitial(#if TESTING_ADS FlxG.random.bool(50) ? AdMobUtil.INTERSTITIAL_VIDEO_AD_UNIT_ID : #end AdMobUtil.INTERSTITIAL_AD_UNIT_ID);
}
/**
+15
View File
@@ -21,6 +21,9 @@ import funkin.ui.MusicBeatSubState;
import funkin.ui.transition.StickerSubState;
import funkin.mobile.util.SwipeUtil;
import funkin.mobile.util.TouchUtil;
#if NO_DISABLE_ADMOB_ADS
import funkin.mobile.util.AdMobUtil;
#end
/**
* Parameters for initializing the PauseSubState.
@@ -193,6 +196,11 @@ class PauseSubState extends MusicBeatSubState
{
super();
this.currentMode = params?.mode ?? Standard;
// Add banner ad when game is paused.
#if NO_DISABLE_ADMOB_ADS
AdMobUtil.addBanner(admob.Admob.BANNER_SIZE_BANNER, admob.Admob.BANNER_ALIGN_TOP);
#end
}
// ===============
@@ -427,6 +435,13 @@ class PauseSubState extends MusicBeatSubState
if (accept && !justOpened)
{
// Remove banner ad when game is unpaused.
#if NO_DISABLE_ADMOB_ADS
if (currentMenuEntries[currentEntry].text != "Change Difficulty"
&& currentMenuEntries[currentEntry].text != "Enable Practice Mode"
&& currentMenuEntries[currentEntry].text != "Back") AdMobUtil.removeBanner();
#end
currentMenuEntries[currentEntry].callback(this);
}
else if (controls.PAUSE && !justOpened)
+2 -17
View File
@@ -990,11 +990,6 @@ class PlayState extends MusicBeatSubState
// Attempt to pause the game.
if ((controls.PAUSE || androidPause || pauseButtonCheck) && isInCountdown && mayPauseGame && !justUnpaused)
{
// Add banner ad when game is paused.
#if NO_DISABLE_ADMOB_ADS
AdMobUtil.addBanner(extension.admob.Admob.BANNER_SIZE_BANNER, extension.admob.Admob.BANNER_ALIGN_TOP);
#end
#if mobile
pauseButton.alpha = 0;
#end
@@ -1181,10 +1176,10 @@ class PlayState extends MusicBeatSubState
function moveToGameOver():Void
{
// Shows a video ad on mobile devices each 3 blueballs
// Shows an interstital ad on mobile devices each 3 blueballs
#if NO_DISABLE_ADMOB_ADS
Constants.GLOBAL_BLUEBALL_COUNTER++;
if (Constants.GLOBAL_BLUEBALL_COUNTER > 0 && Constants.GLOBAL_BLUEBALL_COUNTER % 3 == 0) AdMobUtil.loadInterstitial(true);
if (Constants.GLOBAL_BLUEBALL_COUNTER > 0 && Constants.GLOBAL_BLUEBALL_COUNTER % 3 == 0) AdMobUtil.loadInterstitial();
#end
// Reset and update a bunch of values in advance for the transition back from the game over substate.
@@ -1337,11 +1332,6 @@ class PlayState extends MusicBeatSubState
*/
public override function closeSubState():Void
{
// Remove banner ad when game is unpaused.
#if NO_DISABLE_ADMOB_ADS
AdMobUtil.removeBanner();
#end
if (Std.isOfType(subState, PauseSubState))
{
var event:ScriptEvent = new ScriptEvent(RESUME, true);
@@ -1624,11 +1614,6 @@ class PlayState extends MusicBeatSubState
{
performCleanup();
// Remove banner ad when playstate is destroyed.
#if NO_DISABLE_ADMOB_ADS
AdMobUtil.removeBanner();
#end
super.destroy();
}
+4 -4
View File
@@ -799,9 +799,9 @@ class ResultState extends MusicBeatSubState
if (params.storyMode)
{
// Shows a video ad on mobile devices each week victory.
// Shows a interstital ad on mobile devices each week victory.
#if NO_DISABLE_ADMOB_ADS
if (PlayStatePlaylist.isStoryMode) AdMobUtil.loadInterstitial(true);
if (PlayStatePlaylist.isStoryMode) AdMobUtil.loadInterstitial();
#end
if (PlayerRegistry.instance.hasNewCharacter())
@@ -837,11 +837,11 @@ class ResultState extends MusicBeatSubState
var isPersonalBest = rank > Scoring.calculateRank(params?.prevScoreData);
// Shows a video ad on mobile devices each 3 victories on freeplay.
// Shows a interstital ad on mobile devices each 3 victories on freeplay.
#if NO_DISABLE_ADMOB_ADS
Constants.GLOBAL_FREEPLAY_VICTORY_COUNTER++;
if ((Constants.GLOBAL_FREEPLAY_VICTORY_COUNTER > 0
&& Constants.GLOBAL_FREEPLAY_VICTORY_COUNTER % 3 == 0)) AdMobUtil.loadInterstitial(true);
&& Constants.GLOBAL_FREEPLAY_VICTORY_COUNTER % 3 == 0)) AdMobUtil.loadInterstitial();
#end
if (isScoreValid && isPersonalBest)
+2 -2
View File
@@ -591,13 +591,13 @@ class Constants
#if NO_DISABLE_ADMOB_ADS
/**
* A Counter that is increased by 1 each blueball.
* Only used for video ads each 3 blueballs on mobile.
* Only used for interstital ads each 3 blueballs on mobile.
*/
public static var GLOBAL_BLUEBALL_COUNTER:Int = 0;
/**
* A Counter that is increased by 1 each victory only in freep;ay songs.
* Only used for video ads each 3 victories on mobile.
* Only used for interstital ads each 3 victories on mobile.
*/
public static var GLOBAL_FREEPLAY_VICTORY_COUNTER:Int = 0;
#end