From 0c42035e2ae5da3c9348b5ad5595f6fccb63d0af Mon Sep 17 00:00:00 2001 From: Christen Lofland <christen@lofland.net> Date: Sun, 14 Jan 2024 22:10:36 -0600 Subject: [PATCH] Formatting and types --- .../MapTileModificationParticlesController.gd | 37 ++++++++++--------- Server Camera/ServerCameraController.gd | 2 +- global_variables.gd | 20 +++++----- helper_functions.gd | 2 +- network_websocket.gd | 2 +- player/PlayerController.gd | 4 +- player/PlayerInteractionController.gd | 30 +++++++-------- player/PlayerInventoryManager.gd | 16 ++++---- player/skeleton_fixer.gd | 10 ++--- startup.gd | 4 +- 10 files changed, 64 insertions(+), 63 deletions(-) diff --git a/Items/Map/MapTileModificationParticlesController.gd b/Items/Map/MapTileModificationParticlesController.gd index f6ad7cc..9e2cbad 100644 --- a/Items/Map/MapTileModificationParticlesController.gd +++ b/Items/Map/MapTileModificationParticlesController.gd @@ -6,7 +6,7 @@ var LocalImage: Image var Points: Array[Vector2] var Colors: Array[Color] -var ParticleCount = 0 +var ParticleCount: int = 0 @export var Map: TileMap @@ -15,26 +15,29 @@ func _ready() -> void: #emitting = true pass -func DestroyCell(Position: Vector2i, ID: Vector2i) -> void: - +func DestroyCell(Position: Vector2i, ID: Vector2i) -> void: var Atlas: TileSetAtlasSource = Map.tile_set.get_source(0) - var AtlasImage = Atlas.texture.get_image() - var TileImage = AtlasImage.get_region(Atlas.get_tile_texture_region(ID)) - - var PointsToSample = 1 - var PointsSampled = [] - while(PointsToSample > 0): - PointsToSample-=1 - var SamplePosition = Vector2i(randi_range(0,15),randi_range(0,15)) - while(SamplePosition in PointsSampled): - SamplePosition = Vector2i(randi_range(0,15),randi_range(0,15)) + var AtlasImage: Image = Atlas.texture.get_image() + var TileImage: Image = AtlasImage.get_region(Atlas.get_tile_texture_region(ID)) + + var PointsToSample: int = 1 + var PointsSampled: Array = [] + while PointsToSample > 0: + PointsToSample -= 1 + var SamplePosition: Vector2i = Vector2i(randi_range(0, 15), randi_range(0, 15)) + while SamplePosition in PointsSampled: + SamplePosition = Vector2i(randi_range(0, 15), randi_range(0, 15)) PointsSampled.append(SamplePosition) - var SampleColor = TileImage.get_pixel(SamplePosition.x,SamplePosition.y) - Points.append(Vector2(Position.x*16.0 + SamplePosition.x+0.5,Position.y*16.0 + SamplePosition.y+0.5)) + var SampleColor: Color = TileImage.get_pixel(SamplePosition.x, SamplePosition.y) + Points.append( + Vector2( + Position.x * 16.0 + SamplePosition.x + 0.5, + Position.y * 16.0 + SamplePosition.y + 0.5 + ) + ) Colors.append(SampleColor) - ParticleCount+=1 - + ParticleCount += 1 emission_points = Points emission_colors = Colors diff --git a/Server Camera/ServerCameraController.gd b/Server Camera/ServerCameraController.gd index f378929..b5a5aae 100644 --- a/Server Camera/ServerCameraController.gd +++ b/Server Camera/ServerCameraController.gd @@ -4,7 +4,7 @@ const MovementSpeed: float = 16.0 # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta): +func _process(_delta: float) -> void: var move: Vector2 = Vector2() var input: Vector3 = Vector3() diff --git a/global_variables.gd b/global_variables.gd index 854e570..83324ff 100644 --- a/global_variables.gd +++ b/global_variables.gd @@ -28,28 +28,28 @@ var last_toast: String = "" var initial_map_load_finished: bool = false #Resources -var ResourceIDs = {"Stone": 0, "Red Ore": 1} -var ResourceNames = {} +var ResourceIDs: Dictionary = {"Stone": 0, "Red Ore": 1} +var ResourceNames: Dictionary = {} -func GetResourceName(ID): +func GetResourceName(ID: String) -> Array: BuildResourcesDictionaries() return ResourceNames[ID] -func GetResourceID(Name): +func GetResourceID(Name: String) -> Array: BuildResourcesDictionaries() return ResourceIDs[Name] -var HasBuiltResourcesDistionary = false +var HasBuiltResourcesDictionary: bool = false -func BuildResourcesDictionaries(): - if !HasBuiltResourcesDistionary: - for Key in ResourceIDs.keys(): +func BuildResourcesDictionaries() -> void: + if !HasBuiltResourcesDictionary: + for Key: String in ResourceIDs.keys(): ResourceNames[ResourceIDs[Key]] = Key - HasBuiltResourcesDistionary = true + HasBuiltResourcesDictionary = true -var Players = {} +var Players: Dictionary = {} diff --git a/helper_functions.gd b/helper_functions.gd index 948af43..c068b9e 100644 --- a/helper_functions.gd +++ b/helper_functions.gd @@ -78,7 +78,7 @@ func quit_gracefully() -> void: print_rich( "[color=orange]Disconnecting clients and saving data before shutting down server...[/color]" ) - var server_label = get_node_or_null( + var server_label: Node = get_node_or_null( "/root/Main/Map/ServerCamera/CanvasLayer/Control/Label" ) if server_label: diff --git a/network_websocket.gd b/network_websocket.gd index 2d36d71..dc55ff0 100644 --- a/network_websocket.gd +++ b/network_websocket.gd @@ -84,7 +84,7 @@ func _ready() -> void: func load_level(scene: PackedScene) -> void: var level_parent: Node = get_tree().get_root().get_node("Main/Map") - for c in level_parent.get_children(): + for c: Node in level_parent.get_children(): level_parent.remove_child(c) c.queue_free() var game_scene: Node = scene.instantiate() diff --git a/player/PlayerController.gd b/player/PlayerController.gd index bfdf477..b040e30 100644 --- a/player/PlayerController.gd +++ b/player/PlayerController.gd @@ -31,7 +31,7 @@ func _ready() -> void: # "In this example, it will be set to 0 but you can set any other value." # I believe the default is 0.3, so anything from 0.0 to < 0.3 should help improve this situation # Feel free two tweak the number as you see fit. - var space = get_world_2d().space + var space: RID = get_world_2d().space PhysicsServer2D.space_set_param( space, PhysicsServer2D.SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION, 0.0 ) @@ -129,6 +129,6 @@ func _integrate_forces(state: PhysicsDirectBodyState2D) -> void: @export var InventoryManager: Node2D @rpc("any_peer", "call_remote", "reliable") -func AddInventoryData(Data) -> void: +func AddInventoryData(Data: int) -> void: if IsLocal: InventoryManager.AddData(Data) diff --git a/player/PlayerInteractionController.gd b/player/PlayerInteractionController.gd index b73efff..ca0e301 100644 --- a/player/PlayerInteractionController.gd +++ b/player/PlayerInteractionController.gd @@ -26,7 +26,7 @@ var SpawnedDebugObject: Node2D @export var Flipped: bool = false -func UpdateMiningParticleLength(): +func UpdateMiningParticleLength() -> void: var Extents: Vector3 = MiningParticles.process_material.get("emission_box_extents") Extents.x = MiningDistance @@ -38,7 +38,7 @@ func UpdateMiningParticleLength(): @export var HeadTarget: Node -func Initialize(Local: bool): +func Initialize(Local: bool) -> void: IsLocal = Local #set_process(IsLocal) @@ -112,10 +112,8 @@ func _process(_delta: float) -> void: @export var ArmTargetPosition: Node2D -const mouse_sensitivity = 10 - -func _input(event): +func _input(event: InputEvent) -> void: if event is InputEventMouseButton: if event.button_index == 1 and event.is_pressed(): if !mouse_left_down: @@ -133,26 +131,26 @@ var mouse_left_down: bool var MineCast: RayCast2D var MiningSpeed: float = 0.1 -var CurrentMiningTime = 100 +var CurrentMiningTime: float = 100 -func LeftMouseClicked(): +func LeftMouseClicked() -> void: if CurrentTool == 1: pass pass -func MineRaycast(): +func MineRaycast() -> void: if CurrentMiningTime > MiningSpeed: CurrentMiningTime = 0.0 - var space_state = get_world_2d().direct_space_state + var space_state: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state #var SpawnedDebugObject = DebugObject.instantiate() #get_node("/root").add_child(SpawnedDebugObject) #SpawnedDebugObject.global_position = Arm.global_position - var ArmPosition = Arm.global_position - var MiningParticleDistance = ( + var ArmPosition: Vector2 = Arm.global_position + var MiningParticleDistance: float = ( clamp( clamp(ArmPosition.distance_to(MousePosition), 0, InteractRange), 0.0, @@ -160,7 +158,7 @@ func MineRaycast(): ) / 2.0 ) - var query = PhysicsRayQueryParameters2D.create( + var query: PhysicsRayQueryParameters2D = PhysicsRayQueryParameters2D.create( ArmPosition, ( ArmPosition @@ -171,9 +169,9 @@ func MineRaycast(): ) ) query.exclude = [self] - var result = space_state.intersect_ray(query) - if len(result) > 0: - var HitPoint = result["position"] + var result: Dictionary = space_state.intersect_ray(query) + if result.size() > 0: + var HitPoint: Vector2 = result["position"] if result["collider"] is TileMap: Globals.WorldMap.MineCellAtPosition(HitPoint - result["normal"]) MiningParticleDistance = MiningParticles.global_position.distance_to(HitPoint) / 2.0 @@ -181,6 +179,6 @@ func MineRaycast(): MiningDistance = MiningParticleDistance -func RightMouseClicked(): +func RightMouseClicked() -> void: Globals.WorldMap.PlaceCellAtPosition(get_global_mouse_position()) pass diff --git a/player/PlayerInventoryManager.gd b/player/PlayerInventoryManager.gd index 80a017f..1c5116d 100644 --- a/player/PlayerInventoryManager.gd +++ b/player/PlayerInventoryManager.gd @@ -8,16 +8,16 @@ const MaxBarScale: float = 4 # Called when the node enters the scene tree for the first time. -func _ready(): +func _ready() -> void: #Round about because names dictionary isn't defined till request - for Key in Globals.ResourceIDs.keys(): + for Key: String in Globals.ResourceIDs.keys(): PowderResources[Key] = 0 var IsLocal: bool = false -func Initialize(NewIsLocal): +func Initialize(NewIsLocal: bool) -> void: IsLocal = NewIsLocal set_process(IsLocal) InventoryUpdated = true @@ -27,7 +27,7 @@ var InventoryUpdated: bool = false # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta): +func _process(_delta: float) -> void: if InventoryUpdated: StoneBar.scale.y = float(MaxBarScale) / float(MaxStone) * float(PowderResources["Stone"]) print(float(MaxBarScale) / float(MaxStone) * float(PowderResources["Stone"])) @@ -35,14 +35,14 @@ func _process(_delta): InventoryUpdated = false -#func AddResource(ID: Vector2i, Ammount: int): +#func AddResource(ID: Vector2i, Amount: int): # if ID.x == 0: # pass -func AddData(Data) -> void: - for Key in Data.keys(): - var Extra = PowderResources[Globals.GetResourceName(Key)] + Data[Key] - MaxStone +func AddData(Data: Dictionary) -> void: + for Key: String in Data.keys(): + var Extra: int = PowderResources[Globals.GetResourceName(Key)] + Data[Key] - MaxStone if Extra <= 0: PowderResources[Globals.GetResourceName(Key)] += Data[Key] else: diff --git a/player/skeleton_fixer.gd b/player/skeleton_fixer.gd index c30cd74..6d3073c 100644 --- a/player/skeleton_fixer.gd +++ b/player/skeleton_fixer.gd @@ -3,7 +3,7 @@ @tool extends Skeleton2D -@export var apply_all_local = false: +@export var apply_all_local: bool = false: set(val): apply_all_local = val _apply_all_skeleton_modifier_set_local_to_scene(get_modification_stack(), val, 0) @@ -11,9 +11,9 @@ extends Skeleton2D func _apply_all_skeleton_modifier_set_local_to_scene( stack: SkeletonModificationStack2D, boo: bool, level: int -): - var indent = "" - for k in range(0, level): +) -> void: + var indent: String = "" + for k: int in range(0, level): indent += " " if !stack: @@ -23,7 +23,7 @@ func _apply_all_skeleton_modifier_set_local_to_scene( stack.resource_local_to_scene = boo #print("%sSetting stack %s -> resource_local_to_scene = %s " % [indent, stack, boo]) - for idx in range(0, stack.modification_count): + for idx: int in range(0, stack.modification_count): var modification: SkeletonModification2D = stack.get_modification(idx) modification.resource_local_to_scene = boo #print("%sSetting modifier %s -> resource_local_to_scene = %s " % [indent, stack, boo]) diff --git a/startup.gd b/startup.gd index 0f720a9..95a28c8 100644 --- a/startup.gd +++ b/startup.gd @@ -23,7 +23,7 @@ func _init() -> void: # It also provides us with a unique "instance number" for each debug instance of the game run by the editor # https://gist.github.com/CrankyBunny/71316e7af809d7d4cf5ec6e2369a30b9 _instance_socket = TCPServer.new() - for n in range(0, 4): # Godot Editor only creates up to 4 instances maximum. + for n: int in range(0, 4): # Godot Editor only creates up to 4 instances maximum. if _instance_socket.listen(5000 + n) == OK: Globals.local_debug_instance_number = n break @@ -33,7 +33,7 @@ func _init() -> void: # print("We are instance number ", Globals.local_debug_instance_number) if OS.get_cmdline_user_args().size() > 0: - for arg in OS.get_cmdline_user_args(): + for arg: String in OS.get_cmdline_user_args(): var arg_array: Array = arg.split("=") if arg_array[0] == "server": print_rich("[color=green]Setting as server based on command line argument.[/color]")