Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion entities/ui/main_menu/scenes/MainMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
[ext_resource type="Script" uid="uid://cbevbiicfyjvm" path="res://entities/ui/special_event_area/scripts/SpecialEvent.gd" id="32_v1oo8"]
[ext_resource type="Resource" uid="uid://ran18u8hj7hb" path="res://entities/ui/special_event_area/events/SamuelBirthdayEvent.tres" id="33_bpb6p"]
[ext_resource type="Resource" uid="uid://n7irgub8gja5" path="res://entities/ui/special_event_area/events/SamoryBirthdayEvent.tres" id="34_bpb6p"]
[ext_resource type="Resource" uid="uid://jh7sgg0s0bjs" path="res://entities/ui/special_event_area/events/EasternEvent.tres" id="36_igcei"]

[sub_resource type="Resource" id="Resource_exu4r"]
script = ExtResource("4_psgpi")
Expand Down Expand Up @@ -378,7 +379,7 @@ theme_override_constants/margin_bottom = 10

[node name="SpecialEventArea" parent="BottomLeftDock" unique_id=1164238996 instance=ExtResource("31_seyqs")]
layout_mode = 2
all_events = Array[ExtResource("32_v1oo8")]([ExtResource("33_bpb6p"), ExtResource("34_bpb6p")])
all_events = Array[ExtResource("32_v1oo8")]([ExtResource("33_bpb6p"), ExtResource("34_bpb6p"), ExtResource("36_igcei")])

[connection signal="pressed" from="CenterMainMenu/MainMenuButtonContainer/MainMenuMarginContainer/MainMenuBox/Quick Game AI" to="AvailableAiModes" method="toggle_menu"]
[connection signal="enter_animation_done" from="CenterMainMenu/MainMenuButtonContainer/MainMenuMarginContainer/MainMenuBox/Quit/ControlAnimationComponent" to="CenterMainMenu/MainMenuButtonContainer/MainMenuMarginContainer/MainMenuBox" method="enable_mouse_input"]
Expand Down
18 changes: 18 additions & 0 deletions entities/ui/special_event_area/events/EasternEvent.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[gd_resource type="Resource" script_class="SpecialEvent" format=3 uid="uid://jh7sgg0s0bjs"]

[ext_resource type="Script" uid="uid://cbevbiicfyjvm" path="res://entities/ui/special_event_area/scripts/SpecialEvent.gd" id="1_vb34f"]
[ext_resource type="Resource" uid="uid://dfmjcesfyd2bc" path="res://shared/resources/translations/assets/EasternEventHeadline.tres" id="1_wim2f"]
[ext_resource type="Resource" uid="uid://5h1jddv6fiha" path="res://shared/resources/translations/assets/EasternEventBody.tres" id="2_5pghi"]
[ext_resource type="Script" uid="uid://bs1e8fpwn6ibn" path="res://entities/ui/special_event_area/scripts/validations/EasternDateValidation.gd" id="2_yddd5"]

[sub_resource type="Resource" id="Resource_yddd5"]
script = ExtResource("2_yddd5")
process_text = true
metadata/_custom_type_script = "uid://bs1e8fpwn6ibn"

[resource]
script = ExtResource("1_vb34f")
event_name = ExtResource("1_wim2f")
event_text = ExtResource("2_5pghi")
validation = SubResource("Resource_yddd5")
metadata/_custom_type_script = "uid://cbevbiicfyjvm"
13 changes: 10 additions & 3 deletions entities/ui/special_event_area/events/SamoryBirthdayEvent.tres
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
[ext_resource type="Script" uid="uid://cbevbiicfyjvm" path="res://entities/ui/special_event_area/scripts/SpecialEvent.gd" id="1_bedju"]
[ext_resource type="Resource" uid="uid://bg2bjo5tx1kuf" path="res://shared/resources/translations/assets/BirthdayEventHeadline.tres" id="1_wcubf"]
[ext_resource type="Resource" uid="uid://01yj14dlfdyg" path="res://shared/resources/translations/assets/SamoryBirthDayText.tres" id="2_uw6gj"]
[ext_resource type="Script" uid="uid://h56nmivkqfys" path="res://entities/ui/special_event_area/scripts/validations/FixedDateValidation.gd" id="4_k6m12"]

[sub_resource type="Resource" id="Resource_lb4pf"]
script = ExtResource("4_k6m12")
valid_year = 2024
valid_month = 10
valid_day = 4
process_text = true
metadata/_custom_type_script = "uid://h56nmivkqfys"

[resource]
script = ExtResource("1_bedju")
event_name = ExtResource("1_wcubf")
event_text = ExtResource("2_uw6gj")
valid_month = 10
valid_day = 4
year = 2024
validation = SubResource("Resource_lb4pf")
metadata/_custom_type_script = "uid://cbevbiicfyjvm"
13 changes: 10 additions & 3 deletions entities/ui/special_event_area/events/SamuelBirthdayEvent.tres
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
[ext_resource type="Resource" uid="uid://bg2bjo5tx1kuf" path="res://shared/resources/translations/assets/BirthdayEventHeadline.tres" id="1_4v6lf"]
[ext_resource type="Resource" uid="uid://ipxe810ybd0w" path="res://shared/resources/translations/assets/SamuelBirthdayEventBody.tres" id="2_lb4pf"]
[ext_resource type="Script" uid="uid://cbevbiicfyjvm" path="res://entities/ui/special_event_area/scripts/SpecialEvent.gd" id="3_vt4fd"]
[ext_resource type="Script" uid="uid://h56nmivkqfys" path="res://entities/ui/special_event_area/scripts/validations/FixedDateValidation.gd" id="4_lb4pf"]

[sub_resource type="Resource" id="Resource_8rpam"]
script = ExtResource("4_lb4pf")
valid_year = 2021
valid_month = 7
valid_day = 31
process_text = true
metadata/_custom_type_script = "uid://h56nmivkqfys"

[resource]
script = ExtResource("3_vt4fd")
event_name = ExtResource("1_4v6lf")
event_text = ExtResource("2_lb4pf")
valid_month = 7
valid_day = 31
year = 2021
validation = SubResource("Resource_8rpam")
metadata/_custom_type_script = "uid://cbevbiicfyjvm"
32 changes: 7 additions & 25 deletions entities/ui/special_event_area/scripts/SpecialEvent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,18 @@ class_name SpecialEvent extends Resource

@export var event_name: TextTranslation = null
@export var event_text: TextTranslation = null
@export_group("Valid Date")
@export_enum("January:1",
"February:2",
"March:3",
"April:4",
"Mai:5",
"June:6",
"July:7",
"August:8",
"September:9",
"October:10",
"November:11",
"December:12") var valid_month: int = 1
@export_range(1, 31, 1.0) var valid_day: int = 1
## This value is getting used to calculate the difference between the current year and the year provided
@export var year: int = 2026
@export var validation: SpecialEventValidation

func is_valid_today(year: int, month: int, day: int) -> bool:
return _content_valid() and validation.validate(year, month, day)

func is_valid_today(day: int, month: int ) -> bool:
var content_present: bool = event_name != null and event_text != null
return content_present and valid_month == month and valid_day == day
func _content_valid() -> bool:
return event_name != null and event_text != null and validation != null

func get_text() -> String:
func get_text(year: int, month: int, day: int) -> String:
var text: String = tr(event_text.key)
text = text.replace("%DATE%", _get_date_template())
text = text.replace("%DIFFERENCE%", str(Time.get_date_dict_from_system()["year"] - year))
return "[center]%s[/center][hr][br]%s" % [_get_headline(), text]
return "[center]%s[/center][hr][br]%s" % [_get_headline(), validation.text_processor(text, year, month, day)]

func _get_headline() -> String:
return tr(event_name.key)

func _get_date_template() -> String:
return "%02d.%02d" % [valid_day, valid_month]
4 changes: 3 additions & 1 deletion entities/ui/special_event_area/scripts/SpecialEventArea.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ func _ready() -> void:
func get_valid_events() -> Array[SpecialEvent]:
var valid: Array[SpecialEvent] = []
var date_dictionary: Dictionary = Time.get_date_dict_from_system()
var year: int = date_dictionary.get("year")
var month: int = date_dictionary.get("month")
var day: int = date_dictionary.get("day")
for event: SpecialEvent in all_events:
if event.is_valid_today(day, month):
if event.is_valid_today(year, month, day):
valid.append(event)

return valid

7 changes: 5 additions & 2 deletions entities/ui/special_event_area/scripts/SpecialEventBox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ func set_event(event: SpecialEvent) -> void:
func _ready() -> void:
if _event == null:
queue_free()

text_changed.emit(_event.get_text())
var date_dictionary: Dictionary = Time.get_date_dict_from_system()
var year: int = date_dictionary.get("year")
var month: int = date_dictionary.get("month")
var day: int = date_dictionary.get("day")
text_changed.emit(_event.get_text(year, month, day))
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class_name EasternDateValidation extends SpecialEventValidation
## Calculation is based on https://www.scientificamerican.com/article/the-mathematical-formula-that-reveals-when-easter-is-every-year/

const MARCH_MONTH_NUMBER: int = 3
const MARCH_NUMBER_OF_DAYS: int = 31

func validate(year: int, month: int, day: int) -> bool:
var a: int = year % 19
var b: int = year % 4
var c: int = year % 7

var k: int = floori(year / 100)
var p: int = floori(k / 3)
var q: int = floori(k / 4)

var m: int = 15 + k - p - q
var d: int = (m + 19 * a) % 30

var n: int = (4 + k - q) % 7
var e: int = (2 * b +4 * c + 6 * d + n) % 7
var day_of_month: int = 22 + d + e
if d == 29 and e == 6:
day_of_month = 50
if d == 28 and e == 6 and a > 10:
day_of_month = 49

var eastern_month: int = MARCH_MONTH_NUMBER
if day_of_month > MARCH_NUMBER_OF_DAYS:
day_of_month -= MARCH_NUMBER_OF_DAYS
eastern_month += 1

return eastern_month == month and day_of_month == day

func _process_text(translated_text: String, year: int, _month: int, _day: int) -> String:
return translated_text.replace("%YEAR%", str(year))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bs1e8fpwn6ibn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class_name FixedDateValidation extends SpecialEventValidation

@export_group("Valid year")
## If this is set to true, you need to enter a year. This event will only be active if the provided year is set
@export var single_event: bool = false
## The time this event appear the first time, if single event is set the event will only be shown in that year and never again
## This will also be used to calculate the difference between the actual year and this value
@export_range(2000, 3000, 1) var valid_year: int = 2000
@export_group("Valid Date")
@export_enum("January:1",
"February:2",
"March:3",
"April:4",
"Mai:5",
"June:6",
"July:7",
"August:8",
"September:9",
"October:10",
"November:11",
"December:12") var valid_month: int = 1
@export_range(1, 31, 1.0) var valid_day: int = 1

func validate(year: int, month: int, day: int) -> bool:
var year_check: bool = not single_event or year == valid_year
return year_check and month == valid_month and valid_day == day

func _process_text(translated_text: String, year: int, month: int, day: int) -> String:
translated_text = translated_text.replace("%DATE%", _get_date_template(year, month, day))
translated_text = translated_text.replace("%DIFFERENCE%", str(year - valid_year))
return translated_text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://h56nmivkqfys
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@abstract class_name SpecialEventValidation extends Resource

## Should the text be changed by adding date related information to it?
@export var process_text: bool = false

func text_processor(translated_text: String, year: int, month: int, day: int) -> String:
if process_text:
return _process_text(translated_text, year, month, day)
return translated_text

func _get_date_template(year: int, month: int, day: int) -> String:
return "%02d.%02d.%04d" % [day, month, year]

@abstract func validate(year: int, month: int, day: int) -> bool

@abstract func _process_text(translated_text: String, year: int, month: int, day: int) -> String
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://civk7f0npvw2f
23 changes: 15 additions & 8 deletions locale/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ msgstr ""
msgid "GAME_STATISTIC"
msgstr "[center]Spiele Statistik[/center]"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "PLAYER_TITLE"
msgstr "Spielername"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "PLAYER_SCORE"
msgstr "[right]Punktzahl[/right]"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "REPLAY"
msgstr "Erneut spielen"
Expand Down Expand Up @@ -1500,9 +1492,24 @@ msgstr ""
"Der Tag an dem dieses Spiel erstellt worden ist. Samory wird heute also [b]"
"%DIFFERENCE% Jahre[/b] alt."

#. TRANSLATORS: Can contain a "%YEAR%" variable, getting replaced by the current year
#: shared/resources/translations/assets/EasternEventBody.tres
msgid "EASTERN_EVENT_BODY"
msgstr "Ich wünsche dir frohe Ostern %YEAR%"

#: shared/resources/translations/assets/EasternEventHeadline.tres
msgid "EASTERN_EVENT_HEADLINE"
msgstr "Frohe Ostern"

msgid "Samory"
msgstr ""

#~ msgid "PLAYER_TITLE"
#~ msgstr "Spielername"

#~ msgid "PLAYER_SCORE"
#~ msgstr "[right]Punktzahl[/right]"

#~ msgid "BODY"
#~ msgstr "Körper"

Expand Down
23 changes: 15 additions & 8 deletions locale/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ msgstr ""
msgid "GAME_STATISTIC"
msgstr "[center]Game Statistic[/center]"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "PLAYER_TITLE"
msgstr "Player name"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "PLAYER_SCORE"
msgstr "[right]Player Score[/right]"

#: entities/game/finish_game/scenes/FinishGame.tscn
msgid "REPLAY"
msgstr "Replay"
Expand Down Expand Up @@ -1407,9 +1399,24 @@ msgstr ""
"The day this game was created initially. Samory is [b]%DIFFERENCE% years[/b] "
"old today."

#. TRANSLATORS: Can contain a "%YEAR%" variable, getting replaced by the current year
#: shared/resources/translations/assets/EasternEventBody.tres
msgid "EASTERN_EVENT_BODY"
msgstr "Wishing you a very happy Easter %YEAR%"

#: shared/resources/translations/assets/EasternEventHeadline.tres
msgid "EASTERN_EVENT_HEADLINE"
msgstr "Eastern"

msgid "Samory"
msgstr ""

#~ msgid "PLAYER_TITLE"
#~ msgstr "Player name"

#~ msgid "PLAYER_SCORE"
#~ msgstr "[right]Player Score[/right]"

#~ msgid "BODY"
#~ msgstr "Body"

Expand Down
Loading
Loading