add license, move folders

This commit is contained in:
Nordup 2024-05-04 00:14:24 +04:00
parent 185cc74060
commit 271c4a46a1
132 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,24 @@
extends TextureRect
@export var duration: float
@export var start_scale: float
@export var end_scale: float
@onready var start := Vector2(start_scale, start_scale)
@onready var end := Vector2(end_scale, end_scale)
@onready var default = scale
func _ready() -> void:
animate()
func _notification(what: int) -> void:
if what == NOTIFICATION_ENABLED:
animate()
func animate() -> void:
var tween = create_tween().set_loops()
tween.tween_property(self, "scale", end, duration).from(start)
tween.tween_property(self, "scale", start, duration).from(end)

View file

@ -0,0 +1,6 @@
extends Control
func _ready() -> void:
await get_tree().process_frame
global_position = get_parent().global_position

View file

@ -0,0 +1,9 @@
extends RichTextLabel
func _ready() -> void:
finished.connect(to_line)
func to_line() -> void:
text = text.replace('\n', '\t') # TODO: Handle BBCode

View file

@ -0,0 +1,33 @@
extends Button
class_name PromptResult
@export var gate_events: GateEvents
@export var prompt_text: Label
@export var focus_style: StyleBox
var normal_style: StyleBox
func _ready() -> void:
normal_style = get_theme_stylebox("normal", "")
func fill(prompt: Dictionary) -> void:
if prompt == null: return
var txt: String = prompt["prompt"].to_lower()
txt = StringTools.to_alpha(txt)
prompt_text.text = txt
func _on_button_pressed() -> void:
if prompt_text.text.is_empty(): return
gate_events.search_emit(prompt_text.text)
func focus() -> void:
add_theme_stylebox_override("normal", focus_style)
func unfocus() -> void:
add_theme_stylebox_override("normal", normal_style)

View file

@ -0,0 +1,90 @@
extends Node
class_name PromptNavigation
enum {
UP,
DOWN
}
@export var search: Search
@export var prompt_results: PromptResults
var current_prompt: int = -1
var actual_search_query: String
func _ready() -> void:
search.focus_entered.connect(on_focus_entered)
search.on_release_focus.connect(on_release_focus)
search.on_navigation.connect(on_navigation)
search.text_changed.connect(func(_text): reset())
func on_focus_entered() -> void:
prompt_results._on_search_text_changed(search.text)
func on_release_focus() -> void:
prompt_results.clear()
reset()
func on_navigation(event: int) -> void:
match event:
UP:
prompt_up()
DOWN:
prompt_down()
_:
printerr("Unhandled navigation event")
func prompt_up() -> void:
var from: int = current_prompt
var to: int
if from == -1:
to = prompt_results.get_children().size() - 1
else:
to = from - 1
if from != to:
current_prompt = to
switch_prompt(from, to)
func prompt_down() -> void:
var from: int = current_prompt
var to: int
if from == prompt_results.get_children().size() - 1:
to = -1
else:
to = from + 1
if from != to:
current_prompt = to
switch_prompt(from, to)
func reset() -> void:
current_prompt = -1
actual_search_query = ""
func switch_prompt(from: int, to: int) -> void:
if from == -1:
actual_search_query = search.text
else:
var from_prompt: PromptResult = prompt_results.get_children()[from]
from_prompt.unfocus()
if to == -1:
search.text = actual_search_query
search.caret_column = search.text.length()
else:
var to_prompt: PromptResult = prompt_results.get_children()[to]
to_prompt.focus()
search.text = to_prompt.prompt_text.text
search.caret_column = search.text.length()

View file

@ -0,0 +1,60 @@
extends VBoxContainer
class_name PromptResults
@export var gate_events: GateEvents
@export var api: ApiSettings
@export var result_scene: PackedScene
@export var panel: Control
var prompt_size: float
var result_str: String
func _ready() -> void:
var prompt: Control = result_scene.instantiate()
prompt_size = prompt.size.y
prompt.queue_free()
panel.visible = true
clear()
func _on_search_text_changed(query: String) -> void:
if query.is_empty(): clear(); return
await prompt_request(query)
clear()
var prompts: Array = JSON.parse_string(result_str)
if prompts == null or prompts.is_empty():
return
for prompt in prompts:
var result: PromptResult = result_scene.instantiate()
result.fill(prompt)
add_child(result)
change_size(prompts.size())
func prompt_request(query: String) -> void:
var url = api.prompt + query.uri_encode()
var callback = func(_result, code, _headers, body):
if code == 200:
result_str = body.get_string_from_utf8()
else: Debug.logclr("Request prompt failed. Code " + str(code), Color.RED)
var err = await Backend.request(url, callback)
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request prompt", Color.RED)
func clear() -> void:
for child in get_children():
child.queue_free()
remove_child(child)
change_size(0)
func change_size(promt_count: int) -> void:
panel.size = Vector2(panel.size.x, promt_count * prompt_size)

View file

@ -0,0 +1,25 @@
extends Control
class_name SearchResult
@export var gate_events: GateEvents
@export var url: Label
@export var title: Label
@export var description: RichTextLabel
@export var image: TextureRect
func fill(gate: Dictionary) -> void:
if gate == null: return
url.text = gate["url"]
title.text = "Unnamed" if gate["title"].is_empty() else gate["title"]
description.text = gate["description"]
var image_path = await FileDownloader.download(gate["image"])
image.texture = FileTools.load_external_tex(image_path)
func _on_button_pressed() -> void:
if url.text.is_empty(): return
gate_events.open_gate_emit(url.text)

View file

@ -0,0 +1,38 @@
extends VBoxContainer
@export var gate_events: GateEvents
@export var api: ApiSettings
@export var result_scene: PackedScene
var result_str: String = "{}"
func _ready() -> void:
search(gate_events.current_search_query)
func search(query: String) -> void:
Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN)
await search_request(query)
var gates = JSON.parse_string(result_str)
if gates == null or gates.is_empty():
Debug.logclr("No gates found", Color.YELLOW)
return
for gate in gates:
var result: SearchResult = result_scene.instantiate()
result.fill(gate)
add_child(result)
Debug.logr(gate["url"])
func search_request(query: String) -> void:
var url = api.search + query.uri_encode()
var callback = func(_result, code, _headers, body):
if code == 200:
result_str = body.get_string_from_utf8()
else: Debug.logclr("Request search failed. Code " + str(code), Color.RED)
var err = await Backend.request(url, callback)
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search", Color.RED)

View file

@ -0,0 +1,32 @@
extends Control
@export var gate_events: GateEvents
@export var search_line_edit: LineEdit
@export var search: Control
@export var downloading: Control
@export var success: Control
@export var error: Control
func _ready() -> void:
search_line_edit.text_changed.connect(func(_text): switch_to(search))
gate_events.search.connect(func(_url): switch_to(search))
gate_events.exit_gate.connect(func(): switch_to(search))
gate_events.open_gate.connect(func(_url): switch_to(downloading))
gate_events.gate_entered.connect(func(): switch_to(success))
gate_events.gate_error.connect(func(_code): switch_to(error))
switch_to(search)
func switch_to(_state: Control) -> void:
disable([search, downloading, success, error])
_state.visible = true
_state.process_mode = Node.PROCESS_MODE_INHERIT
func disable(states: Array[Control]) -> void:
for state in states:
state.visible = false
state.process_mode = Node.PROCESS_MODE_DISABLED