-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c19af30
commit 165da04
Showing
8 changed files
with
897 additions
and
800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@tool | ||
class_name ScatterCollection | ||
extends SceneSource | ||
## Multiple scene item collections | ||
|
||
## the scene objects (prefabs) to fetch | ||
@export var prefabs: Array[PackedScene] = []: | ||
set(value): | ||
prefabs = value | ||
is_dirty = true | ||
emit_changed() | ||
|
||
|
||
## the weights to bias which is selected | ||
@export var weights: Array[int] = []: | ||
set(value): | ||
weights = value | ||
is_dirty = true | ||
emit_changed() | ||
|
||
|
||
var is_dirty = false | ||
var total_weight = 0 | ||
|
||
|
||
func get_resource(pick: int = -1) -> PackedScene: | ||
if is_dirty: | ||
total_weight = 0 | ||
for i in range(prefabs.size()): | ||
total_weight += 1 if i >= weights.size() else weights[i] | ||
if pick < 0: | ||
pick = randi_range(0, total_weight) | ||
else: | ||
pick = pick % total_weight | ||
var w := 0 | ||
for i in range(prefabs.size()): | ||
w += 1 if i >= weights.size() else weights[i] | ||
if w >= pick: | ||
return prefabs[i] | ||
return null | ||
|
||
|
||
func has_resource() -> bool: | ||
return prefabs.size() > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@tool | ||
class_name ScatterItem | ||
extends SceneSource | ||
## A single scene item | ||
|
||
## the scene objects (prefabs) to fetch | ||
@export var prefab: PackedScene = null: | ||
set(value): | ||
prefab = value | ||
emit_changed() | ||
|
||
|
||
func get_resource(pick: int = 0) -> PackedScene: | ||
return prefab | ||
|
||
|
||
func has_resource() -> bool: | ||
return prefab != null | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@tool | ||
class_name SceneSource | ||
extends Resource | ||
# A base type for fetching scenes | ||
|
||
func get_resource(pick: int = 0) -> PackedScene: | ||
return null | ||
|
||
|
||
func has_resource() -> bool: | ||
return false |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.