Cleanup tiny sword gym
This commit is contained in:
BIN
docs/gyms/tiny_sword/buildings/castle/Castle.png
Normal file
BIN
docs/gyms/tiny_sword/buildings/castle/Castle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
40
docs/gyms/tiny_sword/buildings/castle/Castle.png.import
Normal file
40
docs/gyms/tiny_sword/buildings/castle/Castle.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cry4arn00kgrt"
|
||||
path="res://.godot/imported/Castle.png-e8b352108f4d5f1f213446b1f212024a.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://docs/gyms/tiny_sword/buildings/castle/Castle.png"
|
||||
dest_files=["res://.godot/imported/Castle.png-e8b352108f4d5f1f213446b1f212024a.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
|
||||
18
docs/gyms/tiny_sword/buildings/castle/castle.gd
Normal file
18
docs/gyms/tiny_sword/buildings/castle/castle.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends Node2D
|
||||
|
||||
@onready var _prestige_panel: PrestigePanel = $PrestigePanel
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _on_area_2d_mouse_entered() -> void:
|
||||
_prestige_panel.visible = true
|
||||
|
||||
func _on_area_2d_mouse_exited() -> void:
|
||||
_prestige_panel.visible = false
|
||||
1
docs/gyms/tiny_sword/buildings/castle/castle.gd.uid
Normal file
1
docs/gyms/tiny_sword/buildings/castle/castle.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cjc0l13b07802
|
||||
50
docs/gyms/tiny_sword/buildings/castle/castle.tscn
Normal file
50
docs/gyms/tiny_sword/buildings/castle/castle.tscn
Normal file
@@ -0,0 +1,50 @@
|
||||
[gd_scene format=3 uid="uid://cl05bdri38mxf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cjc0l13b07802" path="res://docs/gyms/tiny_sword/buildings/castle/castle.gd" id="1_cjtps"]
|
||||
[ext_resource type="Texture2D" uid="uid://cry4arn00kgrt" path="res://docs/gyms/tiny_sword/buildings/castle/Castle.png" id="1_tgvch"]
|
||||
[ext_resource type="PackedScene" uid="uid://dlidx2x0otpjg" path="res://core/prestige/prestige_panel.tscn" id="3_l7gct"]
|
||||
[ext_resource type="Script" uid="uid://cpfmctd4xsfho" path="res://docs/gyms/tiny_sword/buildings/castle/test_buff.gd" id="4_l7gct"]
|
||||
[ext_resource type="Resource" uid="uid://bjc6qmvr7pe12" path="res://docs/gyms/buffs/spawn_worker.tres" id="5_s3a5k"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tgvch"]
|
||||
size = Vector2(312, 198)
|
||||
|
||||
[node name="Castle" type="Node2D" unique_id=1966557957]
|
||||
script = ExtResource("1_cjtps")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1365573096]
|
||||
texture = ExtResource("1_tgvch")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=66203052]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=1342657556]
|
||||
position = Vector2(1, 22)
|
||||
shape = SubResource("RectangleShape2D_tgvch")
|
||||
|
||||
[node name="PrestigePanel" parent="." unique_id=245519778 instance=ExtResource("3_l7gct")]
|
||||
offset_left = 155.0
|
||||
offset_top = -80.0
|
||||
offset_right = 575.0
|
||||
offset_bottom = 126.0
|
||||
|
||||
[node name="TestBuff" type="PanelContainer" parent="." unique_id=2112401476]
|
||||
offset_left = 155.0
|
||||
offset_top = 157.0
|
||||
offset_right = 263.0
|
||||
offset_bottom = 197.0
|
||||
script = ExtResource("4_l7gct")
|
||||
buff_data = ExtResource("5_s3a5k")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="TestBuff" unique_id=1293262110]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="TestBuff/HBoxContainer" unique_id=1519392687]
|
||||
layout_mode = 2
|
||||
text = "Label"
|
||||
|
||||
[node name="Button" type="Button" parent="TestBuff/HBoxContainer" unique_id=1254643833]
|
||||
layout_mode = 2
|
||||
text = "Button"
|
||||
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_area_2d_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_area_2d_mouse_exited"]
|
||||
112
docs/gyms/tiny_sword/buildings/castle/test_buff.gd
Normal file
112
docs/gyms/tiny_sword/buildings/castle/test_buff.gd
Normal file
@@ -0,0 +1,112 @@
|
||||
extends PanelContainer
|
||||
|
||||
@export var buff_data: GeneratorBuffData
|
||||
|
||||
@onready var _label: Label = $HBoxContainer/Label
|
||||
@onready var _button: Button = $HBoxContainer/Button
|
||||
|
||||
var _current_level: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if buff_data != null:
|
||||
_label.text = buff_data.text if not buff_data.text.is_empty() else str(buff_data.id)
|
||||
_button.text = "Buy"
|
||||
_button.disabled = true
|
||||
else:
|
||||
_label.text = "No Buff"
|
||||
_button.text = "Disabled"
|
||||
_button.disabled = true
|
||||
|
||||
_button.pressed.connect(_on_button_pressed)
|
||||
GameState.buff_level_changed.connect(_on_buff_level_changed)
|
||||
GameState.buff_unlocked_changed.connect(_on_buff_unlocked_changed)
|
||||
GameState.currency_changed.connect(_on_currency_changed)
|
||||
_update_ui()
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
if buff_data == null:
|
||||
return
|
||||
|
||||
var cost_currency_id: StringName = _resolve_buff_cost_currency_id(buff_data)
|
||||
if cost_currency_id == &"":
|
||||
push_warning("test_buff: Invalid cost currency")
|
||||
return
|
||||
|
||||
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
|
||||
if GameState.spend_currency_by_id(cost_currency_id, cost):
|
||||
var next_level: int = _current_level + 1
|
||||
GameState.set_buff_level(buff_data.id, next_level)
|
||||
_apply_buff_effect(buff_data, next_level)
|
||||
_current_level = next_level
|
||||
_update_ui()
|
||||
else:
|
||||
push_warning("test_buff: Not enough currency to buy buff")
|
||||
|
||||
|
||||
func _apply_buff_effect(buff: GeneratorBuffData, level: int) -> void:
|
||||
if buff.kind != GeneratorBuffData.BuffKind.RESOURCE_PURCHASE:
|
||||
return
|
||||
|
||||
var target_currency_id: StringName = _resolve_buff_target_currency_id(buff)
|
||||
if target_currency_id == &"":
|
||||
return
|
||||
|
||||
var purchased_amount: BigNumber = buff.get_resource_purchase_amount_for_level(level)
|
||||
if purchased_amount.mantissa > 0.0:
|
||||
GameState.add_currency_by_id(target_currency_id, purchased_amount)
|
||||
|
||||
|
||||
func _resolve_buff_target_currency_id(buff: GeneratorBuffData) -> StringName:
|
||||
if buff.resource_target_currency == null:
|
||||
return &""
|
||||
|
||||
return CurrencyDatabase.get_currency_id(buff.resource_target_currency)
|
||||
|
||||
|
||||
func _on_buff_level_changed(buff_id: StringName, new_level: int) -> void:
|
||||
if buff_data != null and buff_id == buff_data.id:
|
||||
_current_level = new_level
|
||||
_update_ui()
|
||||
|
||||
|
||||
func _on_buff_unlocked_changed(buff_id: StringName, unlocked: bool) -> void:
|
||||
if buff_data != null and buff_id == buff_data.id:
|
||||
_update_ui()
|
||||
|
||||
func _on_currency_changed(_changed_currency_id: StringName, _new_value: BigNumber) -> void:
|
||||
_update_ui()
|
||||
|
||||
func _update_ui() -> void:
|
||||
if buff_data == null:
|
||||
return
|
||||
|
||||
if not GameState.is_buff_unlocked(buff_data.id):
|
||||
_button.disabled = true
|
||||
_button.text = "Locked"
|
||||
return
|
||||
|
||||
var is_maxed: bool = _current_level >= buff_data.max_level if buff_data.max_level >= 0 else false
|
||||
var can_buy: bool = not is_maxed
|
||||
|
||||
var cost_currency_id: StringName = _resolve_buff_cost_currency_id(buff_data)
|
||||
if cost_currency_id != &"":
|
||||
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
|
||||
var current_amount: BigNumber = GameState.get_currency_amount_by_id(cost_currency_id)
|
||||
can_buy = can_buy and (current_amount.is_greater_than(cost) or current_amount.is_equal_to(cost))
|
||||
|
||||
_button.disabled = not can_buy
|
||||
|
||||
if is_maxed:
|
||||
_button.text = "Maxed"
|
||||
else:
|
||||
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
|
||||
_button.text = "Buy (%s)" % cost.to_string_suffix(2)
|
||||
|
||||
|
||||
func _resolve_buff_cost_currency_id(buff: GeneratorBuffData) -> StringName:
|
||||
if buff.cost_currency == null:
|
||||
return &""
|
||||
|
||||
return CurrencyDatabase.get_currency_id(buff.cost_currency)
|
||||
1
docs/gyms/tiny_sword/buildings/castle/test_buff.gd.uid
Normal file
1
docs/gyms/tiny_sword/buildings/castle/test_buff.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cpfmctd4xsfho
|
||||
Reference in New Issue
Block a user