Rewrote news ticker

- Rewrote news ticker based on JSON web API tutorials
- Simplified json files for news ticker as part of rewrite
- Renamed /dialog to /json
This commit is contained in:
Tony Bark 2021-05-30 12:38:41 -04:00
parent b443ee61fe
commit ef6b097ef2
20 changed files with 170 additions and 71 deletions

10
json/ticker/adverts.json Normal file
View file

@ -0,0 +1,10 @@
{
"ticker": [
"[outlet]: Don't Blame Us If You're Not Paying Attention",
"[outlet]: Information With As Few Words As Possible.",
"This Space For Rent.",
"[outlet]: Properly Spelled Words From Beginning To End.",
"[outlet]: Journalistic Integrity Without All The Advertising.",
"[outlet]: No Advertisements Since Before The Beginning."
]
}

17
json/ticker/citylife.json Normal file
View file

@ -0,0 +1,17 @@
{
"ticker": [
"50 Car Pile-Up Results In New City Sculpture.",
"After 36 Years Of Marriage, Man Discovers Wife Is Actually A Rare Yucca Plant.",
"All Raccoons Cheat At Poker, Researchers Say.",
"Cat Hijacks Municipal Bus; Riders Applaud Good Timing At Stops And Courteous Meows.",
"Tommy B. Saif Sez: No Left Turn, Except Buses.",
"Truckload Of Apples Overturns, [city] Diner Offers Applesauce Special.",
"Ordinary Days In [city] Become Common.",
"Semicolon Declared Sexier Than Comma At Grammarian's Fete.",
"Spotted Owl Spotted.",
"Crime Lord Spotted In [city]; Mayor Says \"No Comment\".",
"Cat Burglar Spotted, Mistaken For Dalmatian.",
"Local citizens confused about New Spark Box Pro XL Series U.",
"Customers of the New Spark Box Pro XL Series U confirm that it has Knuckles."
]
}

View file

@ -0,0 +1,5 @@
{
"ticker": [
"Astronomer Warns of Physics Experiment That Could Destroy Our Entire Galaxy"
]
}

View file

@ -0,0 +1,11 @@
{
"ticker": [
"Local Merchants Puzzled By Rumors Of Kitty Kibble Shortage; \"We Have Plenty,\" Say Most.",
"No Kitty Kibble Shortage Says Local Representative Of Kitty Kibble Association.",
"Rumors Persist In Kitty Kibble Shortage; Unfounded Say Many.",
"Cats Say Not Enough Being Done In Kitty Kibble Shortage.",
"Cats Concerned By Rumors Of Kitty Kibble Shortage; Buy In Bulk.",
"Is Kitty Kibble Shortage A Hoax? Cats Search For Truth.",
"Enough Kitty Kibble For Twenty Years, Experts Agree."
]
}

8
json/ticker/sammy.json Normal file
View file

@ -0,0 +1,8 @@
{
"ticker": [
"From The Desk Of Wise Guy Sammy: One Word In This Ticker Is Mispelled.",
"From The Desk Of Wise Guy Sammy: One Word In This Ticker Is Sdrawkcab (Backwards).",
"From The Desk Of Wise Guy Sammy: It Is Easier To Get Forgiveness Than Permission.",
"From The Desk Of Wise Guy Sammy: You Can't Outwait A Bureaucracy."
]
}

View file

@ -132,7 +132,7 @@
"text": "[species] Discovers Picayune Newspaper Lying on the Ground; Throws It Away."
},
"55": {
"text": "Local [species] Bill Flopsby Heads County Commission On Snuggles And Hugs."
"text": "Local citizen, Bill Flopsby Heads County Commission On Snuggles And Hugs."
},
"56": {
"text": "[species] Offers To Let City Bus Run Him Over For Lifetime Salad Bar Privileges."

View file

@ -0,0 +1,5 @@
{
"tower_names": [
{}
]
}

View file

@ -25,6 +25,7 @@ config/windows_native_icon="res://icon.ico"
SimData="*res://scripts/autoload/sim_data.gd"
SimEvents="*res://scripts/autoload/sim_events.gd"
SimTime="*res://scripts/autoload/sim_time.gd"
ZoneData="*res://scripts/autoload/zone_data.gd"
[display]

View file

@ -29,9 +29,9 @@ func _init_advisor(file, advisor):
SimData.Advisors.CITY_PLANNER:
match file:
JsonFile.ANNOUNCEMENTS:
dialogue_file = "res://dialog/advisors/cityplanner.json"
dialogue_file = "res://json/advisors/cityplanner.json"
JsonFile.ANALYSIS:
dialogue_file = "res://dialog/policies/cityplanner_analysis.json"
dialogue_file = "res://json/policies/cityplanner_analysis.json"
avatar_texture.texture = preload("res://sprites/avatars/cindy.png")
name_label.text = "Cindy Diamond"
@ -40,9 +40,9 @@ func _init_advisor(file, advisor):
SimData.Advisors.FINANCIAL:
match file:
JsonFile.ANNOUNCEMENTS:
dialogue_file = "res://dialog/advisors/finacial.json"
dialogue_file = "res://json/advisors/finacial.json"
JsonFile.ANALYSIS:
dialogue_file = "res://dialog/policies/finacial_analysis.json"
dialogue_file = "res://json/policies/finacial_analysis.json"
avatar_texture.texture = preload("res://sprites/avatars/kit.png")
name_label.text = "Kit Welsh"
@ -51,9 +51,9 @@ func _init_advisor(file, advisor):
SimData.Advisors.TRANSPORT:
match file:
JsonFile.ANNOUNCEMENTS:
dialogue_file = "res://dialog/advisors/transport.json"
dialogue_file = "res://json/advisors/transport.json"
JsonFile.ANALYSIS:
dialogue_file = "res://dialog/policies/transport_analysis.json"
dialogue_file = "res://json/policies/transport_analysis.json"
avatar_texture.texture = preload("res://sprites/avatars/zc.png")
name_label.text = "Zack Casey"

View file

@ -0,0 +1,7 @@
extends Node
var power_grid: int # Number of power stations in the area. Helps provide redundancies.
var power_capacity: int
var current_power_cap: int
var prev_power_cap: int
var has_power: bool

View file

@ -14,18 +14,6 @@ var current_power_cap: int
var prev_power_cap: int
var has_power: bool
var res_tax: int = 1
var comm_tax: int = 1
var indust_tax: int = 1
var res_income: int
var comm_income: int
var ind_income: int
var fire_tax: int
var police_tax: int
var power_tax: int
var ticker_files: Array = [
"adverts.json",
"sammy.json"

View file

@ -0,0 +1,13 @@
extends Node
var res_tax: int = 1
var comm_tax: int = 1
var indust_tax: int = 1
var res_income: int
var comm_income: int
var ind_income: int
var fire_tax: int
var police_tax: int
var power_tax: int

View file

@ -11,32 +11,32 @@ onready var ind_rate = $PrecentCtr/IndPctLbl
onready var annual_income = $IncomeCtr/IcnomeLbl
func _ready():
if SimData.res_tax >= 0:
res_slider.value = SimData.res_tax
res_rate.text = str(SimData.res_tax) + "%"
if ZoneData.res_tax >= 0:
res_slider.value = ZoneData.res_tax
res_rate.text = str(ZoneData.res_tax) + "%"
if SimData.res_tax >= 0:
com_slider.value = SimData.comm_tax
com_rate.text = str(SimData.comm_tax) + "%"
if ZoneData.res_tax >= 0:
com_slider.value = ZoneData.comm_tax
com_rate.text = str(ZoneData.comm_tax) + "%"
if SimData.indust_tax >= 0:
ind_slider.value = SimData.indust_tax
ind_rate.text = str(SimData.indust_tax) + "%"
if ZoneData.indust_tax >= 0:
ind_slider.value = ZoneData.indust_tax
ind_rate.text = str(ZoneData.indust_tax) + "%"
func _process(delta):
var total_income = int(SimData.res_income + SimData.comm_income + SimData.ind_income)
var total_income = int(ZoneData.res_income + ZoneData.comm_income + ZoneData.ind_income)
if SimData.prev_month < SimData.month and total_income > 1:
if SimTime.prev_month < SimTime.month and total_income > 1:
annual_income.text = str(total_income) + "/mo"
func _on_ResSlider_value_changed(value):
SimData.res_tax = int(value)
ZoneData.res_tax = int(value)
res_rate.text = str(value) + "%"
func _on_ComSlider_value_changed(value):
SimData.comm_tax = int(value)
ZoneData.comm_tax = int(value)
com_rate.text = str(value) + "%"
func _on_IndSlider_value_changed(value):
SimData.indust_tax = int(value)
ZoneData.indust_tax = int(value)
ind_rate.text = str(value) + "%"

View file

@ -2,76 +2,110 @@ extends ColorRect
onready var ticker_text = $TickerTxt
var news_file = ""
const ticker_path = "res://json/ticker/"
var news_file: String = ""
var rng = RandomNumberGenerator.new()
var news_keys = []
var all_news = []
var speices = [
"Cat",
"Fennec",
"Fox"
]
var json_files = [
"adverts.json",
# "sammy.json"
]
func _index_news():
var news = _load_news()
news_keys.clear()
for key in news:
news_keys.append(news[key])
var news = _load_json()
all_news.clear()
all_news = news["ticker"]
randomize()
news_keys.shuffle()
all_news.shuffle()
func _process(delta):
var prev_json_Files = json_files
var city_life = [
"citylife.json",
"kittykibble.json"
]
if _array_check(city_life, json_files):
match SimData.has_power:
true:
prev_json_Files = json_files
for files in city_life:
json_files.append(files)
false:
prev_json_Files = json_files
for files in city_life:
json_files.append(files)
func _array_check(list1, list2):
for item in list1:
if item in list2:
return true
return false
func _load_news():
func _load_json():
var file = File.new()
if file.file_exists(news_file):
file.open(news_file, file.READ)
var dialogue = parse_json(file.get_as_text())
return dialogue
var result = parse_json(file.get_as_text())
return result
func _ready():
SimData.city_name = SimData.city_name.capitalize()
SimData.mayor_name = SimData.mayor_name.capitalize()
SimEvents.connect("send_alert", self, "_start_alert")
SimEvents.connect("resume_news", self, "_resume_ticker")
_random_news("res://dialog/ticker/ticker.json")
_random_news(json_files)
func _start_alert(message):
SimData.on_alert = true
news_file = "res://dialog/ticker/ticker_alerts.json"
ticker_text.text = news_keys[message].text
news_file = str(ticker_path + "ticker_alerts.json")
ticker_text = all_news
func _random_news(file):
news_file = file
func _random_news(files: Array):
for file in files:
news_file = str(ticker_path + file)
_load_json()
_index_news()
rng.randomize()
_load_news()
_index_news()
randomize()
all_news.shuffle()
var max_mange = news_keys.size() - 1
var ticker_range = rng.randi_range(0, max_mange)
var news = news_keys[ticker_range].text
var news_range = rng.randi_range(0, all_news.size() - 1)
var news_text: String = all_news[news_range]
if SimData.has_ctower or SimData.city_name == "Furtropolis" or "Furville" and "[outlet]" in news:
if SimData.has_ctower or SimData.city_name == "Furtropolis" or "Furville" and "[outlet]" in news_text:
# FNN = Furtropolis/Furry News Network
news = news.replace("[outlet]", "FNN")
elif "[outlet]" in news:
news = news.replace("[outlet]", "Pawprint Press")
if "[species]" in news:
news_text.replace("[outlet]", "FNN")
else:
news_text.replace("[outlet]", "Pawprint Press")
if "[species]" in news_text:
randomize()
speices.shuffle()
news = news.replace("[species]", speices[rng.randi()%speices.size()])
var speices_range = rng.randi_range(speices.size() - 1)
news_text.replace("[species]", speices[speices_range])
if "[city]" in news_text:
news_text.replace("[city]", SimData.city_name)
if "[mayor]" in news_text:
news_text.replace("[mayor]", SimData.mayor_name)
if "[city]" in news:
news = news.replace("[city]", SimData.city_name)
if "[mayor]" in news:
news = news.replace("[mayor]", SimData.mayor_name)
ticker_text.text = news
ticker_text.text = news_text
func _resume_ticker():
_random_news("res://dialog/ticker/ticker.json")
_random_news(json_files)
func _on_RotateNews_timeout():
_random_news("res://dialog/ticker/ticker.json")
_random_news(json_files)