Skip to content

Commit

Permalink
Merge pull request #111 from Poing-Studios/request-agent-v1
Browse files Browse the repository at this point in the history
chore: set requestAgent on plugin
  • Loading branch information
gumaciel authored Nov 11, 2023
2 parents dc9900b + d284ca8 commit 1ba287f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/admob/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="AdMob"
description="The AdMob of Plugin for Android and iOS."
author="Poing Studios"
version="v1.3.4"
version="v1.3.5"
script="src/core/AdMob.gd"
20 changes: 20 additions & 0 deletions addons/admob/src/core/AdMob.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@ extends EditorPlugin

var AdMobEditor : Control

class PoingAdMobEditorExportPlugin extends EditorExportPlugin:
const CFG_FILE_PATH := "res://addons/admob/plugin.cfg"

func _export_begin(features: PoolStringArray, is_debug: bool, path: String, flags: int) -> void:
var file := File.new()

if file.open(CFG_FILE_PATH, File.READ) == OK:
print("Exporting Poing AdMob '.cfg' file")
add_file(CFG_FILE_PATH, file.get_buffer(file.get_len()), false)
file.close()

func _get_name() -> String:
return "PoingAdMob"

var _exporter := PoingAdMobEditorExportPlugin.new()

func _enter_tree():
add_export_plugin(_exporter)

add_autoload_singleton("MobileAds", "res://addons/admob/src/singletons/MobileAds.gd")
AdMobEditor = load("res://addons/admob/src/core/AdMobEditor.tscn").instance()
get_editor_interface().get_editor_viewport().add_child(AdMobEditor)
AdMobEditor.hide()

func _exit_tree():
remove_export_plugin(_exporter)

remove_autoload_singleton("MobileAds")
get_editor_interface().get_editor_viewport().remove_child(AdMobEditor)
AdMobEditor.queue_free()
Expand Down
3 changes: 2 additions & 1 deletion addons/admob/src/singletons/AdMobSingleton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func initialize() -> void:
is_real = config.debug.is_real
is_test_europe_user_consent = config.debug.is_test_europe_user_consent

_plugin.initialize(config.general.is_for_child_directed_treatment, config.general.max_ad_content_rating, is_real, is_test_europe_user_consent)
var google_request_agent := "Godot-PoingStudios-"+PoingAdMobVersionHelper.new().version_formated
_plugin.initialize(config.general.is_for_child_directed_treatment, config.general.max_ad_content_rating, is_real, is_test_europe_user_consent, google_request_agent)



Expand Down
46 changes: 46 additions & 0 deletions addons/admob/version_helper.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# MIT License

# Copyright (c) 2023-present Poing Studios

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

class_name PoingAdMobVersionHelper
extends Object

var version_formated : String = _get_plugin_version_formated() setget set_version_formated

func set_version_formated(value : String) -> void:
version_formated = _get_plugin_version_formated()

static func _get_plugin_version_formated() -> String:
var plugin_config_file := ConfigFile.new()
var version: String = "v1.3.5" #redundancy

if plugin_config_file.load("res://addons/admob/plugin.cfg") == OK:
version = plugin_config_file.get_value("plugin", "version")
else:
push_error("Failed to load plugin.cfg")

var pattern = RegEx.new()
pattern.compile("(?:v)?(\\d+\\.\\d+\\.\\d+)")

var matchs : RegExMatch = pattern.search(version)
if matchs != null:
version = matchs.get_string(1)
return version
10 changes: 10 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

config_version=4

_global_script_classes=[ {
"base": "Object",
"class": "PoingAdMobVersionHelper",
"language": "GDScript",
"path": "res://addons/admob/version_helper.gd"
} ]
_global_script_class_icons={
"PoingAdMobVersionHelper": ""
}

[admob]

config={
Expand Down

0 comments on commit 1ba287f

Please sign in to comment.