tool extends "res://addons/text_editor/TE_RichTextLabel.gd" var chapter_info:Array = [] var sort_on:String = "words" var sort_on_index:int = 1 var sort_reverse:Dictionary = { id=true, chaps=true, words=true, uwords=true, "%":true, modified=true } var skip_words:PoolStringArray func _ready(): var btn = get_parent().get_node("update") btn.add_font_override("font", editor.FONT_R) var _e = btn.connect("pressed", self, "_update") func _update(): chapter_info.clear() # load block list var skip_list = editor.current_directory.plus_file("word_skip_list.txt") skip_words = TE_Util.load_text(skip_list).replace("\n", " ").strip_edges().to_lower().split(" ") for path in editor.file_paths: var file = path.get_file() var ext = file.get_extension() match ext: "md": _process_md(path) # clear empty for i in range(len(chapter_info)-1, -1, -1): var info = chapter_info[i] if not info.words: chapter_info.remove(i) _sort() _redraw() const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] const MONTHS = ["Januaray", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] const TIMES:Dictionary = { "second": 60, "minute": 60, "hour": 24, "day": INF } func get_time(t:int) -> String: for k in TIMES: if t < TIMES[k]: return "%s %s ago" % [t, k + ("" if t == 1 else "s")] t /= TIMES[k] return "???" func _process_md(path:String): var lines = TE_Util.load_text(path).split("\n") var file_time = File.new().get_modified_time(path) var curr_time = OS.get_unix_time() var diff_time = curr_time - file_time var time_nice = get_time(diff_time) if false and diff_time > 9999999: time_nice = OS.get_datetime_from_unix_time(file_time) time_nice.weekday = WEEKDAYS[time_nice.weekday-1].substr(0, 3).to_lower() time_nice.month = MONTHS[time_nice.month-1].substr(0, 3).to_lower() time_nice.hour12 = str(time_nice.hour % 12) time_nice.ampm = "am" if time_nice.hour > 12 else "pm" time_nice = "{weekday} {month} {day}, {year} {hour12}:{minute}:{second}{ampm}".format(time_nice) var out = { path=path, line=0, id=editor.get_localized_path(path), modified=file_time, time_nice=time_nice, words=0, uwords={}, chaps=0, "%":0.0 } chapter_info.append(out) var i = 0 while i < len(lines): # skip head meta if i == 0 and lines[i].begins_with("---"): i += 1 while i < len(lines) and not lines[i].begins_with("---"): if ":" in lines[i]: var p = lines[i].split(":", true, 1) var k = p[0].strip_edges() var v = p[1].strip_edges() match k: "name": out.id = v "prog", "progress": out["%"] = float(v.replace("%", "")) i += 1 # skip comments elif "