Skip to content

Commit

Permalink
chore: format, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Feb 26, 2024
1 parent 69b4252 commit 8cf05f3
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 132 deletions.
41 changes: 26 additions & 15 deletions components/helpers/scatter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,67 @@
class_name Scatter
extends Node3D


## Scatter Meshes Script
##
## This code allows you to quickly place a number of instances of a mesh at
## random locations.

@export var extend: Vector3 = Vector3(1.0, 0.0, 1.0):
set = set_extend
@export var instance_count: int = 10:
set = set_instance_count
@export var min_scale: float = 1.0:
set = set_min_scale
@export var max_scale: float = 1.0:
set = set_max_scale
@export var mesh: Mesh:
set = set_mesh
@export var material_override: Material:
set = set_material_override

@export var extend : Vector3 = Vector3(1.0, 0.0, 1.0): set = set_extend
@export var instance_count : int = 10: set = set_instance_count
@export var min_scale : float = 1.0: set = set_min_scale
@export var max_scale : float = 1.0: set = set_max_scale
@export var mesh : Mesh: set = set_mesh
@export var material_override : Material: set = set_material_override
var dirty: bool = true
var multi_mesh: MultiMesh
var multi_mesh_instance: MultiMeshInstance3D

var dirty : bool = true
var multi_mesh : MultiMesh
var multi_mesh_instance : MultiMeshInstance3D

func set_extend(new_value):
extend = new_value
_set_dirty()


func set_instance_count(new_value):
instance_count = new_value
_set_dirty()


func set_min_scale(new_value):
min_scale = new_value
_set_dirty()


func set_max_scale(new_value):
max_scale = new_value
_set_dirty()


func set_mesh(new_mesh):
mesh = new_mesh
if multi_mesh:
multi_mesh.mesh = mesh


func set_material_override(new_material):
material_override = new_material
if multi_mesh_instance:
multi_mesh_instance.material_override = material_override


func _set_dirty():
if !dirty:
dirty = true
call_deferred("_update_multimesh")


func _update_multimesh():
if !dirty:
return
Expand All @@ -59,17 +71,17 @@ func _update_multimesh():
for i in instance_count:
var t := Transform3D()
var s := randf_range(min_scale, max_scale)
t.basis = Basis() \
.rotated(Vector3.UP, randf_range(-PI, PI)) \
.scaled(Vector3(s, s, s))
t.basis = Basis().rotated(Vector3.UP, randf_range(-PI, PI)).scaled(Vector3(s, s, s))
t.origin = Vector3(
randf_range(-extend.x, extend.x),
randf_range(-extend.y, extend.y),
randf_range(-extend.z, extend.z))
randf_range(-extend.z, extend.z)
)
multi_mesh.set_instance_transform(i, t)

dirty = false


# Called when the node enters the scene tree for the first time.
func _ready():
multi_mesh = MultiMesh.new()
Expand All @@ -83,4 +95,3 @@ func _ready():

# First time creating our multimesh
_update_multimesh()

3 changes: 2 additions & 1 deletion components/helpers/zone_save_point.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
extends Node3D

@export var saved_material : Material
@export var saved_material: Material

# We only allow saving once after our scene loads
var is_saved = false


func _on_save_button_button_pressed(_button):
# Skip if already saved
if is_saved:
Expand Down
9 changes: 4 additions & 5 deletions components/helpers/zone_switch_area.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@tool
extends Area3D


## Zone scene file
@export_file('*.tscn') var zone_scene : String = ""
@export_file("*.tscn") var zone_scene: String = ""

## If true the zone switcher is enabled
@export var enabled : bool = true
@export var enabled: bool = true

## Name of the spawn-point node name in the target scene
@export var spawn_node_name := ""
Expand All @@ -18,7 +17,7 @@ func _ready():


# Called when a body enters this area
func _on_body_entered(body : Node3D):
func _on_body_entered(body: Node3D):
# Ignore if not enabled
if not enabled:
return
Expand All @@ -28,7 +27,7 @@ func _on_body_entered(body : Node3D):
return

# Find our scene base
var scene_base : XRToolsSceneBase = XRTools.find_xr_ancestor(self, "*", "XRToolsSceneBase")
var scene_base: XRToolsSceneBase = XRTools.find_xr_ancestor(self, "*", "XRToolsSceneBase")
if not scene_base:
return

Expand Down
2 changes: 0 additions & 2 deletions components/persistent/persistent.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
class_name Persistent


## Persistent script
##
## This script defines constants used in the persistence system.


## Notification to trigger loading state
const NOTIFICATION_LOAD_STATE := 57001

Expand Down
21 changes: 9 additions & 12 deletions components/persistent/persistent_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
class_name PersistentItem
extends XRToolsPickable


## Persistent Item Instance Node
##
## The [PersistentItem] type is for instances of items managed by the
Expand All @@ -20,15 +19,14 @@ extends XRToolsPickable
## persisted to the [PersistentWorld] store by overriding the
## [method _load_world_state] and [method _save_world_state] methods.


# Group for world-data properties
@export_group("World Data")

## This property specifies the unique ID (or base ID) for this item
@export var item_id : String
@export var item_id: String

## This property specifies the [PersistentItemType] of this item
@export var item_type : PersistentItemType
@export var item_type: PersistentItemType

## This property indicates whether this object was dynamically created
@export var item_dynamic := false
Expand All @@ -42,19 +40,18 @@ extends XRToolsPickable
## Timeout for auto-return
@export var auto_return_timeout := 2.0


# Destroyed flag
var _destroyed := false

# Last pocket this object was in
var _last_pocket : PersistentPocket
var _last_pocket: PersistentPocket

# Auto-return timer node
var _auto_return_timer : Timer
var _auto_return_timer: Timer


# Add support for is_xr_class
func is_xr_class(p_name : String) -> bool:
func is_xr_class(p_name: String) -> bool:
return p_name == "PersistentItem" or super(p_name)


Expand Down Expand Up @@ -88,7 +85,7 @@ func _get_configuration_warnings() -> PackedStringArray:


# Handle notifications
func _notification(what : int) -> void:
func _notification(what: int) -> void:
# Ignore notifications on freeing objects
if is_queued_for_deletion():
return
Expand Down Expand Up @@ -141,7 +138,7 @@ func _save_state() -> void:
return

# Design-time items must be saved with the destroyed state
PersistentWorld.instance.set_value(item_id, { destroyed = true })
PersistentWorld.instance.set_value(item_id, {destroyed = true})
return

# Populate the state information
Expand All @@ -167,7 +164,7 @@ func _destroy() -> void:
## [PersistentItem] can override this method to load additional item state by
## calling super() to load the basic information and then reading additional
## state information from the dictionary.
func _load_world_state(state : Dictionary) -> void:
func _load_world_state(state: Dictionary) -> void:
# Restore the location
var location = state.get("location")
if location is Transform3D:
Expand All @@ -179,7 +176,7 @@ func _load_world_state(state : Dictionary) -> void:
## [PersistentItem] can override this method to save additional item state by
## calling super() to save the basic information and then writing additional
## state information to the dictionary.
func _save_world_state(state : Dictionary) -> void:
func _save_world_state(state: Dictionary) -> void:
# Save the type and location
state["type"] = item_type.type_id
state["location"] = global_transform
Expand Down
10 changes: 4 additions & 6 deletions components/persistent/persistent_item_database.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
class_name PersistentItemDatabase
extends Resource


## Persistent Item Database Resource
##
## This resource defines all [PersistentItemType] items supported by the
## persistence system. The [PersistentZone] classe use this resource when
## creating [PersistentItem] instances.


## This property is the array of supported persistent item types
@export var items : Array[PersistentItemType] : set = _set_items

@export var items: Array[PersistentItemType]:
set = _set_items

# Items cache
var _cache := {}
Expand All @@ -22,7 +20,7 @@ var _cache_valid := false

## This method gets a [PersistentItemType] given its [param type_id]. If no
## corresponding [PersistentItemType] is found then this function returns null.
func get_type(type_id : String) -> PersistentItemType:
func get_type(type_id: String) -> PersistentItemType:
# Populate the cache if necessary
if not _cache_valid:
_populate_cache()
Expand All @@ -31,7 +29,7 @@ func get_type(type_id : String) -> PersistentItemType:


# Handle setting the items
func _set_items(p_items : Array[PersistentItemType]) -> void:
func _set_items(p_items: Array[PersistentItemType]) -> void:
# Save the new items
items = p_items

Expand Down
6 changes: 2 additions & 4 deletions components/persistent/persistent_item_type.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
class_name PersistentItemType
extends Resource


## Persistent Item Type Resource
##
## This resource defines a type of persistent items managed by the
## persistence system.


## This property specifies the unique type ID
@export var type_id : String
@export var type_id: String

## This property specifies the scene-file for instancing the [PersistentItem]
@export_file('*.tscn') var instance_scene : String
@export_file("*.tscn") var instance_scene: String
28 changes: 14 additions & 14 deletions components/persistent/persistent_pocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@
class_name PersistentPocket
extends XRToolsSnapZone


## Persistent Pocket Node
##
## The [PersistentPocket] type holds persistent items managed by the
## persistence system. The [PersistentPocket] type extends from
## [XRToolsSnapZone] to allow [PersistentItem] objects to be snapped or
## removed by the player.


## Enumeration to control pocket behavior when the parent item is held
enum HeldBehavior {
IGNORE, ## Ignore picked_up/dropped changes
ENABLE, ## Enable when picked up
DISABLE ## Disable when picked up
## Ignore picked_up/dropped changes
IGNORE,
## Enable when picked up
ENABLE,
## Disable when picked up
DISABLE
}


# Group for world-data properties
@export_group("World Data")

## This property specifies the unique ID of this pocket
@export var pocket_id : String
@export var pocket_id: String

# Group for options
@export_group("Options")

## Pocket behavior when held
@export var held_behavior := HeldBehavior.ENABLE : set = _set_held_behavior

@export var held_behavior := HeldBehavior.ENABLE:
set = _set_held_behavior

# Parent pickable body
var _parent_body : XRToolsPickable
var _parent_body: XRToolsPickable


# Add support for is_xr_class
func is_xr_class(p_name : String) -> bool:
func is_xr_class(p_name: String) -> bool:
return p_name == "PersistentPocket" or super(p_name)


Expand Down Expand Up @@ -76,7 +76,7 @@ func _get_configuration_warnings() -> PackedStringArray:


# Handle notifications
func _notification(what : int) -> void:
func _notification(what: int) -> void:
# Ignore notifications on freeing objects
if is_queued_for_deletion():
return
Expand Down Expand Up @@ -110,7 +110,7 @@ func _save_state() -> void:
return

# Get the item_id of the PersistentItem in the pocket
var item_id : String = picked_up_object.item_id
var item_id: String = picked_up_object.item_id

# Save that the pocket holds the item
PersistentWorld.instance.set_value(pocket_id, item_id)
Expand Down Expand Up @@ -154,7 +154,7 @@ func _on_dropped(_pickable) -> void:


# Called when the held_behavior property has been modified
func _set_held_behavior(p_held_behavior : HeldBehavior) -> void:
func _set_held_behavior(p_held_behavior: HeldBehavior) -> void:
held_behavior = p_held_behavior
if is_inside_tree() and _parent_body:
_update_held_behavior()
Expand Down
Loading

0 comments on commit 8cf05f3

Please sign in to comment.