AdMobSettings.gd 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var AdMobLoad = preload("res://addons/admob/src/utils/AdMobLoad.gd")
  2. var AdMobSave = preload("res://addons/admob/src/utils/AdMobSave.gd")
  3. enum INITIALIZATION_STATUS {NOT_READY, READY}
  4. const PATH_ADMOB_PROJECT_SETTINGS = "admob/config"
  5. const BANNER_SIZE : Array = ["BANNER", "MEDIUM_RECTANGLE", "FULL_BANNER", "LEADERBOARD", "ADAPTIVE", "SMART_BANNER"]
  6. const MAX_AD_RATING : Array = ["G", "PG", "T", "MA"]
  7. enum POSITION {BOTTOM, TOP}
  8. var config : Dictionary = {
  9. "general" : {
  10. "is_enabled": true,
  11. "is_for_child_directed_treatment": false,
  12. "max_ad_content_rating": "PG"
  13. },
  14. "debug" : {
  15. "is_debug_on_release": false,
  16. "is_real": true,
  17. "is_test_europe_user_consent": false
  18. },
  19. "banner": {
  20. "position": POSITION.TOP,
  21. "respect_safe_area" : true,
  22. "show_instantly": true,
  23. "size": BANNER_SIZE[0],
  24. "unit_ids" : {
  25. "Android": {
  26. "standard" : "ca-app-pub-3940256099942544/6300978111",
  27. },
  28. "iOS": {
  29. "standard" : "ca-app-pub-3940256099942544/2934735716"
  30. }
  31. }
  32. },
  33. "interstitial": {
  34. "unit_ids" : {
  35. "Android": {
  36. "standard" : "ca-app-pub-3940256099942544/1033173712"
  37. },
  38. "iOS": {
  39. "standard" : "ca-app-pub-3940256099942544/4411468910"
  40. }
  41. }
  42. },
  43. "rewarded": {
  44. "unit_ids" : {
  45. "Android": {
  46. "standard" : "ca-app-pub-3940256099942544/5224354917"
  47. },
  48. "iOS": {
  49. "standard" : "ca-app-pub-3940256099942544/1712485313"
  50. }
  51. }
  52. },
  53. "rewarded_interstitial": {
  54. "unit_ids" : {
  55. "Android": {
  56. "standard" : "ca-app-pub-3940256099942544/5354046379"
  57. },
  58. "iOS": {
  59. "standard" : "ca-app-pub-3940256099942544/6978759866"
  60. }
  61. }
  62. }
  63. } setget set_config
  64. func _init():
  65. var config_project_settings : Dictionary = AdMobLoad.load_config(PATH_ADMOB_PROJECT_SETTINGS)
  66. merge_dir(config, config_project_settings)
  67. if Engine.editor_hint:
  68. save_config()
  69. func save_config():
  70. AdMobSave.save_config(PATH_ADMOB_PROJECT_SETTINGS, self.config)
  71. func set_config(value : Dictionary):
  72. config = value
  73. save_config()
  74. func merge_dir(target : Dictionary, patch : Dictionary):
  75. for key in patch:
  76. if target.has(key):
  77. var tv = target[key]
  78. if typeof(tv) == TYPE_DICTIONARY:
  79. merge_dir(tv, patch[key])
  80. else:
  81. target[key] = patch[key]
  82. else:
  83. target[key] = patch[key]
  84. static func pascal2snake(string : String) -> String:
  85. string = string.replacen("adformat", "")
  86. var result = PoolStringArray()
  87. for ch in string:
  88. if ch == ch.to_lower():
  89. result.append(ch)
  90. else:
  91. result.append('_'+ch.to_lower())
  92. result[0] = result[0][1]
  93. return result.join('')