Use "not" instead of the exclamation mark in GDScript files

Also add String casts
This commit is contained in:
Aaron Franke
2021-06-28 23:30:05 -04:00
parent 7bfc57d1ae
commit 7e129db12e
30 changed files with 67 additions and 66 deletions

View File

@@ -7,7 +7,7 @@ func _process(_delta):
var numbers = ""
var index = 0
for state in fsm_node.states_stack:
states_names += state.get_name() + "\n"
states_names += String(state.get_name()) + "\n"
numbers += str(index) + "\n"
index += 1
$States.text = states_names

View File

@@ -11,4 +11,4 @@ func _physics_process(_delta):
func _on_StateMachine_state_changed(current_state):
text = current_state.get_name()
text = String(current_state.get_name())

View File

@@ -6,7 +6,7 @@ const MASS = 10.0
const ARRIVE_DISTANCE = 10.0
export(float) var speed = 200.0
var _state = null
var _state = States.IDLE
var _path = []
var _target_point_world = Vector2()

View File

@@ -92,7 +92,7 @@ func _initialize_collision_shapes():
for node in $Shapes.get_children():
var body = node as PhysicsBody2D
var shape = body.shape_owner_get_shape(0, 0)
shape.resource_name = node.name.substr("RigidBody".length())
shape.resource_name = String(node.name).substr("RigidBody".length())
_collision_shapes.push_back(shape)

View File

@@ -25,7 +25,7 @@ func _physics_process(_delta):
for node in $Shapes.get_children():
var body = node as PhysicsBody2D
var space_state = body.get_world_2d().direct_space_state
var body_name = body.name.substr("RigidBody".length())
var body_name = String(body.name).substr("RigidBody".length())
Log.print_log("* Testing: %s" % body_name)
@@ -45,7 +45,7 @@ func _physics_process(_delta):
res = _add_raycast(space_state, center, center + Vector2(0, 40))
Log.print_log("Raycast inside: %s" % ("HIT" if res else "NO HIT"))
if body.name.ends_with("ConcavePolygon"):
if String(body.name).ends_with("ConcavePolygon"):
# Raycast inside an internal face.
center.x += 20
res = _add_raycast(space_state, center, center + Vector2(0, 40))

View File

@@ -91,7 +91,7 @@ func _on_option_selected(option):
func _find_type_index(type_name):
for type_index in range(_object_templates.size()):
var type_node = _object_templates[type_index]
if type_node.name.find(type_name) > -1:
if String(type_node.name).find(type_name) > -1:
return type_index
Log.print_error("Invalid shape type: " + type_name)

View File

@@ -9,7 +9,7 @@ var _down
onready var _screen_size_y = get_viewport_rect().size.y
func _ready():
var n = name.to_lower()
var n = String(name).to_lower()
_up = n + "_move_up"
_down = n + "_move_down"
if n == "left":

View File

@@ -65,7 +65,8 @@ right_move_up={
[rendering]
quality/driver/driver_name="GLES2"
quality/2d/use_pixel_snap=true
2d/snapping/use_gpu_pixel_snap=true
vram_compression/import_etc=true
vram_compression/import_etc2=false
quality/2d/use_pixel_snap=true
viewport/default_clear_color=Color( 0, 0, 0, 1 )

View File

@@ -8,9 +8,9 @@ onready var pictures = $Pictures
func _ready():
for c in pictures.get_children():
picture.add_item("PIC: " + c.get_name())
picture.add_item("PIC: " + String(c.get_name()))
for c in effects.get_children():
effect.add_item("FX: " + c.get_name())
effect.add_item("FX: " + String(c.get_name()))
func _on_picture_item_selected(ID):

View File

@@ -54,7 +54,7 @@ func _unhandled_input(ev):
func _process(delta):
var current_tester = testers.get_child(tester_index)
material_name.text = current_tester.get_name()
material_name.text = String(current_tester.get_name())
# This code assumes CameraHolder's Y and Z coordinates are already correct.
var target_position = current_tester.transform.origin.x
var current_position = camera_holder.transform.origin.x

View File

@@ -95,7 +95,7 @@ func _initialize_collision_shapes():
for node in $Shapes.get_children():
var body = node as PhysicsBody
var shape = body.shape_owner_get_shape(0, 0)
shape.resource_name = node.name.substr("RigidBody".length())
shape.resource_name = String(node.name).substr("RigidBody".length())
_collision_shapes.push_back(shape)

View File

@@ -87,7 +87,7 @@ func _on_option_selected(option):
func _find_type_index(type_name):
for type_index in range(_object_templates.size()):
var type_node = _object_templates[type_index]
if type_node.name.find(type_name) > -1:
if String(type_node.name).find(type_name) > -1:
return type_index
Log.print_error("Invalid shape type: " + type_name)

View File

@@ -49,13 +49,13 @@ func _physics_process(dt):
var col = ds.intersect_ray(target, target + delta, collision_exception)
var col_right = ds.intersect_ray(target, target + Basis(Vector3.UP, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
if !col.empty():
if not col.empty():
# If main ray was occluded, get camera closer, this is the worst case scenario.
delta = col.position - target
elif !col_left.empty() and col_right.empty():
elif not col_left.empty() and col_right.empty():
# If only left ray is occluded, turn the camera around to the right.
delta = Basis(Vector3.UP, deg2rad(-dt * autoturn_speed)).xform(delta)
elif col_left.empty() and !col_right.empty():
elif col_left.empty() and not col_right.empty():
# If only right ray is occluded, turn the camera around to the left.
delta = Basis(Vector3.UP, deg2rad(dt *autoturn_speed)).xform(delta)
# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn.

View File

@@ -56,7 +56,7 @@ func _physics_process(delta):
if is_on_floor():
var sharp_turn = hspeed > 0.1 and rad2deg(acos(dir.dot(hdir))) > SHARP_TURN_THRESHOLD
if dir.length() > 0.1 and !sharp_turn:
if dir.length() > 0.1 and not sharp_turn:
if hspeed > 0.001:
hdir = adjust_facing(hdir, dir, delta, 1.0 / hspeed * TURN_SPEED, Vector3.UP)
else:

View File

@@ -7,7 +7,7 @@ onready var voxel_world = $"../VoxelWorld"
func _process(_delta):
if Input.is_action_just_pressed("debug"):
visible = !visible
visible = not visible
text = "Position: " + _vector_to_string_appropriate_digits(player.transform.origin)
text += "\nEffective render distance: " + str(voxel_world.effective_render_distance)

View File

@@ -11,7 +11,7 @@ onready var voxel_world = $"../VoxelWorld"
func _process(_delta):
if Input.is_action_just_pressed("pause"):
pause.visible = crosshair.visible
crosshair.visible = !crosshair.visible
crosshair.visible = not crosshair.visible
options.visible = false
if crosshair.visible:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

View File

@@ -27,7 +27,7 @@ func strsec(secs):
func _process(_delta):
if !playing or !$Player.playing:
if not playing or not $Player.playing:
return
var time = 0.0

View File

@@ -23,14 +23,14 @@ onready var lines_root = $Lines
onready var lines = [$Lines/X, $Lines/Y, $Lines/Z]
func _process(_delta):
if !lines:
if not lines:
return # Somehow this node hasn't been set up yet.
if !node_25d:
if not node_25d:
return # We're most likely viewing the Gizmo25D scene.
# While getting the mouse position works in any viewport, it doesn't do
# anything significant unless the mouse is in the 2.5D viewport.
var mouse_position = get_local_mouse_position()
if !_moving:
if not _moving:
# If the mouse is farther than this many pixels, it won't grab anything.
var closest_distance = 20.0
dominant_axis = -1
@@ -46,9 +46,9 @@ func _process(_delta):
return
lines[dominant_axis].modulate.a = 1
if !wants_to_move:
if not wants_to_move:
_moving = false
elif wants_to_move and !_moving:
elif wants_to_move and not _moving:
_moving = true
_start_position = mouse_position
@@ -90,7 +90,7 @@ func initialize():
# specialized for this script, it assumes that each segment starts at
# (0, 0) and it provides a deadzone around the origin.
func _distance_to_segment_at_index(index, point):
if !lines:
if not lines:
return INF
if point.length_squared() < 400:
return INF

View File

@@ -21,7 +21,7 @@ func _ready():
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
var edited_scene_root = get_tree().edited_scene_root
if !edited_scene_root:
if not edited_scene_root:
# Godot hasn't finished loading yet, so try loading the plugin again.
editor_interface.set_plugin_enabled("node25d", false)
editor_interface.set_plugin_enabled("node25d", true)
@@ -34,7 +34,7 @@ func _ready():
func _process(delta):
if !editor_interface: # Something's not right... bail!
if not editor_interface: # Something's not right... bail!
return
# View mode polling.
@@ -70,9 +70,9 @@ func _process(delta):
for overlay_child in overlay_children:
var contains = false
for selected in selection:
if selected == overlay_child.node_25d and !view_mode_changed_this_frame:
if selected == overlay_child.node_25d and not view_mode_changed_this_frame:
contains = true
if !contains:
if not contains:
overlay_child.queue_free()
# Add new gizmos.

View File

@@ -60,7 +60,7 @@ func get_basis():
func get_spatial_position():
if !_spatial_node:
if not _spatial_node:
_spatial_node = get_child(0)
return _spatial_node.translation

View File

@@ -16,7 +16,7 @@ func _process(delta):
return
if Input.is_action_just_pressed("toggle_isometric_controls"):
isometric_controls = !isometric_controls
isometric_controls = not isometric_controls
if Input.is_action_just_pressed("reset_position"):
transform = Transform(Basis(), Vector3.UP * 10)
vertical_speed = 0

View File

@@ -103,7 +103,7 @@ func _check_movement() -> bool:
# Check for isometric controls and add more to movement accordingly.
# For efficiency, only check the X axis since this X axis value isn't used anywhere else.
if !_parent_math.isometric_controls and is_equal_approx(Node25D.SCALE * 0.86602540378, _parent_node25d.get_basis()[0].x):
if not _parent_math.isometric_controls and is_equal_approx(Node25D.SCALE * 0.86602540378, _parent_node25d.get_basis()[0].x):
if Input.is_action_pressed("move_right"):
z += 1
if Input.is_action_pressed("move_left"):

View File

@@ -2,4 +2,4 @@ extends Control
func _process(_delta):
if Input.is_action_just_pressed("toggle_control_hints"):
visible = !visible
visible = not visible

View File

@@ -16,7 +16,7 @@ func _physics_process(_delta):
modetext += "Fullscreen\n"
else:
modetext += "Windowed\n"
if !OS.is_window_resizable():
if not OS.is_window_resizable():
modetext += "FixedSize\n"
if OS.is_window_minimized():
modetext += "Minimized\n"
@@ -55,7 +55,7 @@ func _physics_process(_delta):
$Label_Screen1_DPI.hide()
$Button_Fullscreen.set_pressed(OS.is_window_fullscreen())
$Button_FixedSize.set_pressed(!OS.is_window_resizable())
$Button_FixedSize.set_pressed(not OS.is_window_resizable())
$Button_Minimized.set_pressed(OS.is_window_minimized())
$Button_Maximized.set_pressed(OS.is_window_maximized())
$Button_MouseModeVisible.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE)
@@ -82,39 +82,39 @@ func _unhandled_input(event):
func check_wm_api():
var s = ""
if !OS.has_method("get_screen_count"):
if not OS.has_method("get_screen_count"):
s += " - get_screen_count()\n"
if !OS.has_method("get_current_screen"):
if not OS.has_method("get_current_screen"):
s += " - get_current_screen()\n"
if !OS.has_method("set_current_screen"):
if not OS.has_method("set_current_screen"):
s += " - set_current_screen()\n"
if !OS.has_method("get_screen_position"):
if not OS.has_method("get_screen_position"):
s += " - get_screen_position()\n"
if !OS.has_method("get_screen_size"):
if not OS.has_method("get_screen_size"):
s += " - get_screen_size()\n"
if !OS.has_method("get_window_position"):
if not OS.has_method("get_window_position"):
s += " - get_window_position()\n"
if !OS.has_method("set_window_position"):
if not OS.has_method("set_window_position"):
s += " - set_window_position()\n"
if !OS.has_method("get_window_size"):
if not OS.has_method("get_window_size"):
s += " - get_window_size()\n"
if !OS.has_method("set_window_size"):
if not OS.has_method("set_window_size"):
s += " - set_window_size()\n"
if !OS.has_method("set_window_fullscreen"):
if not OS.has_method("set_window_fullscreen"):
s += " - set_window_fullscreen()\n"
if !OS.has_method("is_window_fullscreen"):
if not OS.has_method("is_window_fullscreen"):
s += " - is_window_fullscreen()\n"
if !OS.has_method("set_window_resizable"):
if not OS.has_method("set_window_resizable"):
s += " - set_window_resizable()\n"
if !OS.has_method("is_window_resizable"):
if not OS.has_method("is_window_resizable"):
s += " - is_window_resizable()\n"
if !OS.has_method("set_window_minimized"):
if not OS.has_method("set_window_minimized"):
s += " - set_window_minimized()\n"
if !OS.has_method("is_window_minimized"):
if not OS.has_method("is_window_minimized"):
s += " - is_window_minimized()\n"
if !OS.has_method("set_window_maximized"):
if not OS.has_method("set_window_maximized"):
s += " - set_window_maximized()\n"
if !OS.has_method("is_window_maximized"):
if not OS.has_method("is_window_maximized"):
s += " - is_window_maximized()\n"
if s.length() == 0:

View File

@@ -28,7 +28,7 @@ func _input(event):
if event is InputEventMouseMotion:
r_pos = -event.relative
if event.is_action("ui_cancel") and event.is_pressed() and !event.is_echo():
if event.is_action("ui_cancel") and event.is_pressed() and not event.is_echo():
if (state == STATE_GRAB):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
state = STATE_MENU

View File

@@ -53,7 +53,7 @@ func _on_connected():
var query = payment.queryPurchases("inapp") # Use "subs" for subscriptions.
if query.status == OK:
for purchase in query.purchases:
if !purchase.is_acknowledged:
if not purchase.is_acknowledged:
print("Purchase " + str(purchase.sku) + " has not been acknowledged. Acknowledging...")
payment.acknowledgePurchase(purchase.purchase_token)
else:
@@ -70,7 +70,7 @@ func _on_purchases_updated(purchases):
# See _on_connected
for purchase in purchases:
if !purchase.is_acknowledged:
if not purchase.is_acknowledged:
print("Purchase " + str(purchase.sku) + " has not been acknowledged. Acknowledging...")
payment.acknowledgePurchase(purchase.purchase_token)

View File

@@ -24,8 +24,8 @@ func _ready():
func _gui_input(event):
# We must start touching inside, but we can drag or unpress outside.
# if !(event is InputEventScreenDrag or
# (event is InputEventScreenTouch and (!event.pressed or get_global_rect().has_point(event.position)))):
# if not (event is InputEventScreenDrag or
# (event is InputEventScreenTouch and (not event.pressed or get_global_rect().has_point(event.position)))):
# return
var finger_count = base_state.size()
@@ -75,7 +75,7 @@ func _gui_input(event):
# Two fingers => To pinch-zoom and rotate around Z.
# Accept unpress or drag.
if event is InputEventScreenTouch:
if !event.pressed and base_state.has(event.index):
if not event.pressed and base_state.has(event.index):
# Some known touching finger released.
# Remove released finger from the base state.

View File

@@ -21,7 +21,7 @@ func _ready():
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
var edited_scene_root = get_tree().edited_scene_root
if !edited_scene_root:
if not edited_scene_root:
# Godot hasn't finished loading yet, so try loading the plugin again.
editor_interface.set_plugin_enabled("node25d", false)
editor_interface.set_plugin_enabled("node25d", true)
@@ -34,7 +34,7 @@ func _ready():
func _process(delta):
if !editor_interface: # Something's not right... bail!
if not editor_interface: # Something's not right... bail!
return
# View mode polling.
@@ -70,9 +70,9 @@ func _process(delta):
for overlay_child in overlay_children:
var contains = false
for selected in selection:
if selected == overlay_child.get("node25d") and !view_mode_changed_this_frame:
if selected == overlay_child.get("node25d") and not view_mode_changed_this_frame:
contains = true
if !contains:
if not contains:
overlay_child.queue_free()
# Add new gizmos.

View File

@@ -2,4 +2,4 @@ extends Control
func _process(_delta):
if Input.is_action_just_pressed("toggle_control_hints"):
visible = !visible
visible = not visible

View File

@@ -41,7 +41,7 @@ func _physics_process(_delta):
motion = Vector2()
if bombing and not prev_bombing:
var bomb_name = get_name() + str(bomb_index)
var bomb_name = String(get_name()) + str(bomb_index)
var bomb_pos = position
rpc("setup_bomb", bomb_name, bomb_pos, get_tree().get_network_unique_id())