From c90a2514458b7349fef38309688c2abd56ddff25 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sun, 2 Feb 2020 04:52:41 -0500 Subject: [PATCH] Update the rest of the misc demos to Godot 3.1.2 I have not tested if these work, but I made minimal changes to them (only things like comments and newlines). --- misc/android_iap/iap.gd | 35 +++++++++----- misc/android_iap/iap_demo.gd | 20 +++++--- misc/android_iap/icon.png | Bin 1047 -> 2121 bytes misc/android_iap/project.godot | 2 +- misc/joypads/joypads.gd | 28 ++++++----- misc/multitouch_cubes/CubeScene.tscn | 1 - misc/multitouch_cubes/GestureArea.gd | 64 ++++++++++++------------- misc/multitouch_cubes/Main.tscn | 13 ----- misc/multitouch_cubes/default_env.tres | 1 - misc/multitouch_view/Main.gd | 10 ++-- misc/multitouch_view/Main.tscn | 1 - misc/multitouch_view/default_env.tres | 1 - misc/multitouch_view/icon.png.import | 3 ++ 13 files changed, 91 insertions(+), 88 deletions(-) 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 c95432a38f68f41b1994acc64372fcf9f0fd37ff..0d23bff0bd5fea12a63aa3b8b151dadc4a272658 100644 GIT binary patch delta 2119 zcmV-N2)Or`2+0tT8Gi-<0063Kaozv`2oOm`K~#9!N(3A@{j94)XviTT1?w0)&yx9h!(++_ec5(0$PIKbK zrf`EL7Oa@D3vDC{9MC6L833%9u`>W=4ldnE%M1Wk%-97xEKPRJg1L<(3c~;Dn3);E z%*@QpoG6@_F@MYqW@cu`%*=M5zHlV1LXss{U01#G*3P`{p6A-#nb9~?@T)OPwP^bZ z{WELhOZ)yadn0|xajGZAOgOCoKTce!LjhNmo?EQGzCHo|244#`%%P1wpx6AD+(QAE z;Tkvv7`1qZZbv4mr>94~y?sh5uGh(sJWcb8m1kJK7=Pff1zWB1xJMg(=u1wrITsGN z;Dp<)3-HzGC8}?1R()%y{2~iA{7|^Q-FD|`{J!VD8r!;bKQ`4WH^h98w%^Qsp38v) zE;!*v!+i^|=}4f!zXw7wZ!?bG%jG|+XB1Yk%pKCAjy?u6u@gZ~`>kwg59X91@t}9gAthSQ?z9JvXwn?tCi2HTUf1zzNWB z+XC>C0?ST48I0osPJo6>3-Ix<`TAq}I@^!HZZCn&m(m?x05|~}Hnj1CH|G}M^o=k9 za6cwRzdtU-C&L!#;@xP0{HkV+J09im0>BA3Kz|F(Cj-X|0C;pt0rvY|6z~o&(BV5d zYU$`!XIHnp&fQjaL5X^LAAQ4r+;JDfP6@cZ!V1trQ{LxqtIO;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bva2}B_}Z9fuAuv zN>Ou;Jy2wGm$QbZzI>jz*Wu~^|Nr&(`LDy%XpgRut;6i_^naVR$>Hhm!_(jA=jU*6 zaICDX^Yin3e0+$Ah|kZ@xy#wx+uKY`OhG_GWMpK_+T@_1pu@w%q`c0!xVTtYSRNWA z9vUJ!NnHG}P6+@2010$bPE!D1tl#7Di`t_wM(~Zra}i&qZ@nyB%3~_L2LF-On1`-n4El z8?I(sP2z(MgV-NTfB*3>XgRLu_ZDuuf6sV;hyofRB1W;(Ey$~|K;yd!N)a5SSmO*d z*0}-jfP)gDlAIY~1bu;K1da{Rjk;F=sE?2t0@lr)A%D=3fbQ&<4nqbJl&h@LkuuSE3L zA1LR4-+%h_Y5z_Om7J*mOvm){sq{ib4}F0LqTT+J^qIaim;I(L?(3(@H=^%-fr9AA zr`r2i&0SLe`}wKzOfudZ_^JZ0)Cqj5ZHS&O34hEDfmL4sS41zLq%9R%0O!^1{q%E3 z<7sbTI<98eZ|M#7Ktb>F@z+E%!xQOoN%ZJj-pUU`sN#j*<{Onz! zGMy96-yYB$(99;^r`V+j92}qxa0ZNLc%8)afz<(l7;wntH$%Kc7FCZg0{o={r7DmD zIDb4&Ok=yA0AN)hMEni+CjlYfo z&G%)Xdn`&Blo&e-i0WG+I(t4Sg{TRG+<)_%uFC{3hf462fF>~LjKM(#1{Sz}(8Oy* z4uA^Wfg-LLB4_Pk+kys7-47mv(B%5 zewv5T*>{4@&ShF$g~)6CqhRLMb@1x@Uo79I_20f^{r?-}Eclt8zH#gT0000 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]