Skip to content

Commit

Permalink
Moved away from http requests for fetching chapters
Browse files Browse the repository at this point in the history
Switch from downloading bible text from internet to using locally installed
copies. Added a word of jesus RichTextEffect. Applied smooth scrolling to bible
text view.
  • Loading branch information
GsLogiMaker committed Oct 8, 2022
1 parent 9a5409d commit 5cb4f90
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export_presets.cfg
data_*/
# Godot 4+ specific ignores
.godot/
Bibles/*
80 changes: 42 additions & 38 deletions BibleViwer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ const SAVE_FORMAT_VERSION:= 0

@export var chapter_tab:PackedScene

var bible_version:= "nkjv"
## An [Array] of the books of the bible.
var books:= []
var books:= load_book_names() as Array
## The currently selected chater tab.
var current_tab:int = -1
var to_book:String = "Genesis"
var to_chapter:int = 1
var fuzzy_books:Array = []
var font_size:= 16:
set(v):
Expand Down Expand Up @@ -57,25 +56,18 @@ func _ready() -> void:
%PageResolutionY.value
)

# Get books of bible
var outputs:= []
OS.execute("python3", ["Py/get_books.py"], outputs)
books = outputs[0].split(", ")
books.pop_back()
books = books.map(func(book:String):
book = book.strip_escapes()
return book.substr(0,book.length()-1)
)

load_settings()

if %ChapterTabs.get_child_count() == 0:
add_tab("Genesis", 1)


func add_tab(book:String, chapter:int) -> CanvasItem:
var new_tab:Node = chapter_tab.instantiate()
%ChapterTabs.add_child(new_tab)
new_tab.book = book
new_tab.chapter = chapter
new_tab.text = get_chapter_text(to_book, to_chapter)
new_tab.text = get_chapter_text(book, chapter)
new_tab.visible = false
new_tab.font_size = font_size
%ChapterTabBar.add_tab("%s %d" % [book, chapter])
Expand Down Expand Up @@ -104,19 +96,22 @@ func book_fuzzy_search(search_by:String) -> Array:
return closest_matches


func load_book_names() -> Array:
var file:= FileAccess.open("res://bibles.txt", FileAccess.READ)
var arr:= file.get_as_text().split("\n") as Array
arr.erase("")
return arr


func get_chapter_text(book:String, chapter:int) -> String:
var outputs:= []
OS.execute(
"python3",
[
"Py/nkjv_scraper.py",
"--site",
"https://www.biblegateway.com/passage/?search=%s+%d&version=%s"
% [book, chapter, "NKJV"]
],
outputs
)
return outputs[0]
var path:= "Bibles/%s/%s_%s.txt" \
% [bible_version, book.replace(" ", "_"), int(chapter)]
var file:= FileAccess.open(path, FileAccess.READ)

if file == null:
return ""

return file.get_as_text()


func get_saving_properties() -> Dictionary:
Expand All @@ -130,11 +125,19 @@ func get_saving_properties() -> Dictionary:


func goto_chapter(book:String, chapter:int) -> void:
var chapter_text:= get_chapter_text(book, chapter)
if chapter_text == "":
book = books[wrapi(books.find(book)+1, 0, books.size())]
chapter = 1
goto_chapter(book, chapter)

%SearchBook.text = book
%SearchChapter.value = chapter

var curr_chapter_tab:= %ChapterTabs.get_child(current_tab)
curr_chapter_tab.book = book
curr_chapter_tab.chapter = chapter
curr_chapter_tab.text = get_chapter_text(to_book, to_chapter)
curr_chapter_tab.text = get_chapter_text(book, chapter)
curr_chapter_tab.font_size = font_size
%ChapterTabBar.set_tab_title(current_tab, "%s %d" % [book, chapter])

Expand All @@ -152,7 +155,8 @@ func load_settings() -> void:
for prop in obj_meta.params:
var config_property:= "%s.%s"%[obj_meta.name, prop]
if config.has_section_key("data", config_property):
obj.set(prop, config.get_value("data", config_property))
var val = config.get_value("data", config_property)
obj.set(prop, val)


func remove_tab(tab_index:int) -> void:
Expand All @@ -168,7 +172,6 @@ func remove_tab(tab_index:int) -> void:
func save_settings() -> void:
var config:= ConfigFile.new()
config.set_value("meta", "format", SAVE_FORMAT_VERSION)
prints("_tabs", self._tabs)
var to_save:= get_saving_properties()
for obj in to_save:
var obj_meta:Dictionary = to_save[obj]
Expand All @@ -195,11 +198,9 @@ func switch_tab(tab_index:int) -> void:


func _on_fuzzy_book_pressed(button:Button) -> void:
to_book = button.text
%SearchBook.text = to_book
_on_search_book_text_changed(to_book)
_on_search_book_text_changed(button.text)
%SearchBook.grab_focus()
goto_chapter(to_book, to_chapter)
goto_chapter(button.text, %SearchChapter.value)


func _on_search_book_text_changed(new_text:String) -> void:
Expand All @@ -212,28 +213,26 @@ func _on_search_book_text_changed(new_text:String) -> void:
return

%FuzzyBooks.visible = true
to_book = str(fuzzy_books[0][0])
%FuzzyBook1.text = str(fuzzy_books[0][0])
%FuzzyBook2.text = str(fuzzy_books[1][0])
%FuzzyBook3.text = str(fuzzy_books[2][0])
%FuzzyBook4.text = str(fuzzy_books[3][0])


func _on_search_chapter_text_changed(value:int) -> void:
to_chapter = value
goto_chapter(to_book, to_chapter)
goto_chapter(%SearchBook.text, value)


func _on_search_enter(_p=null) -> void:
goto_chapter(to_book, to_chapter)
goto_chapter(%SearchBook.text, %SearchChapter.value)


func _on_tab_bar_tab_close_pressed(tab:int) -> void:
remove_tab(tab)


func _on_new_tab_pressed() -> void:
add_tab(to_book, to_chapter)
add_tab(%SearchBook.text, %SearchChapter.value)


func _on_chapter_tab_bar_tab_changed(tab: int) -> void:
Expand All @@ -258,3 +257,8 @@ func _on_page_resiazable_toggled(button_pressed: bool) -> void:
func _on_font_size_value_changed(value: float) -> void:
self.font_size = value
save_settings()


func _on_scroll_value_changed(value: float) -> void:
var scroll_cont:= %ChapterTabs.get_child(current_tab).get_node(^"%TextScroll")
scroll_cont.scroll_vertical = value * scroll_cont.get_child(0).get_rect().size.y
31 changes: 30 additions & 1 deletion BibleViwer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ chapter_tab = ExtResource("2_rn5h4")

[node name="ChapterTabs" type="MarginContainer" parent="."]
unique_name_in_owner = true
layout_mode = 2
offset_left = 5.0
offset_top = 5.0
offset_right = 1147.0
Expand All @@ -47,7 +48,7 @@ offset_bottom = 643.0
[node name="Window" type="Window" parent="."]
title = "Bible Reader Controls"
position = Vector2i(2000, 60)
size = Vector2i(334, 240)
size = Vector2i(334, 241)
current_screen = 1
wrap_controls = true

Expand All @@ -63,16 +64,19 @@ theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5

[node name="VBoxContainer" type="VBoxContainer" parent="Window/MarginContainer"]
layout_mode = 2
offset_left = 5.0
offset_top = 5.0
offset_right = 1147.0
offset_bottom = 643.0

[node name="TabControls" type="HBoxContainer" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_right = 1142.0
offset_bottom = 31.0

[node name="ScrollContainer" type="ScrollContainer" parent="Window/MarginContainer/VBoxContainer/TabControls"]
layout_mode = 2
offset_right = 1049.0
offset_bottom = 31.0
size_flags_horizontal = 3
Expand All @@ -81,52 +85,61 @@ vertical_scroll_mode = 0

[node name="ChapterTabBar" type="TabBar" parent="Window/MarginContainer/VBoxContainer/TabControls/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
offset_right = 1049.0
size_flags_horizontal = 3
clip_tabs = false
tab_close_display_policy = 2

[node name="NewTab" type="Button" parent="Window/MarginContainer/VBoxContainer/TabControls"]
layout_mode = 2
offset_left = 1053.0
offset_right = 1142.0
offset_bottom = 31.0
size_flags_vertical = 0
text = "+ New Tab"

[node name="BookSearchContainer" type="HBoxContainer" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_top = 35.0
offset_right = 1142.0
offset_bottom = 66.0

[node name="VBoxContainer" type="VBoxContainer" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer"]
layout_mode = 2
offset_right = 569.0
offset_bottom = 31.0
size_flags_horizontal = 3

[node name="SearchBook" type="LineEdit" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
offset_right = 569.0
offset_bottom = 31.0
focus_neighbor_right = NodePath("../../SearchChapter")
focus_neighbor_bottom = NodePath("../FuzzyBooks/VBoxContainer/FuzzyBook1")
focus_next = NodePath("../../SearchChapter")
text = "Genesis"
placeholder_text = "Book"
script = SubResource("GDScript_jd8xs")

[node name="FuzzyBooks" type="PanelContainer" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
offset_top = 35.0
offset_right = 569.0
offset_bottom = 67.0

[node name="VBoxContainer" type="VBoxContainer" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer/FuzzyBooks"]
layout_mode = 2
offset_right = 569.0
offset_bottom = 32.0
theme_override_constants/separation = 0

[node name="FuzzyBook1" type="Button" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer/FuzzyBooks/VBoxContainer" node_paths=PackedStringArray("shortcut_context")]
unique_name_in_owner = true
layout_mode = 2
offset_right = 569.0
offset_bottom = 8.0
shortcut = SubResource("Shortcut_apwqq")
Expand All @@ -136,6 +149,7 @@ alignment = 0

[node name="FuzzyBook2" type="Button" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer/FuzzyBooks/VBoxContainer" node_paths=PackedStringArray("shortcut_context")]
unique_name_in_owner = true
layout_mode = 2
offset_top = 8.0
offset_right = 569.0
offset_bottom = 16.0
Expand All @@ -145,6 +159,7 @@ alignment = 0

[node name="FuzzyBook3" type="Button" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer/FuzzyBooks/VBoxContainer" node_paths=PackedStringArray("shortcut_context")]
unique_name_in_owner = true
layout_mode = 2
offset_top = 16.0
offset_right = 569.0
offset_bottom = 24.0
Expand All @@ -154,6 +169,7 @@ alignment = 0

[node name="FuzzyBook4" type="Button" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer/VBoxContainer/FuzzyBooks/VBoxContainer" node_paths=PackedStringArray("shortcut_context")]
unique_name_in_owner = true
layout_mode = 2
offset_top = 24.0
offset_right = 569.0
offset_bottom = 32.0
Expand All @@ -164,17 +180,20 @@ alignment = 0

[node name="SearchChapter" type="SpinBox" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer"]
unique_name_in_owner = true
layout_mode = 2
offset_left = 573.0
offset_right = 1142.0
offset_bottom = 31.0
size_flags_horizontal = 3
size_flags_vertical = 0
min_value = 1.0
max_value = 1000.0
value = 1.0

[node name="SearchVerse" type="SpinBox" parent="Window/MarginContainer/VBoxContainer/BookSearchContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
offset_left = 764.0
offset_right = 1142.0
offset_bottom = 31.0
Expand All @@ -185,18 +204,21 @@ max_value = 200.0
value = 1.0

[node name="PageLabel" type="Label" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_top = 70.0
offset_right = 1142.0
offset_bottom = 96.0
text = "Page Resolution"

[node name="PageResolutionControls" type="HBoxContainer" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_top = 100.0
offset_right = 1142.0
offset_bottom = 131.0

[node name="PageResolutionX" type="SpinBox" parent="Window/MarginContainer/VBoxContainer/PageResolutionControls"]
unique_name_in_owner = true
layout_mode = 2
offset_right = 516.0
offset_bottom = 31.0
size_flags_horizontal = 3
Expand All @@ -207,6 +229,7 @@ suffix = "px"

[node name="PageResolutionY" type="SpinBox" parent="Window/MarginContainer/VBoxContainer/PageResolutionControls"]
unique_name_in_owner = true
layout_mode = 2
offset_left = 520.0
offset_right = 1037.0
offset_bottom = 31.0
Expand All @@ -218,32 +241,37 @@ suffix = "px"

[node name="PageResiazable" type="CheckBox" parent="Window/MarginContainer/VBoxContainer/PageResolutionControls"]
unique_name_in_owner = true
layout_mode = 2
offset_left = 1041.0
offset_right = 1142.0
offset_bottom = 31.0
button_pressed = true
text = "Resizable"

[node name="FontLabel" type="Label" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_top = 135.0
offset_right = 1142.0
offset_bottom = 161.0
text = "Font"

[node name="FontControls" type="HBoxContainer" parent="Window/MarginContainer/VBoxContainer"]
layout_mode = 2
offset_top = 165.0
offset_right = 1142.0
offset_bottom = 196.0

[node name="FontSizeLabel" type="Label" parent="Window/MarginContainer/VBoxContainer/FontControls"]
self_modulate = Color(0.678431, 0.678431, 0.678431, 1)
layout_mode = 2
offset_top = 2.0
offset_right = 70.0
offset_bottom = 28.0
text = "Font Size"

[node name="FontSize" type="SpinBox" parent="Window/MarginContainer/VBoxContainer/FontControls"]
unique_name_in_owner = true
layout_mode = 2
offset_left = 74.0
offset_right = 157.0
offset_bottom = 31.0
Expand All @@ -254,6 +282,7 @@ suffix = "px"
[node name="PanelContainer" type="PanelContainer" parent="Window/MarginContainer/VBoxContainer"]
visible = false
self_modulate = Color(1, 1, 1, 0)
layout_mode = 2
offset_top = 200.0
offset_right = 1142.0
offset_bottom = 638.0
Expand Down
Loading

0 comments on commit 5cb4f90

Please sign in to comment.