init
This commit is contained in:
commit
d7bed0fa73
4
.editorconfig
Normal file
4
.editorconfig
Normal file
@ -0,0 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
1
icon.svg
Normal file
1
icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
||||
|
After Width: | Height: | Size: 995 B |
43
icon.svg.import
Normal file
43
icon.svg.import
Normal file
@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bmb3k4y6h1xd0"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
21
project.godot
Normal file
21
project.godot
Normal file
@ -0,0 +1,21 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="AABGG"
|
||||
run/main_scene="uid://dgnxuejg2n1xb"
|
||||
config/features=PackedStringArray("4.5", "GL Compatibility")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
95
scenes/main.tscn
Normal file
95
scenes/main.tscn
Normal file
@ -0,0 +1,95 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dgnxuejg2n1xb"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b8xlgs6663g2b" path="res://scripts/main.gd" id="1_o5qli"]
|
||||
|
||||
[node name="Main" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_o5qli")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="HFlowContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 50)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Artist" type="LineEdit" parent="Panel/VBoxContainer/HFlowContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Demon Hunter"
|
||||
placeholder_text = "Artist"
|
||||
|
||||
[node name="Album" type="LineEdit" parent="Panel/VBoxContainer/HFlowContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "War"
|
||||
placeholder_text = "Album"
|
||||
|
||||
[node name="Button" type="Button" parent="Panel/VBoxContainer/HFlowContainer"]
|
||||
layout_mode = 2
|
||||
text = "Search"
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ImageContainer" type="HFlowContainer" parent="Panel/VBoxContainer/ScrollContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="StatusBar" type="TextEdit" parent="Panel/VBoxContainer/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 50)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Status..."
|
||||
editable = false
|
||||
wrap_mode = 1
|
||||
|
||||
[node name="CreateCollageButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Create Collage"
|
||||
|
||||
[node name="HTTPRequest" type="HTTPRequest" parent="."]
|
||||
|
||||
[node name="ImageHttpRequest" type="HTTPRequest" parent="."]
|
||||
|
||||
[node name="CollagePopupPanel" type="PopupPanel" parent="."]
|
||||
oversampling_override = 1.0
|
||||
initial_position = 4
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="CollagePopupPanel"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 4.0
|
||||
offset_top = 4.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -4.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
127
scripts/main.gd
Normal file
127
scripts/main.gd
Normal file
@ -0,0 +1,127 @@
|
||||
extends Control
|
||||
|
||||
@onready var artist_input: LineEdit = $Panel/VBoxContainer/HFlowContainer/Artist
|
||||
@onready var album_input: LineEdit = $Panel/VBoxContainer/HFlowContainer/Album
|
||||
@onready var search_button: Button = $Panel/VBoxContainer/HFlowContainer/Button
|
||||
@onready var output: TextEdit = $Panel/VBoxContainer/HBoxContainer/StatusBar
|
||||
@onready var http_request: HTTPRequest = $HTTPRequest
|
||||
@onready var http_image_request: HTTPRequest = $ImageHttpRequest
|
||||
@onready var collage_popup_panel: PopupPanel = $CollagePopupPanel
|
||||
@onready var create_collage_button: Button = $Panel/VBoxContainer/HBoxContainer/CreateCollageButton
|
||||
|
||||
|
||||
var _image_array: Array[ImageTexture] = []
|
||||
|
||||
func _ready() -> void:
|
||||
http_request.request_completed.connect(_on_http_request_completed)
|
||||
search_button.pressed.connect(_on_search)
|
||||
|
||||
http_image_request.request_completed.connect(_on_http_image_request_completed)
|
||||
|
||||
create_collage_button.pressed.connect(_on_create_collage)
|
||||
|
||||
|
||||
func _on_create_collage():
|
||||
var w = 1920
|
||||
var h = 1080
|
||||
var collage: ImageTexture = create_collage(w, h, false)
|
||||
var img = collage.get_image()
|
||||
var save_path = "user://saved_image.png"
|
||||
var error: Error = img.save_png(save_path)
|
||||
|
||||
if error == OK:
|
||||
print("Image saved successfully to: " + save_path)
|
||||
else:
|
||||
print("Error saving image: " + str(error))
|
||||
#collage_popup_panel.get_node("TextureRect").texture = collage
|
||||
#collage_popup_panel.size = Vector2(w, h)
|
||||
#collage_popup_panel.show()
|
||||
|
||||
|
||||
func _on_http_request_completed(result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
if result == HTTPRequest.RESULT_SUCCESS:
|
||||
var json_data = JSON.parse_string(body.get_string_from_utf8()) as Dictionary
|
||||
if json_data:
|
||||
var data_arr: Array = json_data["data"]
|
||||
var album: Dictionary = data_arr[0]
|
||||
var cover_url: String = album["cover_big"]
|
||||
output.text = str(cover_url)
|
||||
http_image_request.request(cover_url)
|
||||
else:
|
||||
output.text = "Failed to parse JSON"
|
||||
else:
|
||||
output.text = str("HTTP Request failed with result: ", result, " and code: ", response_code)
|
||||
|
||||
|
||||
# https://api.deezer.com/search/album?q=Demon%20Hunter%20War
|
||||
func _on_search() -> void:
|
||||
var artist = artist_input.text.replace(" ", "%20")
|
||||
var album = album_input.text.replace(" ", "%20")
|
||||
if artist == "" or album == "": return
|
||||
|
||||
var url = str("https://api.deezer.com/search/album?q=",artist,"%20",album)
|
||||
http_request.request(url)
|
||||
|
||||
|
||||
func _on_http_image_request_completed(result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
if result == HTTPRequest.RESULT_SUCCESS:
|
||||
var img = Image.new()
|
||||
var err = img.load_jpg_from_buffer(body)
|
||||
if err == OK:
|
||||
var tex = ImageTexture.new()
|
||||
tex = ImageTexture.create_from_image(img)
|
||||
var new_tex_rect_node: TextureRect = TextureRect.new()
|
||||
$Panel/VBoxContainer/ScrollContainer/ImageContainer.add_child(new_tex_rect_node)
|
||||
new_tex_rect_node.texture = tex
|
||||
_image_array.append(tex)
|
||||
else:
|
||||
output.text = str("Error loading image: ", err)
|
||||
else:
|
||||
output.text = str("HTTP Request failed with result: ", result, " and code: ", response_code)
|
||||
|
||||
|
||||
func create_collage(w: int, h: int, fail_if_not_even: bool) -> ImageTexture:
|
||||
var tile_w := 500
|
||||
var tile_h := 500
|
||||
|
||||
# Compute how many tiles we need to cover the area
|
||||
var cols:int = ceil(w / tile_w)
|
||||
var rows:int = ceil(h / tile_h)
|
||||
var total_needed:int = cols * rows
|
||||
|
||||
if fail_if_not_even and _image_array.size() < total_needed:
|
||||
push_error("Not enough images to fill collage")
|
||||
return null
|
||||
|
||||
var shuffled := _image_array.duplicate()
|
||||
shuffled.shuffle()
|
||||
while shuffled.size() < total_needed:
|
||||
shuffled.append_array(shuffled)
|
||||
|
||||
# Actual cell size for each tile
|
||||
var cell_w := w / cols
|
||||
var cell_h := h / rows
|
||||
|
||||
# Create the collage image with black background
|
||||
var collage := Image.create(w, h, false, Image.FORMAT_RGBA8)
|
||||
collage.fill(Color.BLACK)
|
||||
|
||||
var idx := 0
|
||||
for row in rows:
|
||||
for col in cols:
|
||||
if idx >= shuffled.size():
|
||||
break
|
||||
var tex: ImageTexture = shuffled[idx]
|
||||
var img: Image = tex.get_image()
|
||||
if img.get_format() != collage.get_format():
|
||||
img.convert(collage.get_format())
|
||||
|
||||
# Resize to fit the cell exactly (aspect ratio is fine to distort slightly)
|
||||
img.resize(cell_w, cell_h)
|
||||
|
||||
collage.blit_rect(img, Rect2i(Vector2i(0, 0), Vector2i(cell_w, cell_h)),
|
||||
Vector2i(col * cell_w, row * cell_h))
|
||||
|
||||
idx += 1
|
||||
|
||||
return ImageTexture.create_from_image(collage)
|
||||
1
scripts/main.gd.uid
Normal file
1
scripts/main.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://b8xlgs6663g2b
|
||||
Loading…
Reference in New Issue
Block a user