forked from tweecode/twine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.py
100 lines (88 loc) · 4.27 KB
/
header.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os, imp
from collections import OrderedDict
from random import shuffle
class Header(object):
def __init__(self, id, path, builtinPath):
self.id = id.lower()
self.path = path
self.label = id.capitalize()
self.builtinPath = builtinPath
def filesToEmbed(self):
"""Returns an Ordered Dictionary of file names to embed into the output.
The item key is the label to look for within the output.
The item value is the name of the file who's contents will be embedded into the output.
Internal headers referring to files outside their folders should use
the following form for paths: self.builtinPath + ...
External headers must use the following form for paths: self.path + "filename.js"
"""
return OrderedDict([
('"JONAH"', self.builtinPath + os.sep + 'jonah' + os.sep + 'code.js'),
('"SUGARCANE"', self.builtinPath + os.sep + 'sugarcane' + os.sep + 'code.js'),
('"ENGINE"', self.builtinPath + os.sep + 'engine.js')
])
def storySettings(self):
"""Returns a list of StorySettings dictionaries."""
# Randomise the obfuscate key
obfuscatekey = list('anbocpdqerfsgthuivjwkxlymz')
shuffle(obfuscatekey)
obfuscatekey = ''.join(obfuscatekey)
return [{
"type": "checkbox",
"name": "undo",
"label": "Let the player undo moves",
"desc": "In Sugarcane, this enables the browser's back button.\nIn Jonah, this lets the player click links in previous passages.",
"default": "on"
},{
"type": "checkbox",
"name": "bookmark",
"label": "Let the player use passage bookmarks",
"desc": "This enables the Bookmark links in Jonah and Sugarcane.\n(If the player can't undo, bookmarks are always disabled.)",
"default": "on"
},{
"type": "checkbox",
"name": "exitprompt",
"label": "Prompt before closing or reloading the page",
"desc": "In most browsers, this asks the player to confirm closing or reloading the \npage after they've made at least 1 move.",
"default": "off"
},{
"type": "checkbox",
"name": "obfuscate",
"label": "Obfuscate the HTML source to obscure spoilers",
"values": ("swap","off")
},{
"type": "text",
"name": "obfuscatekey",
"label": "Obfuscation key:",
"default": obfuscatekey
},{
"type": "text",
"name": "identity",
"label": "What your work identifies as:",
"desc": "Is it a game, a story, a poem, or something else?\n(This is used for dialogs and error messages only.)",
"default": "game"
},{
"type": "checkbox",
"name": "jquery",
"label": "Include the jQuery script library?",
"desc": "This enables the jQuery() function and the $() shorthand.\nIndividual scripts may force this on by containing the text 'requires jQuery'.",
},{
"type": "checkbox",
"name": "modernizr",
"label": "Include the Modernizr script library?",
"desc": "This adds CSS classes to the <html> element that can be used to write\nmore compatible CSS or scripts. See http://modernizr.com/docs for details.\nIndividual scripts/stylesheets may force this on by containing the\ntext 'requires Modernizr'.",
}]
def is_endtag(self, name, tag):
"""Return true if the name is equal to an endtag."""
return (name == ('end' + tag))
def nested_macros(self):
"""Returns a list of macro names that support nesting."""
return ['if', 'silently', 'nobr']
@staticmethod
def factory(type, path, builtinPath):
header_def = path + type + '.py'
if os.access(header_def, os.R_OK):
py_mod = imp.load_source(type, header_def)
obj = py_mod.Header(type, path, builtinPath)
else:
obj = Header(type, path, builtinPath)
return obj