Skip to content

Commit 375d5d1

Browse files
authored
Merge pull request #397 from aaronfranke/misc
Update and improve misc demos for Godot 3.1.2
2 parents c9d3646 + c90a251 commit 375d5d1

31 files changed

+309
-373
lines changed

misc/android_iap/iap.gd

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extends Node
32

43
signal purchase_success(item_name)
@@ -24,16 +23,16 @@ func _ready():
2423
print("GodotPayment singleton is only available on Android devices.")
2524

2625
if payment:
27-
# set callback with this script instance
26+
# Set callback with this script instance.
2827
payment.setPurchaseCallbackId(get_instance_id())
2928

30-
# set consume purchased item automatically after purchase, defulat value is true
29+
# Set consume purchased item automatically after purchase, default value is true.
3130
func set_auto_consume(auto):
3231
if payment:
3332
payment.setAutoConsume(auto)
3433

3534

36-
# request user owned item, callback : has_purchased
35+
# Request user owned item, callback: has_purchased.
3736
func request_purchased():
3837
if payment:
3938
payment.requestPurchased()
@@ -54,49 +53,57 @@ func purchase(item_name):
5453
# transaction_id could be any string that used for validation internally in java
5554
payment.purchase(item_name, "transaction_id")
5655

56+
5757
func purchase_success(_receipt, _signature, sku):
5858
print("purchase_success : ", sku)
5959
emit_signal("purchase_success", sku)
6060

61+
6162
func purchase_fail():
6263
print("purchase_fail")
6364
emit_signal("purchase_fail")
6465

66+
6567
func purchase_cancel():
6668
print("purchase_cancel")
6769
emit_signal("purchase_cancel")
6870

71+
6972
func purchase_owned(sku):
7073
print("purchase_owned : ", sku)
7174
emit_signal("purchase_owned", sku)
7275

7376

74-
# consume purchased item
75-
# callback : consume_success, consume_fail
77+
# Consume purchased item.
78+
# Callback: consume_success, consume_fail
7679
func consume(item_name):
7780
if payment:
7881
payment.consume(item_name)
7982

80-
# consume all purchased items
83+
84+
# Consume all purchased items.
8185
func consume_all():
8286
if payment:
8387
payment.consumeUnconsumedPurchases()
8488

89+
8590
func consume_success(_receipt, _signature, sku):
8691
print("consume_success : ", sku)
8792
emit_signal("consume_success", sku)
8893

89-
# if consume fail, need to call request_purchased() to get purchase token from google
90-
# then try to consume again
94+
95+
# If consume fails, need to call request_purchased() to get purchase token from Google.
96+
# Then try to consume again.
9197
func consume_fail():
9298
emit_signal("consume_fail")
9399

94-
# no purchased item to consume
100+
101+
# No purchased item to consume.
95102
func consume_not_required():
96103
emit_signal("consume_not_required")
97104

98105

99-
# detail info of IAP items
106+
# Detail info of IAP items:
100107
# sku_details = {
101108
# product_id (String) : {
102109
# type (String),
@@ -111,19 +118,21 @@ func consume_not_required():
111118
# }
112119
var sku_details = {}
113120

114-
# query for details of IAP items
115-
# callback : sku_details_complete
121+
# Query for details of IAP items.
122+
# Callback: sku_details_complete
116123
func sku_details_query(list):
117124
if payment:
118125
var sku_list = PoolStringArray(list)
119126
payment.querySkuDetails(sku_list)
120127

128+
121129
func sku_details_complete(result):
122130
print("sku_details_complete : ", result)
123131
for key in result.keys():
124132
sku_details[key] = result[key]
125133
emit_signal("sku_details_complete")
126134

135+
127136
func sku_details_error(error_message):
128137
print("error_sku_details = ", error_message)
129138
emit_signal("sku_details_error")

misc/android_iap/iap_demo.gd

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extends Control
32

43
onready var alert = get_node("alert")
@@ -24,47 +23,56 @@ func on_purchase_success(item_name):
2423
alert.set_text("Purchase success : " + item_name)
2524
alert.popup()
2625

26+
2727
func on_purchase_fail():
2828
alert.set_text("Purchase fail")
2929
alert.popup()
3030

31+
3132
func on_purchase_cancel():
3233
alert.set_text("Purchase cancel")
3334
alert.popup()
3435

36+
3537
func on_purchase_owned(item_name):
36-
alert.set_text("Purchase owned : " + item_name)
38+
alert.set_text("Purchase owned: " + item_name)
3739
alert.popup()
3840

41+
3942
func on_has_purchased(item_name):
4043
if item_name == null:
4144
alert.set_text("Don't have purchased item")
4245
else:
43-
alert.set_text("Has purchased : " + item_name)
46+
alert.set_text("Has purchased: " + item_name)
4447
alert.popup()
4548

49+
4650
func on_consume_success(item_name):
47-
alert.set_text("Consume success : " + item_name)
51+
alert.set_text("Consume success: " + item_name)
4852
alert.popup()
4953

54+
5055
func on_consume_fail():
5156
alert.set_text("Try to request purchased first")
5257
alert.popup()
5358

59+
5460
func on_sku_details_complete():
55-
alert.set_text("Got detail info : " + to_json(iap.sku_details["item_test_a"]))
61+
alert.set_text("Got detail info: " + to_json(iap.sku_details["item_test_a"]))
5662
alert.popup()
5763

5864

5965
func button_purchase():
6066
iap.purchase("item_tess")
6167

68+
6269
func button_consume():
6370
iap.consume("item_tess")
6471

72+
6573
func button_request():
6674
iap.request_purchased()
6775

76+
6877
func button_query():
6978
iap.sku_details_query(["item_test_a", "item_test_b"])
70-

misc/android_iap/icon.png

1.05 KB
Loading

misc/android_iap/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ modules="org/godotengine/godot/GodotPaymentV3"
1919

2020
[application]
2121

22-
config/name="Android IAP"
22+
config/name="Android in-app purchases"
2323
run/main_scene="res://main.tscn"
2424
config/icon="res://icon.png"
2525

misc/instancing/ball.tscn

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ bounce = 0.4
88
[sub_resource type="CircleShape2D" id=2]
99
radius = 30.0
1010

11-
[node name="ball" type="RigidBody2D"]
11+
[node name="Ball" type="RigidBody2D"]
1212
physics_material_override = SubResource( 1 )
1313

14-
[node name="sprite" type="Sprite" parent="."]
14+
[node name="Sprite" type="Sprite" parent="."]
1515
texture = ExtResource( 1 )
1616

17-
[node name="collision" type="CollisionShape2D" parent="."]
17+
[node name="Collision" type="CollisionShape2D" parent="."]
1818
shape = SubResource( 2 )
19-

misc/instancing/ball_factory.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extends Position2D
1+
extends Node2D
22

3-
export (PackedScene) var ball_scene = preload("res://ball.tscn")
3+
export(PackedScene) var ball_scene = preload("res://ball.tscn")
44

55
func _unhandled_input(event):
66
if event.is_echo():
@@ -10,7 +10,7 @@ func _unhandled_input(event):
1010
spawn(get_global_mouse_position())
1111

1212

13-
func spawn(spawn_global_position = global_position):
13+
func spawn(spawn_global_position):
1414
var instance = ball_scene.instance()
1515
instance.global_position = spawn_global_position
1616
add_child(instance)

misc/instancing/project.godot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ _global_script_class_icons={
1616
[application]
1717

1818
config/name="Scene Instancing Demo"
19-
run/main_scene="res://container.tscn"
19+
run/main_scene="res://scene_instancing.tscn"
2020
config/icon="res://icon.png"
2121

2222
[display]
@@ -35,4 +35,4 @@ singletons=[ ]
3535

3636
[rendering]
3737

38-
environment/default_clear_color=Color( 0.290196, 0.160784, 0.160784, 1 )
38+
environment/default_clear_color=Color( 0.301961, 0.301961, 0.301961, 1 )

misc/instancing/container.tscn renamed to misc/instancing/scene_instancing.tscn

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,57 @@ bounce = 0.4
3333
[sub_resource type="PhysicsMaterial" id=10]
3434
bounce = 0.4
3535

36-
[node name="container" type="Node"]
36+
[node name="SceneInstancing" type="Node2D"]
3737

38-
[node name="ball_factory" type="Position2D" parent="."]
38+
[node name="BallFactory" type="Node2D" parent="."]
3939
script = ExtResource( 1 )
4040

41-
[node name="static" type="StaticBody2D" parent="."]
41+
[node name="Static" type="StaticBody2D" parent="."]
4242

43-
[node name="collision" type="CollisionPolygon2D" parent="static"]
43+
[node name="Collision" type="CollisionPolygon2D" parent="Static"]
4444
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
4545

46-
[node name="polygon2d" type="Polygon2D" parent="static"]
46+
[node name="Polygon2D" type="Polygon2D" parent="Static"]
4747
color = Color( 1, 0.266667, 0.419608, 1 )
4848
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
4949

50-
[node name="ball 1" parent="." instance=ExtResource( 2 )]
50+
[node name="Ball1" parent="." instance=ExtResource( 2 )]
5151
position = Vector2( 223.823, 161.773 )
5252
physics_material_override = SubResource( 1 )
5353

54-
[node name="ball 2" parent="." instance=ExtResource( 2 )]
54+
[node name="Ball2" parent="." instance=ExtResource( 2 )]
5555
position = Vector2( 388.078, 213.215 )
5656
physics_material_override = SubResource( 2 )
5757

58-
[node name="ball 3" parent="." instance=ExtResource( 2 )]
58+
[node name="Ball3" parent="." instance=ExtResource( 2 )]
5959
position = Vector2( 439.52, 104.013 )
6060
physics_material_override = SubResource( 3 )
6161

62-
[node name="ball 4" parent="." instance=ExtResource( 2 )]
62+
[node name="Ball4" parent="." instance=ExtResource( 2 )]
6363
position = Vector2( 235.555, 336.858 )
6464
physics_material_override = SubResource( 4 )
6565

66-
[node name="ball 5" parent="." instance=ExtResource( 2 )]
66+
[node name="Ball5" parent="." instance=ExtResource( 2 )]
6767
position = Vector2( 509.555, 362.858 )
6868
physics_material_override = SubResource( 5 )
6969

70-
[node name="ball 6" parent="." instance=ExtResource( 2 )]
70+
[node name="Ball6" parent="." instance=ExtResource( 2 )]
7171
position = Vector2( 635.555, 147.858 )
7272
physics_material_override = SubResource( 6 )
7373

74-
[node name="ball 7" parent="." instance=ExtResource( 2 )]
74+
[node name="Ball7" parent="." instance=ExtResource( 2 )]
7575
position = Vector2( 631.872, 325.88 )
7676
physics_material_override = SubResource( 7 )
7777

78-
[node name="ball 8" parent="." instance=ExtResource( 2 )]
78+
[node name="Ball8" parent="." instance=ExtResource( 2 )]
7979
position = Vector2( 529.97, 205.561 )
8080
physics_material_override = SubResource( 8 )
8181

82-
[node name="ball 9" parent="." instance=ExtResource( 2 )]
82+
[node name="Ball9" parent="." instance=ExtResource( 2 )]
8383
position = Vector2( 101.489, 167.502 )
8484
physics_material_override = SubResource( 9 )
8585

86-
[node name="ball 10" parent="." instance=ExtResource( 2 )]
86+
[node name="Ball10" parent="." instance=ExtResource( 2 )]
8787
position = Vector2( 143.756, 295.139 )
8888
physics_material_override = SubResource( 10 )
8989

misc/joypads/joypads.gd

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@ extends Control
77
#
88
# Licensed under the MIT license
99

10-
# Member variables
10+
const DEADZONE = 0.2
11+
1112
var joy_num
1213
var cur_joy = -1
1314
var axis_value
1415

15-
const DEADZONE = 0.2
16+
func _ready():
17+
set_physics_process(true)
18+
Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
19+
1620

1721
func _physics_process(_delta):
18-
# Get the joypad device number from the spinbox
22+
# Get the joypad device number from the spinbox.
1923
joy_num = get_node("device_info/joy_num").get_value()
2024

21-
# Display the name of the joypad if we haven't already
25+
# Display the name of the joypad if we haven't already.
2226
if joy_num != cur_joy:
2327
cur_joy = joy_num
2428
get_node("device_info/joy_name").set_text(Input.get_joy_name(joy_num))
2529

26-
# Loop through the axes and show their current values
30+
# Loop through the axes and show their current values.
2731
for axis in range(JOY_AXIS_0, JOY_AXIS_MAX):
2832
axis_value = Input.get_joy_axis(joy_num, axis)
29-
get_node("axes/axis_prog" + str(axis)).set_value(100*axis_value)
33+
get_node("axes/axis_prog" + str(axis)).set_value(100 * axis_value)
3034
get_node("axes/axis_val" + str(axis)).set_text(str(axis_value))
3135
# Show joypad direction indicators
3236
if axis <= JOY_ANALOG_RY:
@@ -40,33 +44,31 @@ func _physics_process(_delta):
4044
get_node("diagram/axes/" + str(axis) + "+").hide()
4145
get_node("diagram/axes/" + str(axis) + "-").show()
4246

43-
# Loop through the buttons and highlight the ones that are pressed
47+
# Loop through the buttons and highlight the ones that are pressed.
4448
for btn in range(JOY_BUTTON_0, JOY_BUTTON_MAX):
4549
if Input.is_joy_button_pressed(joy_num, btn):
46-
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
50+
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color.white)
4751
get_node("diagram/buttons/" + str(btn)).show()
4852
else:
4953
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1))
5054
get_node("diagram/buttons/" + str(btn)).hide()
5155

52-
func _ready():
53-
set_physics_process(true)
54-
Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
5556

56-
#Called whenever a joypad has been connected or disconnected.
57+
# Called whenever a joypad has been connected or disconnected.
5758
func _on_joy_connection_changed(device_id, connected):
5859
if device_id == cur_joy:
5960
if connected:
6061
get_node("device_info/joy_name").set_text(Input.get_joy_name(device_id))
6162
else:
6263
get_node("device_info/joy_name").set_text("")
6364

65+
6466
func _on_start_vibration_pressed():
6567
var weak = get_node("vibration/vibration_weak_value").get_value()
6668
var strong = get_node("vibration/vibration_strong_value").get_value()
6769
var duration = get_node("vibration/vibration_duration_value").get_value()
68-
6970
Input.start_joy_vibration(cur_joy, weak, strong, duration)
7071

72+
7173
func _on_stop_vibration_pressed():
7274
Input.stop_joy_vibration(cur_joy)

misc/multitouch_cubes/CubeScene.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ near = 0.1
2727

2828
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
2929
environment = ExtResource( 1 )
30-

0 commit comments

Comments
 (0)