mirror of
https://github.com/Relintai/wfc_module_samples.git
synced 2024-11-13 12:47:17 +01:00
Proper test project setup.
This commit is contained in:
parent
f72ef4a1f7
commit
7af9db6c8c
@ -1,18 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://TextureRect.gd" type="Script" id=1]
|
||||
[ext_resource path="res://samples/Mazelike.png" type="Image" id=2]
|
||||
|
||||
[node name="Control" type="PanelContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="VBoxContainer" type="GridContainer" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 593.0
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer"]
|
||||
script = ExtResource( 1 )
|
||||
img = ExtResource( 2 )
|
125
project/OverlappingDemos.tscn
Normal file
125
project/OverlappingDemos.tscn
Normal file
@ -0,0 +1,125 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://TextureRect.gd" type="Script" id=1]
|
||||
[ext_resource path="res://new_buttongroup.tres" type="ButtonGroup" id=2]
|
||||
|
||||
[node name="Control" type="PanelContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
source_image_rect_path = NodePath("VBoxContainer2/VBoxContainer/HBoxContainer/TextureRect")
|
||||
result_image_rect_path = NodePath("VBoxContainer2/VBoxContainer/HBoxContainer2/TextureRect")
|
||||
settings_label_path = NodePath("VBoxContainer2/VBoxContainer/HBoxContainer3/Label2")
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 593.0
|
||||
|
||||
[node name="VBoxContainer" type="HBoxContainer" parent="VBoxContainer2"]
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 562.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="HBoxContainer" type="VBoxContainer" parent="VBoxContainer2/VBoxContainer"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 562.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 14.0
|
||||
text = "Source Image"
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer2/VBoxContainer/HBoxContainer"]
|
||||
margin_top = 18.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 318.0
|
||||
rect_min_size = Vector2( 300, 300 )
|
||||
expand = true
|
||||
|
||||
[node name="HBoxContainer2" type="VBoxContainer" parent="VBoxContainer2/VBoxContainer"]
|
||||
margin_left = 304.0
|
||||
margin_right = 604.0
|
||||
margin_bottom = 562.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer2"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 14.0
|
||||
text = "Generated Image"
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer2/VBoxContainer/HBoxContainer2"]
|
||||
margin_top = 18.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 318.0
|
||||
rect_min_size = Vector2( 300, 300 )
|
||||
expand = true
|
||||
|
||||
[node name="HBoxContainer3" type="VBoxContainer" parent="VBoxContainer2/VBoxContainer"]
|
||||
margin_left = 608.0
|
||||
margin_right = 659.0
|
||||
margin_bottom = 562.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer3"]
|
||||
margin_right = 51.0
|
||||
margin_bottom = 14.0
|
||||
text = "Settings"
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer3"]
|
||||
margin_top = 18.0
|
||||
margin_right = 51.0
|
||||
margin_bottom = 32.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer2"]
|
||||
margin_top = 566.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 586.0
|
||||
alignment = 1
|
||||
|
||||
[node name="Button" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 296.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 20.0
|
||||
text = "Prev"
|
||||
|
||||
[node name="Button5" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 340.0
|
||||
margin_right = 423.0
|
||||
margin_bottom = 20.0
|
||||
text = "Randomize"
|
||||
|
||||
[node name="Button2" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 427.0
|
||||
margin_right = 469.0
|
||||
margin_bottom = 20.0
|
||||
text = "Next"
|
||||
|
||||
[node name="Control" type="Control" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 473.0
|
||||
margin_right = 573.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 100, 0 )
|
||||
|
||||
[node name="Button3" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 577.0
|
||||
margin_right = 666.0
|
||||
margin_bottom = 20.0
|
||||
toggle_mode = true
|
||||
pressed = true
|
||||
group = ExtResource( 2 )
|
||||
text = "Overlapping"
|
||||
|
||||
[node name="Button4" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 670.0
|
||||
margin_right = 713.0
|
||||
margin_bottom = 20.0
|
||||
toggle_mode = true
|
||||
group = ExtResource( 2 )
|
||||
text = "Tiled"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button" to="." method="_on_prev_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button5" to="." method="_on_randomize_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button2" to="." method="_on_next_pressed"]
|
||||
[connection signal="toggled" from="VBoxContainer2/HBoxContainer/Button3" to="." method="_on_overlapping_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer2/HBoxContainer/Button4" to="." method="_on_tiled_toggled"]
|
@ -1,36 +1,211 @@
|
||||
extends TextureRect
|
||||
extends Control
|
||||
|
||||
export(Image) var img : Image
|
||||
export(int, "Overlapping,Tiled") var rect_type : int
|
||||
|
||||
func _ready():
|
||||
export(NodePath) var source_image_rect_path : NodePath
|
||||
export(NodePath) var result_image_rect_path : NodePath
|
||||
export(NodePath) var settings_label_path : NodePath
|
||||
|
||||
var _current_data_index : int = -1
|
||||
|
||||
enum SampleDataType {
|
||||
SAMPLE_DATA_TYPE_OVERLAPPING = 0,
|
||||
SAMPLE_DATA_TYPE_TILED = 1,
|
||||
};
|
||||
|
||||
class SampleData:
|
||||
var type : int = 0
|
||||
var image_name : String = ""
|
||||
var pattern_size : int = 3
|
||||
var periodic : bool = false
|
||||
var width : int = 0
|
||||
var height : int = 0
|
||||
var symmetry : int = 8
|
||||
var ground : bool = false
|
||||
var limit : int = 0
|
||||
var screenshots : int = 0
|
||||
var periodic_input : int = true
|
||||
|
||||
func _to_string():
|
||||
return "SampleData\ntype: " + str(type) + \
|
||||
"\nimage_name: " + image_name + \
|
||||
"\npattern_size: " + str(pattern_size) + \
|
||||
"\nperiodic: " + str(periodic) + \
|
||||
"\nwidth: " + str(width) + \
|
||||
"\nheight: " + str(height) + \
|
||||
"\nsymmetry: " + str(symmetry) + \
|
||||
"\nground: " + str(ground) + \
|
||||
"\nlimit: " + str(limit) + \
|
||||
"\nscreenshots: " + str(screenshots) + \
|
||||
"\nperiodic_input: " + str(periodic_input)
|
||||
|
||||
|
||||
var data : Array
|
||||
|
||||
func _init():
|
||||
load_data()
|
||||
|
||||
func load_data():
|
||||
var a = ResourceLoader.load("res://samples/samples.xml")
|
||||
|
||||
data.clear()
|
||||
|
||||
var xmlp : XMLParser = XMLParser.new()
|
||||
xmlp.open("res://samples/samples.xml")
|
||||
|
||||
while xmlp.read() == OK:
|
||||
if xmlp.get_node_type() == XMLParser.NODE_ELEMENT:
|
||||
if xmlp.get_node_name() == "overlapping" || xmlp.get_node_name() == "simpletiled":
|
||||
var entry : SampleData = SampleData.new()
|
||||
|
||||
if xmlp.get_node_name() == "overlapping":
|
||||
entry.type = SampleDataType.SAMPLE_DATA_TYPE_OVERLAPPING
|
||||
else:
|
||||
entry.type = SampleDataType.SAMPLE_DATA_TYPE_TILED
|
||||
|
||||
for i in range(xmlp.get_attribute_count()):
|
||||
var attrib_name : String = xmlp.get_attribute_name(i)
|
||||
var attrib_value : String = xmlp.get_attribute_value(i)
|
||||
|
||||
if attrib_name == "name":
|
||||
entry.image_name = attrib_value
|
||||
elif attrib_name == "N":
|
||||
entry.pattern_size = int(attrib_value)
|
||||
elif attrib_name == "periodic":
|
||||
if attrib_value == "True":
|
||||
entry.periodic = true
|
||||
else:
|
||||
entry.periodic = false
|
||||
elif attrib_name == "width":
|
||||
entry.width = int(attrib_value)
|
||||
elif attrib_name == "height":
|
||||
entry.height = int(attrib_value)
|
||||
elif attrib_name == "symmetry":
|
||||
entry.symmetry = int(attrib_value)
|
||||
elif attrib_name == "ground":
|
||||
entry.ground = int(attrib_value)
|
||||
elif attrib_name == "limit":
|
||||
entry.limit = int(attrib_value)
|
||||
elif attrib_name == "screenshots":
|
||||
entry.screenshots = int(attrib_value)
|
||||
elif attrib_name == "periodic_input":
|
||||
entry.periodic_input = int(attrib_value)
|
||||
|
||||
data.push_back(entry)
|
||||
|
||||
func _enter_tree():
|
||||
_on_next_pressed()
|
||||
|
||||
func generate_image():
|
||||
if (rect_type == SampleDataType.SAMPLE_DATA_TYPE_OVERLAPPING):
|
||||
generate_image_overlapping()
|
||||
else:
|
||||
generate_image_tiled()
|
||||
|
||||
func generate_image_overlapping():
|
||||
get_node(source_image_rect_path).texture = null
|
||||
get_node(result_image_rect_path).texture = null
|
||||
|
||||
var sd : SampleData = data[_current_data_index]
|
||||
|
||||
get_node(settings_label_path).text = sd.to_string()
|
||||
|
||||
var indexer : ImageIndexer = ImageIndexer.new()
|
||||
|
||||
indexer.index_image(img)
|
||||
var img : Image = ResourceLoader.load("res://samples/" + sd.image_name + ".png")
|
||||
var source_tex : ImageTexture = ImageTexture.new();
|
||||
source_tex.create_from_image(img, 0)
|
||||
get_node(source_image_rect_path).texture = source_tex
|
||||
|
||||
indexer.index_image(img)
|
||||
var indices : PoolIntArray = indexer.get_color_indices()
|
||||
|
||||
#<overlapping name="Mazelike" N="3" periodic="True"/>
|
||||
|
||||
var wfc : OverlappingWaveFormCollapse = OverlappingWaveFormCollapse.new()
|
||||
wfc.periodic_input = true
|
||||
wfc.out_height = 300
|
||||
wfc.out_width = 300
|
||||
wfc.pattern_size = 3
|
||||
wfc.pattern_size = sd.pattern_size
|
||||
wfc.periodic_output = sd.periodic
|
||||
wfc.symmetry = sd.symmetry
|
||||
wfc.ground = sd.ground
|
||||
|
||||
wfc.periodic_input = sd.periodic_input
|
||||
|
||||
wfc.out_height = img.get_height()
|
||||
wfc.out_width = img.get_width()
|
||||
|
||||
wfc.set_input(indices, img.get_width(), img.get_height())
|
||||
|
||||
#todo
|
||||
#if sd.width > 0 && sd.height > 0:
|
||||
# wfc.set_input(indices, sd.width, sd.height)
|
||||
#else:
|
||||
# wfc.set_input(indices, img.get_width(), img.get_height())
|
||||
|
||||
randomize()
|
||||
wfc.set_seed(randi())
|
||||
|
||||
wfc.initialize()
|
||||
|
||||
var res : PoolIntArray = wfc.generate_image_index_data()
|
||||
|
||||
if (res.size() == 0):
|
||||
print("(res.size() == 0)")
|
||||
return
|
||||
|
||||
var data : PoolByteArray = indexer.indices_to_argb8_data(res)
|
||||
|
||||
var res_img : Image = Image.new()
|
||||
res_img.create_from_data(300, 300, false, Image.FORMAT_RGBA8, data)
|
||||
res_img.create_from_data(img.get_width(), img.get_height(), false, Image.FORMAT_RGBA8, data)
|
||||
|
||||
var res_tex : ImageTexture = ImageTexture.new();
|
||||
res_tex.create_from_image(res_img, 0)
|
||||
|
||||
texture = res_tex
|
||||
get_node(result_image_rect_path).texture = res_tex
|
||||
|
||||
func generate_image_tiled():
|
||||
pass
|
||||
|
||||
func _on_prev_pressed():
|
||||
while true:
|
||||
_current_data_index -= 1
|
||||
|
||||
if _current_data_index < 0:
|
||||
_current_data_index = data.size() - 1
|
||||
|
||||
if data[_current_data_index].type == rect_type:
|
||||
break
|
||||
|
||||
generate_image()
|
||||
|
||||
func _on_next_pressed():
|
||||
while true:
|
||||
_current_data_index += 1
|
||||
|
||||
if _current_data_index >= data.size():
|
||||
_current_data_index = 0
|
||||
|
||||
if data[_current_data_index].type == rect_type:
|
||||
break
|
||||
|
||||
generate_image()
|
||||
|
||||
func _on_tiled_toggled(on : bool):
|
||||
if !on:
|
||||
return
|
||||
|
||||
rect_type = 1
|
||||
|
||||
_current_data_index = -1
|
||||
|
||||
_on_next_pressed()
|
||||
|
||||
func _on_overlapping_toggled(on : bool):
|
||||
if !on:
|
||||
return
|
||||
|
||||
rect_type = 0
|
||||
|
||||
_current_data_index = -1
|
||||
|
||||
_on_next_pressed()
|
||||
|
||||
|
||||
func _on_randomize_pressed():
|
||||
generate_image()
|
||||
|
68
project/TiledDemos.tscn
Normal file
68
project/TiledDemos.tscn
Normal file
@ -0,0 +1,68 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://TextureRect.gd" type="Script" id=1]
|
||||
|
||||
[node name="Control" type="PanelContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 593.0
|
||||
|
||||
[node name="VBoxContainer" type="GridContainer" parent="VBoxContainer2"]
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 562.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer2/VBoxContainer"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 300.0
|
||||
rect_min_size = Vector2( 300, 300 )
|
||||
expand = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer2"]
|
||||
margin_top = 566.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 586.0
|
||||
alignment = 1
|
||||
|
||||
[node name="Button" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 340.0
|
||||
margin_right = 380.0
|
||||
margin_bottom = 20.0
|
||||
text = "Prev"
|
||||
|
||||
[node name="Button2" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 384.0
|
||||
margin_right = 426.0
|
||||
margin_bottom = 20.0
|
||||
text = "Next"
|
||||
|
||||
[node name="Control" type="Control" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 430.0
|
||||
margin_right = 530.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 100, 0 )
|
||||
|
||||
[node name="Button3" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 534.0
|
||||
margin_right = 623.0
|
||||
margin_bottom = 20.0
|
||||
text = "Overlapping"
|
||||
|
||||
[node name="Button4" type="Button" parent="VBoxContainer2/HBoxContainer"]
|
||||
margin_left = 627.0
|
||||
margin_right = 670.0
|
||||
margin_bottom = 20.0
|
||||
disabled = true
|
||||
text = "Tiled"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button" to="VBoxContainer2/VBoxContainer/TextureRect" method="_on_prev_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button2" to="VBoxContainer2/VBoxContainer/TextureRect" method="_on_next_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button3" to="VBoxContainer2/VBoxContainer/TextureRect" method="_on_overlapping_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/Button4" to="VBoxContainer2/VBoxContainer/TextureRect" method="_on_tiled_pressed"]
|
3
project/new_buttongroup.tres
Normal file
3
project/new_buttongroup.tres
Normal file
@ -0,0 +1,3 @@
|
||||
[gd_resource type="ButtonGroup" format=2]
|
||||
|
||||
[resource]
|
@ -11,7 +11,7 @@ config_version=4
|
||||
[application]
|
||||
|
||||
config/name="project"
|
||||
run/main_scene="res://Control.tscn"
|
||||
run/main_scene="res://OverlappingDemos.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[physics]
|
||||
|
Loading…
Reference in New Issue
Block a user