summaryrefslogtreecommitdiff
path: root/game/wiki.rpy
diff options
context:
space:
mode:
Diffstat (limited to 'game/wiki.rpy')
-rw-r--r--game/wiki.rpy72
1 files changed, 72 insertions, 0 deletions
diff --git a/game/wiki.rpy b/game/wiki.rpy
new file mode 100644
index 0000000..2f8b2be
--- /dev/null
+++ b/game/wiki.rpy
@@ -0,0 +1,72 @@
+#################################################################################
+# This file is part of Mana Launcher.
+# Copyright (C) 2023 Jesusalva <jesusalva@tmw2.org>
+#
+# Distributed under the MIT license.
+#################################################################################
+init python:
+ if mwclient is not None:
+ wiki=mwclient.Site('wiki.themanaworld.org', path='/')
+ else:
+ wiki=None
+
+ def wiki_get(game, page):
+ if wiki is None:
+ return ""
+ page = wiki.pages['%s:%s' % (game, page)]
+ if page.exists:
+ return page.text(expandtemplates=False) # expandtemplates=True cache=False
+ return ""
+
+ def wiki_links(page):
+ ls=[]
+ for ln in list(page.links()):
+ # ln.name takes the namespace in account
+ # ln.base_name is ln.name but split by "/"
+ # ln.page_title has no namespace and base_title is split by "/"
+ # Red links are excluded by the if clause
+ if ln.exists:
+ ls.append([str(ln.page_title), str(ln.name)])
+ return ls
+
+ def wiki_sub(s, nl=" "):
+ parsed=""
+ if s.startswith('https://'):
+ parsed+="{a=%s}%s{/a}" % (s, _("External Link"))
+ elif s.startswith('[[') and s.startswith(']]'):
+ # We don't have a code for this...
+ parsed+=s
+ elif s.startswith('{{') and s.startswith('}}'):
+ return ""
+ else:
+ parsed+=s
+ parsed+=nl
+ return parsed
+
+ def wiki_parse(raw):
+ raw=raw.replace('<br>', '\n').replace('<br/>', '\n')
+ fin=""
+ part=""
+ for s in raw.split('\n'):
+ part+=wiki_sub(s, "\n")
+ for s in part.split(' '):
+ fin+=wiki_sub(s, " ")
+ # TODO: Add a see-also section with the inner links
+ return fin
+
+ def load_wiki(server=99):
+ global statusmsg
+ print("Loading wiki for server %d" % server)
+ # persistent.serverlist[server]["Help"]
+ game="Classic"
+ page="Walkthrough"
+
+ #data=wiki_get(game, page)
+ print("Wiki loaded, parsing")
+ statusmsg = "Boo boo boo" #wiki_parse(data)
+ print("Done!")
+ renpy.restart_interaction()
+ print("Forcefully restarted, returning now.")
+ return None
+
+