From 1a6dd05f13d7afb312332c9636436cadcf01639b Mon Sep 17 00:00:00 2001
From: jacob janzen <53062115+JacobJanzen@users.noreply.github.com>
Date: Sat, 16 Nov 2024 11:43:41 -0600
Subject: Stonks for real this time (#2)

* start labels

* stonks

* stonks for real this time
---
 scenes/stockticker/Stock Ticker.tscn    |  92 ++++++++++++------
 scenes/stockticker/buy_n_sell.gd        |  25 -----
 scenes/stockticker/fishe/gar.png        | Bin 0 -> 64014 bytes
 scenes/stockticker/fishe/gar.png.import |  34 +++++++
 scenes/stockticker/stonks.gd            | 161 +++++++++++++++++++++++++++-----
 5 files changed, 234 insertions(+), 78 deletions(-)
 delete mode 100644 scenes/stockticker/buy_n_sell.gd
 create mode 100644 scenes/stockticker/fishe/gar.png
 create mode 100644 scenes/stockticker/fishe/gar.png.import

(limited to 'scenes')

diff --git a/scenes/stockticker/Stock Ticker.tscn b/scenes/stockticker/Stock Ticker.tscn
index 9352ef8..f3abfc7 100644
--- a/scenes/stockticker/Stock Ticker.tscn	
+++ b/scenes/stockticker/Stock Ticker.tscn	
@@ -1,20 +1,21 @@
-[gd_scene load_steps=9 format=3 uid="uid://g2veoq55y14i"]
+[gd_scene load_steps=10 format=3 uid="uid://g2veoq55y14i"]
 
 [ext_resource type="Texture2D" uid="uid://voruypgyi77e" path="res://scenes/stockticker/UI-Background-Colour.png" id="1_wbfee"]
 [ext_resource type="Script" path="res://scenes/stockticker/stonks.gd" id="2_pan4m"]
 [ext_resource type="Theme" uid="uid://ve18rbkeiwti" path="res://UI/text.tres" id="3_dv3dr"]
-[ext_resource type="Script" path="res://scenes/stockticker/buy_n_sell.gd" id="4_l8sru"]
 [ext_resource type="Texture2D" uid="uid://vie3nmimge1t" path="res://scenes/stockticker/BuyButton.png" id="5_mpf30"]
 [ext_resource type="Texture2D" uid="uid://dvidbk3clx6dn" path="res://scenes/stockticker/BuyButtonPressed.png" id="6_styy2"]
 [ext_resource type="Texture2D" uid="uid://dw8wpd47me7wu" path="res://scenes/stockticker/SellButton.png" id="7_h6hir"]
 [ext_resource type="Texture2D" uid="uid://b773rtpy6rtx5" path="res://scenes/stockticker/SellButtonPressed.png" id="8_essj7"]
+[ext_resource type="Theme" uid="uid://duy8w6dc8ebi3" path="res://UI/darksouls.tres" id="8_yqn4n"]
+[ext_resource type="Texture2D" uid="uid://dpp7abs35p6i5" path="res://scenes/stockticker/fishe/gar.png" id="9_bv8iw"]
 
 [node name="Node2D" type="Node2D"]
 
 [node name="Background" type="Sprite2D" parent="."]
 modulate = Color(0.796078, 0.796078, 0.796078, 1)
-position = Vector2(576.25, 323.75)
-scale = Vector2(1153.5, 648.5)
+position = Vector2(639.75, 359.75)
+scale = Vector2(1280.5, 720.5)
 texture = ExtResource("1_wbfee")
 
 [node name="Timer" type="Timer" parent="."]
@@ -23,7 +24,15 @@ autostart = true
 [node name="Stonks" type="Node2D" parent="."]
 script = ExtResource("2_pan4m")
 
-[node name="Sprite2D" type="Sprite2D" parent="Stonks"]
+[node name="SellButton" type="TextureButton" parent="Stonks"]
+offset_left = 439.0
+offset_top = 565.0
+offset_right = 794.0
+offset_bottom = 694.0
+texture_normal = ExtResource("7_h6hir")
+texture_pressed = ExtResource("8_essj7")
+
+[node name="StonkWindow" type="Sprite2D" parent="Stonks"]
 position = Vector2(582, 205)
 scale = Vector2(1062.25, 337)
 texture = ExtResource("1_wbfee")
@@ -79,44 +88,67 @@ text = "0"
 horizontal_alignment = 1
 
 [node name="Stonks" type="Line2D" parent="Stonks"]
+width = 2.0
+default_color = Color(1, 0, 0, 1)
 
 [node name="Price Label" type="Label" parent="Stonks"]
-offset_left = 387.0
-offset_top = 387.0
-offset_right = 1112.0
-offset_bottom = 452.0
+offset_left = 26.0
+offset_top = 476.0
+offset_right = 751.0
+offset_bottom = 541.0
 theme = ExtResource("3_dv3dr")
 text = "Price:
 $"
 
-[node name="BuyNSell" type="Node2D" parent="."]
-script = ExtResource("4_l8sru")
-
-[node name="BuyButton" type="TextureButton" parent="BuyNSell"]
+[node name="BuyButton" type="TextureButton" parent="Stonks"]
 offset_left = 54.0
-offset_top = 475.0
+offset_top = 563.0
 offset_right = 409.0
-offset_bottom = 604.0
+offset_bottom = 692.0
 texture_normal = ExtResource("5_mpf30")
 texture_pressed = ExtResource("6_styy2")
 
-[node name="SellButton" type="TextureButton" parent="BuyNSell"]
-offset_left = 441.0
-offset_top = 477.0
-offset_right = 796.0
-offset_bottom = 606.0
-texture_normal = ExtResource("7_h6hir")
-texture_pressed = ExtResource("8_essj7")
-
-[node name="Shares Held Label" type="Label" parent="BuyNSell"]
-offset_left = 6.0
-offset_top = 390.0
-offset_right = 336.0
-offset_bottom = 455.0
+[node name="Shares Held Label" type="Label" parent="Stonks"]
+offset_left = 29.0
+offset_top = 388.0
+offset_right = 359.0
+offset_bottom = 453.0
 theme = ExtResource("3_dv3dr")
 text = "Shares
 Held:"
 
+[node name="DarkSoulsTextBox" type="Sprite2D" parent="Stonks"]
+visible = false
+self_modulate = Color(0, 0, 0, 0.721569)
+position = Vector2(639.937, 355.875)
+scale = Vector2(1279.88, 260.25)
+texture = ExtResource("1_wbfee")
+
+[node name="DarkSoulsLabel" type="Label" parent="Stonks"]
+visible = false
+offset_left = 64.0
+offset_top = 258.0
+offset_right = 1209.0
+offset_bottom = 450.0
+theme = ExtResource("8_yqn4n")
+text = "Stock Bankrupt"
+horizontal_alignment = 1
+
+[node name="Sprite2D" type="Sprite2D" parent="."]
+position = Vector2(1036, 555)
+scale = Vector2(0.671875, 0.622)
+texture = ExtResource("9_bv8iw")
+
+[node name="Label" type="Label" parent="."]
+offset_left = 823.0
+offset_top = 588.0
+offset_right = 1082.0
+offset_bottom = 785.0
+theme = ExtResource("3_dv3dr")
+theme_override_colors/font_color = Color(0, 0, 0, 1)
+theme_override_font_sizes/font_size = 82
+text = "GAR"
+
 [connection signal="timeout" from="Timer" to="Stonks" method="_on_timer_timeout"]
-[connection signal="button_up" from="BuyNSell/BuyButton" to="BuyNSell" method="_on_buy_button_button_up"]
-[connection signal="button_up" from="BuyNSell/SellButton" to="BuyNSell" method="_on_sell_button_button_up"]
+[connection signal="button_up" from="Stonks/SellButton" to="Stonks" method="_on_sell_button_button_up"]
+[connection signal="button_up" from="Stonks/BuyButton" to="Stonks" method="_on_buy_button_button_up"]
diff --git a/scenes/stockticker/buy_n_sell.gd b/scenes/stockticker/buy_n_sell.gd
deleted file mode 100644
index be0e777..0000000
--- a/scenes/stockticker/buy_n_sell.gd
+++ /dev/null
@@ -1,25 +0,0 @@
-extends Node2D
-
-var stonks = 0
-
-# Called when the node enters the scene tree for the first time.
-func _ready() -> void:
-	var label = $"Shares Held Label"
-	label.text = "Shares\nHeld:%d" % stonks
-
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(delta: float) -> void:
-	pass
-
-
-func _on_buy_button_button_up() -> void:
-	if stonks < 100:
-		stonks += 1
-		var label = $"Shares Held Label"
-		label.text = "Shares\nHeld:%d" % stonks
-
-func _on_sell_button_button_up() -> void:
-	if stonks > 0:
-		stonks -= 1
-		var label = $"Shares Held Label"
-		label.text = "Shares\nHeld:%d" % stonks
diff --git a/scenes/stockticker/fishe/gar.png b/scenes/stockticker/fishe/gar.png
new file mode 100644
index 0000000..658fa5e
Binary files /dev/null and b/scenes/stockticker/fishe/gar.png differ
diff --git a/scenes/stockticker/fishe/gar.png.import b/scenes/stockticker/fishe/gar.png.import
new file mode 100644
index 0000000..428ca58
--- /dev/null
+++ b/scenes/stockticker/fishe/gar.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dpp7abs35p6i5"
+path="res://.godot/imported/gar.png-de723b6b5530a2f3aa7ae68d1173ed75.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://scenes/stockticker/fishe/gar.png"
+dest_files=["res://.godot/imported/gar.png-de723b6b5530a2f3aa7ae68d1173ed75.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+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/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
diff --git a/scenes/stockticker/stonks.gd b/scenes/stockticker/stonks.gd
index fefc340..508fb82 100644
--- a/scenes/stockticker/stonks.gd
+++ b/scenes/stockticker/stonks.gd
@@ -1,52 +1,167 @@
 extends Node2D
 
+const MAX_PRICES = 15
+
+const Y_START = 60
+const Y_END = 356
+const X_START = 50
+const X_END = 1000
+
+var price_label
+var shares_label
+var top_label
+var mid_label
+var bottom_label
+var darksouls_background: Sprite2D
+var darksouls_text: Label
+
 var price_history = []
-var max_prices = 15
-var max_up_multiplier = 2
-var max_down_multiplier = 2
+var base_pos_mult = 0.5 # no size limit
+var base_neg_mult = 0.5 # probably keep this below 1
+
+var hype_mult = 1.0
+var hype_decr = 0.1
+var hype_inc = 0.05
+var panic_mult = 1.0
+var panic_decr = 0.1
+var panic_inc = 0.01
+
 var bailout_counter = 0
 var bailout_time = 1
 
-var bailout_price = 5
-var start_val = 5
+var bailout_price = Big.new(5)
+var start_val = Big.new(5)
 var prev_price = start_val
 
+var shares = 0
+
+func handle_bailout(new_price: Big) -> Big:
+	if bailout_counter < bailout_time:
+		new_price = Big.new(0)
+		bailout_counter += 1
+	else:
+		darksouls_background.visible = true
+		darksouls_text.visible = true
+		darksouls_text.text = "Bailed Out"
+		new_price = bailout_price
+		bailout_counter = 0
+		bailout_time *= 2
+		panic_mult = 1.0
+		hype_mult = 1.0
+		
+	return new_price
+	
+func draw_stonks(minval: Big, maxval: Big) -> void:
+	var stonks: Line2D = $Stonks
+	stonks.clear_points()
+	
+	var index = 0
+	var x_delta = (X_END - X_START)/float(len(price_history)-1)
+	var y_range = Big.new(Y_END - Y_START)
+	var price_range = maxval.minus(minval)
+	for price: Big in price_history:
+		var x_pos = x_delta * index + X_START
+		var y_pos = Y_END
+		if price_range.isGreaterThan(0.001):
+			var price_ratio = (price.minus(minval)).dividedBy(price_range)
+			y_pos = float(Big.new(Y_END).minus(y_range.times(price_ratio)).toString())
+		var pos = Vector2(x_pos, y_pos)
+		stonks.add_point(pos, index)
+		index += 1
+	
+func get_min_price() -> Big:
+	var minval = Big.new(-1)
+	for price in price_history:
+		if price.isLessThan(minval) or minval.isLessThan(0):
+			minval = price
+	return minval
+	
+func get_max_price() -> Big:
+	var maxval = Big.new(-1)
+	for price in price_history:
+		if price.isGreaterThan(maxval):
+			maxval = price
+	return maxval
+
 # Called when the node enters the scene tree for the first time.
 func _ready() -> void:
-	print(start_val)
-	var label = $"Price Label"
-	label.text = "Price:\n$%f" % start_val
+	price_label = $"Price Label"
+	shares_label = $"Shares Held Label"
+	top_label = $Top
+	mid_label = $Middle
+	bottom_label = $Bottom
+	darksouls_background = $DarkSoulsTextBox
+	darksouls_text = $DarkSoulsLabel
+	
+	price_label.text = "Price:\n$%s" % start_val.toString()
 	price_history.push_front(start_val)
+	
+	shares_label.text = "Shares\nHeld:%d" % shares
 
  
 # Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(delta: float) -> void:
+func _process(_delta: float) -> void:
 	pass
 
 
 func _on_timer_timeout() -> void:
+	darksouls_background.visible = false
+	darksouls_text.visible = false
 	var new_price = prev_price
 	
-	if prev_price <= 0:
-		if bailout_counter < bailout_time:
-			new_price = 0
-			bailout_counter += 1
-		else:
-			new_price = bailout_price
-			bailout_counter = 0
+	hype_mult -= hype_decr
+	if hype_mult < 1: hype_mult = 1.0
+	
+	panic_mult -= panic_decr
+	if panic_mult < 1: panic_mult = 1.0
+		
+	if prev_price.isLessThanOrEqualTo(0):
+		new_price = handle_bailout(new_price)
 	elif randf() < 0.5:
-		new_price += 1 * max_up_multiplier * randf()
+		var mult = Big.new(1).plus(Big.new(base_pos_mult * hype_mult * randf()))
+		new_price = new_price.times(mult)
 	else:
-		new_price -= 1 * max_down_multiplier * randf()
+		var mult = Big.new(1).minus(Big.new(base_neg_mult * panic_mult * randf()))
+		new_price = new_price.times(mult)
 		
-	if new_price < 0: new_price = 0
+	if new_price.isLessThan(1) or new_price.toString()[0] == '-':
+		print(bailout_counter)
+		print(new_price.toString())
+		if bailout_counter == 0:
+			darksouls_background.visible = true
+			darksouls_text.visible = true
+			darksouls_text.text = "Stock Bankrupt"
+			new_price = Big.new(0)
+			shares = 0
+			shares_label.text = "Shares\nHeld:%d" % shares
 		
-	if len(price_history) >= max_prices:
+	if len(price_history) >= MAX_PRICES:
 		price_history.pop_front()
 	price_history.push_back(new_price)
 	prev_price = new_price
 	
-	var label = $"Price Label"
-	label.text = "Price:\n$%f" % new_price
+	price_label.text = "Price:\n$%s" % new_price.toString()
+	
+	var min_price = get_min_price()
+	var max_price = get_max_price()
+	var mean_price = min_price.plus(max_price).dividedBy(2)
 	
-	print(new_price)
+	top_label.text = "%s" % max_price.toScientific()
+	mid_label.text = "%s" % mean_price.toScientific()
+	bottom_label.text = "%s" % min_price.toScientific()
+	
+	draw_stonks(min_price, max_price)
+
+
+func _on_buy_button_button_up() -> void:
+	if shares < 100 and prev_price.isGreaterThan(0):
+		shares += 1
+		shares_label.text = "Shares\nHeld:%d" % shares
+		hype_mult += hype_inc
+
+
+func _on_sell_button_button_up() -> void:
+	if shares > 0:
+		shares -= 1
+		shares_label.text = "Shares\nHeld:%d" % shares
+		panic_mult += panic_inc
-- 
cgit v1.2.3