Skip to content

Commit

Permalink
Formatting and types
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisl8 committed Jan 15, 2024
1 parent 22240b8 commit 0c42035
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 63 deletions.
37 changes: 20 additions & 17 deletions Items/Map/MapTileModificationParticlesController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Server Camera/ServerCameraController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions global_variables.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
2 changes: 1 addition & 1 deletion helper_functions.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion network_websocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions player/PlayerController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
30 changes: 14 additions & 16 deletions player/PlayerInteractionController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -38,7 +38,7 @@ func UpdateMiningParticleLength():
@export var HeadTarget: Node


func Initialize(Local: bool):
func Initialize(Local: bool) -> void:
IsLocal = Local
#set_process(IsLocal)

Expand Down Expand Up @@ -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:
Expand All @@ -133,34 +131,34 @@ 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,
MiningParticles.global_position.distance_to(MousePosition)
)
/ 2.0
)
var query = PhysicsRayQueryParameters2D.create(
var query: PhysicsRayQueryParameters2D = PhysicsRayQueryParameters2D.create(
ArmPosition,
(
ArmPosition
Expand All @@ -171,16 +169,16 @@ 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

MiningDistance = MiningParticleDistance


func RightMouseClicked():
func RightMouseClicked() -> void:
Globals.WorldMap.PlaceCellAtPosition(get_global_mouse_position())
pass
16 changes: 8 additions & 8 deletions player/PlayerInventoryManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,22 +27,22 @@ 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"]))
print(StoneBar.scale.y)
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:
Expand Down
10 changes: 5 additions & 5 deletions player/skeleton_fixer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
@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)


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:
Expand All @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions startup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]")
Expand Down

0 comments on commit 0c42035

Please sign in to comment.