-
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
bfa0797
commit d6e0dd6
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
addons/wfc/examples/demo_wfc_2d_tilemaplayer_multilayer_remap.tscn
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
addons/wfc/problems/2d/preconditions/precondition_2d_remap.gd
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,23 @@ | ||
extends WFC2DPrecondition | ||
|
||
class_name WFC2DPreconditionRemap | ||
|
||
var _node: Node | ||
var _mapper: WFCMapper2D | ||
var _domains_map: Array[WFCBitSet] | ||
|
||
func _init(node: Node, mapper: WFCMapper2D, domains_map: Array[WFCBitSet]) -> void: | ||
assert(mapper.supports_map(node)) | ||
assert(mapper.size() == domains_map.size()) | ||
|
||
_node = node | ||
_mapper = mapper | ||
_domains_map = domains_map | ||
|
||
func read_domain(coords: Vector2i) -> WFCBitSet: | ||
var read := _mapper.read_cell(_node, coords) | ||
|
||
if read < 0: | ||
return null | ||
|
||
return _domains_map[read] |
39 changes: 39 additions & 0 deletions
39
addons/wfc/problems/2d/preconditions/precondition_2d_remap_by_map.gd
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,39 @@ | ||
extends WFC2DPrecondition2DNullSettings | ||
|
||
class_name WFC2DPrecondition2DRemapByMapSettings | ||
|
||
@export_node_path | ||
var class_map: NodePath | ||
|
||
func _learn_classes(mapper: WFCMapper2D, map: Node) -> Array[WFCBitSet]: | ||
var res: Array[WFCBitSet] = [] | ||
|
||
for i in range(mapper.size()): | ||
var set := WFCBitSet.new(mapper.size()) | ||
set.set_bit(i, true) | ||
res.push_back(set) | ||
|
||
var used_rect := mapper.get_used_rect(map) | ||
|
||
for row in range(used_rect.position.y, used_rect.end.y): | ||
var row_set := WFCBitSet.new(mapper.size()) | ||
for col in range(used_rect.position.x, used_rect.end.x): | ||
var tile := mapper.read_cell(map, Vector2i(col, row)) | ||
if tile >= 0: | ||
row_set.set_bit(tile, true) | ||
|
||
for tile in row_set.iterator(): | ||
res[tile].union_in_place(row_set) | ||
|
||
return res | ||
|
||
func create_precondition(parameters: CreationParameters) -> WFC2DPrecondition: | ||
assert(class_map != null) | ||
var class_map_node := parameters.generator_node.get_node(class_map) | ||
assert(parameters.problem_settings.rules.mapper.supports_map(class_map_node)) | ||
|
||
return WFC2DPreconditionRemap.new( | ||
parameters.target_node, | ||
parameters.problem_settings.rules.mapper, | ||
_learn_classes(parameters.problem_settings.rules.mapper, class_map_node) | ||
) |