diff --git a/misc/android_iap/iap.gd b/misc/android_iap/iap.gd index 220769cb..c920d9b3 100644 --- a/misc/android_iap/iap.gd +++ b/misc/android_iap/iap.gd @@ -1,4 +1,3 @@ - extends Node signal purchase_success(item_name) @@ -24,16 +23,16 @@ func _ready(): print("GodotPayment singleton is only available on Android devices.") if payment: - # set callback with this script instance + # Set callback with this script instance. payment.setPurchaseCallbackId(get_instance_id()) -# set consume purchased item automatically after purchase, defulat value is true +# Set consume purchased item automatically after purchase, default value is true. func set_auto_consume(auto): if payment: payment.setAutoConsume(auto) -# request user owned item, callback : has_purchased +# Request user owned item, callback: has_purchased. func request_purchased(): if payment: payment.requestPurchased() @@ -54,49 +53,57 @@ func purchase(item_name): # transaction_id could be any string that used for validation internally in java payment.purchase(item_name, "transaction_id") + func purchase_success(_receipt, _signature, sku): print("purchase_success : ", sku) emit_signal("purchase_success", sku) + func purchase_fail(): print("purchase_fail") emit_signal("purchase_fail") + func purchase_cancel(): print("purchase_cancel") emit_signal("purchase_cancel") + func purchase_owned(sku): print("purchase_owned : ", sku) emit_signal("purchase_owned", sku) -# consume purchased item -# callback : consume_success, consume_fail +# Consume purchased item. +# Callback: consume_success, consume_fail func consume(item_name): if payment: payment.consume(item_name) -# consume all purchased items + +# Consume all purchased items. func consume_all(): if payment: payment.consumeUnconsumedPurchases() + func consume_success(_receipt, _signature, sku): print("consume_success : ", sku) emit_signal("consume_success", sku) -# if consume fail, need to call request_purchased() to get purchase token from google -# then try to consume again + +# If consume fails, need to call request_purchased() to get purchase token from Google. +# Then try to consume again. func consume_fail(): emit_signal("consume_fail") -# no purchased item to consume + +# No purchased item to consume. func consume_not_required(): emit_signal("consume_not_required") -# detail info of IAP items +# Detail info of IAP items: # sku_details = { # product_id (String) : { # type (String), @@ -111,19 +118,21 @@ func consume_not_required(): # } var sku_details = {} -# query for details of IAP items -# callback : sku_details_complete +# Query for details of IAP items. +# Callback: sku_details_complete func sku_details_query(list): if payment: var sku_list = PoolStringArray(list) payment.querySkuDetails(sku_list) + func sku_details_complete(result): print("sku_details_complete : ", result) for key in result.keys(): sku_details[key] = result[key] emit_signal("sku_details_complete") + func sku_details_error(error_message): print("error_sku_details = ", error_message) emit_signal("sku_details_error") diff --git a/misc/android_iap/iap_demo.gd b/misc/android_iap/iap_demo.gd index eeab2635..dea73c71 100644 --- a/misc/android_iap/iap_demo.gd +++ b/misc/android_iap/iap_demo.gd @@ -1,4 +1,3 @@ - extends Control onready var alert = get_node("alert") @@ -24,47 +23,56 @@ func on_purchase_success(item_name): alert.set_text("Purchase success : " + item_name) alert.popup() + func on_purchase_fail(): alert.set_text("Purchase fail") alert.popup() + func on_purchase_cancel(): alert.set_text("Purchase cancel") alert.popup() + func on_purchase_owned(item_name): - alert.set_text("Purchase owned : " + item_name) + alert.set_text("Purchase owned: " + item_name) alert.popup() + func on_has_purchased(item_name): if item_name == null: alert.set_text("Don't have purchased item") else: - alert.set_text("Has purchased : " + item_name) + alert.set_text("Has purchased: " + item_name) alert.popup() + func on_consume_success(item_name): - alert.set_text("Consume success : " + item_name) + alert.set_text("Consume success: " + item_name) alert.popup() + func on_consume_fail(): alert.set_text("Try to request purchased first") alert.popup() + func on_sku_details_complete(): - alert.set_text("Got detail info : " + to_json(iap.sku_details["item_test_a"])) + alert.set_text("Got detail info: " + to_json(iap.sku_details["item_test_a"])) alert.popup() func button_purchase(): iap.purchase("item_tess") + func button_consume(): iap.consume("item_tess") + func button_request(): iap.request_purchased() + func button_query(): iap.sku_details_query(["item_test_a", "item_test_b"]) - diff --git a/misc/android_iap/icon.png b/misc/android_iap/icon.png index c95432a3..0d23bff0 100644 Binary files a/misc/android_iap/icon.png and b/misc/android_iap/icon.png differ diff --git a/misc/android_iap/project.godot b/misc/android_iap/project.godot index b1615740..48ec31b4 100644 --- a/misc/android_iap/project.godot +++ b/misc/android_iap/project.godot @@ -19,7 +19,7 @@ modules="org/godotengine/godot/GodotPaymentV3" [application] -config/name="Android IAP" +config/name="Android in-app purchases" run/main_scene="res://main.tscn" config/icon="res://icon.png" diff --git a/misc/joypads/joypads.gd b/misc/joypads/joypads.gd index 7b67ef53..0b73caa5 100644 --- a/misc/joypads/joypads.gd +++ b/misc/joypads/joypads.gd @@ -7,26 +7,30 @@ extends Control # # Licensed under the MIT license -# Member variables +const DEADZONE = 0.2 + var joy_num var cur_joy = -1 var axis_value -const DEADZONE = 0.2 +func _ready(): + set_physics_process(true) + Input.connect("joy_connection_changed", self, "_on_joy_connection_changed") + func _physics_process(_delta): - # Get the joypad device number from the spinbox + # Get the joypad device number from the spinbox. joy_num = get_node("device_info/joy_num").get_value() - # Display the name of the joypad if we haven't already + # Display the name of the joypad if we haven't already. if joy_num != cur_joy: cur_joy = joy_num get_node("device_info/joy_name").set_text(Input.get_joy_name(joy_num)) - # Loop through the axes and show their current values + # Loop through the axes and show their current values. for axis in range(JOY_AXIS_0, JOY_AXIS_MAX): axis_value = Input.get_joy_axis(joy_num, axis) - get_node("axes/axis_prog" + str(axis)).set_value(100*axis_value) + get_node("axes/axis_prog" + str(axis)).set_value(100 * axis_value) get_node("axes/axis_val" + str(axis)).set_text(str(axis_value)) # Show joypad direction indicators if axis <= JOY_ANALOG_RY: @@ -40,20 +44,17 @@ func _physics_process(_delta): get_node("diagram/axes/" + str(axis) + "+").hide() get_node("diagram/axes/" + str(axis) + "-").show() - # Loop through the buttons and highlight the ones that are pressed + # Loop through the buttons and highlight the ones that are pressed. for btn in range(JOY_BUTTON_0, JOY_BUTTON_MAX): if Input.is_joy_button_pressed(joy_num, btn): - get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1)) + get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color.white) get_node("diagram/buttons/" + str(btn)).show() else: get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1)) get_node("diagram/buttons/" + str(btn)).hide() -func _ready(): - set_physics_process(true) - Input.connect("joy_connection_changed", self, "_on_joy_connection_changed") -#Called whenever a joypad has been connected or disconnected. +# Called whenever a joypad has been connected or disconnected. func _on_joy_connection_changed(device_id, connected): if device_id == cur_joy: if connected: @@ -61,12 +62,13 @@ func _on_joy_connection_changed(device_id, connected): else: get_node("device_info/joy_name").set_text("") + func _on_start_vibration_pressed(): var weak = get_node("vibration/vibration_weak_value").get_value() var strong = get_node("vibration/vibration_strong_value").get_value() var duration = get_node("vibration/vibration_duration_value").get_value() - Input.start_joy_vibration(cur_joy, weak, strong, duration) + func _on_stop_vibration_pressed(): Input.stop_joy_vibration(cur_joy) diff --git a/misc/multitouch_cubes/CubeScene.tscn b/misc/multitouch_cubes/CubeScene.tscn index 2d48955a..7f2831b1 100644 --- a/misc/multitouch_cubes/CubeScene.tscn +++ b/misc/multitouch_cubes/CubeScene.tscn @@ -27,4 +27,3 @@ near = 0.1 [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = ExtResource( 1 ) - diff --git a/misc/multitouch_cubes/GestureArea.gd b/misc/multitouch_cubes/GestureArea.gd index c6896cf7..01479321 100644 --- a/misc/multitouch_cubes/GestureArea.gd +++ b/misc/multitouch_cubes/GestureArea.gd @@ -13,7 +13,7 @@ var curr_state var target_node -# We keep here a copy of the state before the number of fingers changed to avoid accumulation errors +# We keep here a copy of the state before the number of fingers changed to avoid accumulation errors. var base_xform func _ready(): @@ -21,8 +21,9 @@ func _ready(): curr_state = {} target_node = get_node(target) + func _gui_input(event): - # We must start touching inside, but we can drag or unpress outside + # We must start touching inside, but we can drag or unpress outside. # if !(event is InputEventScreenDrag || # (event is InputEventScreenTouch && (!event.pressed || get_global_rect().has_point(event.position)))): # return @@ -30,101 +31,96 @@ func _gui_input(event): var finger_count = base_state.size() if finger_count == 0: - # No fingers => Accept press - + # No fingers => Accept press. if event is InputEventScreenTouch: if event.pressed: - # A finger started touching + # A finger started touching. base_state = { event.index: event.position, } elif finger_count == 1: - # One finger => For rotating around X and Y - # Accept one more press, unpress or drag - + # One finger => For rotating around X and Y. + # Accept one more press, unpress or drag. if event is InputEventScreenTouch: if event.pressed: - # One more finger started touching + # One more finger started touching. - # Reset the base state to the only current and the new fingers + # Reset the base state to the only current and the new fingers. base_state = { curr_state.keys()[0]: curr_state.values()[0], event.index: event.position, } else: if base_state.has(event.index): - # Only touching finger released + # Only touching finger released. base_state.clear() elif event is InputEventScreenDrag: if curr_state.has(event.index): - # Touching finger dragged - + # Touching finger dragged. var unit_drag = _px2unit(base_state[base_state.keys()[0]] - event.position) if one_finger_rot_x: - target_node.global_rotate(Vector3(0, 1, 0), deg2rad(180.0 * unit_drag.x)) + target_node.global_rotate(Vector3.UP, deg2rad(180.0 * unit_drag.x)) if one_finger_rot_y: - target_node.global_rotate(Vector3(1, 0, 0), deg2rad(180.0 * unit_drag.y)) - # Since rotating around two axes, we have to reset the base constantly + target_node.global_rotate(Vector3.RIGHT, deg2rad(180.0 * unit_drag.y)) + # Since rotating around two axes, we have to reset the base constantly. curr_state[event.index] = event.position base_state[event.index] = event.position base_xform = target_node.get_transform() elif finger_count == 2: - # Two fingers => To pinch-zoom and rotate around Z - # Accept unpress or drag - + # Two fingers => To pinch-zoom and rotate around Z. + # Accept unpress or drag. if event is InputEventScreenTouch: if !event.pressed && base_state.has(event.index): - # Some known touching finger released + # Some known touching finger released. - # Remove released finger from the base state + # Remove released finger from the base state. base_state.erase(event.index) - # Reset the base state to the now only toyching finger + # Reset the base state to the now only toyching finger. base_state = { curr_state.keys()[0]: curr_state.values()[0], } elif event is InputEventScreenDrag: if curr_state.has(event.index): - # Some known touching finger dragged - - # Update + # Some known touching finger dragged. curr_state[event.index] = event.position - # Compute base and current inter-finger vectors + # Compute base and current inter-finger vectors. var base_segment = base_state[base_state.keys()[0]] - base_state[base_state.keys()[1]] var new_segment = curr_state[curr_state.keys()[0]] - curr_state[curr_state.keys()[1]] - # Get the base scale from the base matrix + # Get the base scale from the base matrix. var base_scale = Vector3(base_xform.basis.x.x, base_xform.basis.y.y, base_xform.basis.z.z).length() if two_fingers_zoom: - # Compute the new scale limiting it and taking into account the base scale + # Compute the new scale limiting it and taking into account the base scale. var new_scale = clamp(base_scale * (new_segment.length() / base_segment.length()), min_scale, max_scale) / base_scale - target_node.set_transform(base_xform.scaled(new_scale * Vector3(1, 1, 1))) + target_node.set_transform(base_xform.scaled(new_scale * Vector3.ONE)) else: target_node.set_transform(base_xform) if two_fingers_rot_z: - # Apply rotation between base inter-finger vector and the current one + # Apply rotation between base inter-finger vector and the current one. var rot = new_segment.angle_to(base_segment) - target_node.global_rotate(Vector3(0, 0, 1), rot) + target_node.global_rotate(Vector3.BACK, rot) # Finger count changed? if base_state.size() != finger_count: - # Copy new base state to the current state + # Copy new base state to the current state. curr_state = {} for idx in base_state.keys(): curr_state[idx] = base_state[idx] - # Remember the base transform + # Remember the base transform. base_xform = target_node.get_transform() + # Converts a vector in pixels to a unitary magnitude, -# considering the number of pixels of the shorter axis is the unit +# considering the number of pixels of the shorter axis is the unit. func _px2unit(v): var shortest = min(get_size().x, get_size().y) return v * (1.0 / shortest) diff --git a/misc/multitouch_cubes/Main.tscn b/misc/multitouch_cubes/Main.tscn index 72a88a5c..696b1667 100644 --- a/misc/multitouch_cubes/Main.tscn +++ b/misc/multitouch_cubes/Main.tscn @@ -37,9 +37,6 @@ render_target_update_mode = 3 [node name="Spatial" parent="HBoxContainer/ViewportContainer/Viewport" instance=ExtResource( 2 )] -[node name="DirectionalLight" parent="HBoxContainer/ViewportContainer/Viewport/Spatial" index="1"] -light_cull_mask = 4294967295 - [node name="Camera" parent="HBoxContainer/ViewportContainer/Viewport/Spatial" index="2"] current = true @@ -72,9 +69,6 @@ render_target_update_mode = 3 [node name="Spatial" parent="HBoxContainer/ViewportContainer2/Viewport" instance=ExtResource( 2 )] -[node name="DirectionalLight" parent="HBoxContainer/ViewportContainer2/Viewport/Spatial" index="1"] -light_cull_mask = 4294967295 - [node name="Camera" parent="HBoxContainer/ViewportContainer2/Viewport/Spatial" index="2"] current = true @@ -112,9 +106,6 @@ render_target_update_mode = 3 [node name="Spatial" parent="HBoxContainer2/ViewportContainer/Viewport" instance=ExtResource( 2 )] -[node name="DirectionalLight" parent="HBoxContainer2/ViewportContainer/Viewport/Spatial" index="1"] -light_cull_mask = 4294967295 - [node name="Camera" parent="HBoxContainer2/ViewportContainer/Viewport/Spatial" index="2"] current = true @@ -145,9 +136,6 @@ render_target_update_mode = 3 [node name="Spatial" parent="HBoxContainer2/ViewportContainer2/Viewport" instance=ExtResource( 2 )] -[node name="DirectionalLight" parent="HBoxContainer2/ViewportContainer2/Viewport/Spatial" index="1"] -light_cull_mask = 4294967295 - [node name="Camera" parent="HBoxContainer2/ViewportContainer2/Viewport/Spatial" index="2"] current = true @@ -158,7 +146,6 @@ margin_right = 279.0 margin_bottom = 23.0 text = "One-finger X/Y, two-finger Z + pinch" - [editable path="HBoxContainer/ViewportContainer/Viewport/Spatial"] [editable path="HBoxContainer/ViewportContainer2/Viewport/Spatial"] diff --git a/misc/multitouch_cubes/default_env.tres b/misc/multitouch_cubes/default_env.tres index 2488177a..b8ab5c74 100644 --- a/misc/multitouch_cubes/default_env.tres +++ b/misc/multitouch_cubes/default_env.tres @@ -2,4 +2,3 @@ [resource] ambient_light_color = Color( 0.307434, 0.362682, 0.539063, 1 ) - diff --git a/misc/multitouch_view/Main.gd b/misc/multitouch_view/Main.gd index 976dabaf..d31d612d 100644 --- a/misc/multitouch_view/Main.gd +++ b/misc/multitouch_view/Main.gd @@ -1,20 +1,22 @@ extends Node2D func _process(_delta): - # To keep redrawing on every frame + # Keep redrawing on every frame. update() + func _draw(): - # Get the touch helper singleton + # Get the touch helper singleton. var touch_helper = get_node("/root/TouchHelper") - # Draw every pointer as a circle + # Draw every pointer as a circle. for ptr_id in touch_helper.state.keys(): var pos = touch_helper.state[ptr_id] var color = _get_color_for_ptr_id(ptr_id) color.a = 0.75 draw_circle(pos, 40.0, color) -# Just a way of getting different colors + +# Just a way of getting different colors. func _get_color_for_ptr_id(id): var x = (id % 7) + 1 return Color(float(bool(x & 1)), float(bool(x & 2)), float(bool(x & 4))) diff --git a/misc/multitouch_view/Main.tscn b/misc/multitouch_view/Main.tscn index 8b6acc9b..cc043c2f 100644 --- a/misc/multitouch_view/Main.tscn +++ b/misc/multitouch_view/Main.tscn @@ -4,4 +4,3 @@ [node name="Main" type="Node2D"] script = ExtResource( 1 ) - diff --git a/misc/multitouch_view/default_env.tres b/misc/multitouch_view/default_env.tres index 4b7cb0ac..d37b59de 100644 --- a/misc/multitouch_view/default_env.tres +++ b/misc/multitouch_view/default_env.tres @@ -11,4 +11,3 @@ ground_curve = 0.01 [resource] background_mode = 2 background_sky = SubResource( 1 ) - diff --git a/misc/multitouch_view/icon.png.import b/misc/multitouch_view/icon.png.import index 45ee6af7..96cbf462 100644 --- a/misc/multitouch_view/icon.png.import +++ b/misc/multitouch_view/icon.png.import @@ -3,6 +3,9 @@ importer="texture" type="StreamTexture" path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} [deps]