1
0
Bläddra i källkod

WIP Modding INterface

Stephan Fuchs 11 månader sedan
förälder
incheckning
82aab77d29

+ 1 - 0
.gitignore

@@ -45,3 +45,4 @@ glife.html
 
 
 __pycache__/
+mods/modable_glife.html

+ 1 - 0
mods/mod.html

@@ -0,0 +1 @@
+<tw-passagedata pid="1680" name="Start_before" tags="mod" position="1225,20975" size="100,100">Modded with Example Mod</tw-passagedata>

+ 3 - 0
mods/util/MakeMod.bat

@@ -0,0 +1,3 @@
+@ECHO off
+
+Python -X utf8 mods/util/MakeMod.py

+ 35 - 0
mods/util/MakeMod.py

@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+import os
+import fileinput
+import re
+import sys
+
+
+modTag = "mod"
+
+file_path_html = 'glife.html'
+file_path_mod = 'mods/mod.html'
+
+data = ''
+modData = ''
+
+with open(file_path_html, 'r') as file:
+    data = file.read()
+
+i = 0
+regex = r"""<tw-passagedata pid="(\d+)" name="([\s\w]+)" tags="(.*?)" (?:position="\d+,\d+" )?(?:size="\d+,\d+")?>(.*?)</tw-passagedata>"""
+for match in re.finditer(regex,data,re.S):
+    tags = match.group(3).split()
+
+    if(modTag in tags):
+        modData += match.group(0)+'\n'
+    i += 1
+    if(i % 100 == 0):
+        print(i)
+
+
+
+with open(file_path_mod, 'w') as file:
+    file.write(modData)
+
+print('Done')

+ 3 - 0
mods/util/MakeModableHtml.bat

@@ -0,0 +1,3 @@
+@ECHO off
+
+Python -X utf8 mods/util/MakeModableHtml.py

+ 21 - 0
mods/util/MakeModableHtml.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+import os
+import fileinput
+import re
+import sys
+
+file_path_html = 'glife.html'
+file_path_out = 'mods/modable_glife.html'
+
+data = ''
+with open(file_path_html, 'r') as file:
+    data = file.read()
+
+
+data = re.sub(r"""(<script id="script-sugarcube" type="text/javascript">)(.*?)(</script>)""",r"""\1$.ajax({  url: "test.html",  cache: false})  .done(function( html ) {    $( "tw-storydata" ).append( html );\2});\3""",data,1, re.S)
+
+
+with open(file_path_out, 'w') as file:
+    file.write(data)
+
+print('Done')

+ 5 - 0
sugarcube/src/PassageHeader.tw

@@ -12,6 +12,11 @@
 
 <<include 'PassageHeaderAll'>>
 
+
+<<if Story.has($here+'_before')>>
+    <<include `$here+'_before'`>>
+<</if>>
+
 :: PassageHeaderAll
 <!-- Also exists for subpassages and if CLA was called -->
 <div id="connectedLocations"></div>

+ 2 - 0
sugarcube/src/mods/example/exampleMod.tw

@@ -0,0 +1,2 @@
+:: Start_before[mod]
+Modded with Example Mod