/usr/share/doc/instead/manual/examples/cutscene.lua is in instead-doc-base 1.9.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | -- example module
require "timer"
require "xact"
stead.cut_text = '>>>'
local function get_token(txt, pos)
if not pos then
pos = 1
end
local s,e;
e = pos
while true do
s, e = txt:find("[\\{]", e);
if not s then
break
end
if txt:sub(s, s) == '\\' then
e = e + 2
else
break
end
end
local nest = 1
local ss, ee
ee = e
while s do
ss, ee = txt:find("[\\{}]", ee + 1);
if ss then
if txt:sub(ss, ss) == '\\' then
ee = ee + 1
elseif txt:sub(ss, ss) == '{' then
nest = nest + 1
else
nest = nest - 1
end
if nest == 0 then
return s, ee
end
else
break
end
end
return nil
end
local function parse_token(txt)
local s, e, t
t = txt:sub(2, -2)
local c = t:gsub("^([a-zA-Z]+)[ \t]*.*$", "%1");
local a = t:gsub("^[^ \t]+[ \t]*(.*)$", "%1");
if a then a = a:gsub("[ \t]+$", "") end
return c, a
end
cutscene = function(v)
v.txt = v.dsc
if v.left then
error ("Do not use left in cutscene.", 2)
end
v.left = function(s)
timer:set(s._timer);
s:reset()
end;
if v.timer then
error ("Do not use timer in cutscene.", 2)
end
v.timer = function(s)
s._fading = nil
s._state = s._state + 1
timer:stop()
s:step()
return true
end;
v.forcedsc = true
if not v.pic then
v.pic = function(s)
return s._pic
end;
end
if not v.fading then
v.fading = function(s)
return s._fading
end
end
v.reset = function(s)
s._state = 1
s._code = 1
s._fading = nil
s._txt = nil
s._dsc = nil
s._pic = nil
end
v:reset()
if v.entered then
error ("Do not use entered in cutscene.", 2)
end
v.entered = function(self)
self:reset()
self._timer = timer:get()
self:step();
end;
v.step = function(self)
local s, e, c, a
local n = v._state
local txt = ''
local code = 0
local out = ''
if not self._txt then
if type(self.txt) == 'table' then
local k,v
for k,v in ipairs(self.txt) do
if type(v) == 'function' then
v = v()
end
txt = txt .. tostring(v)
end
else
txt = stead.call(self, 'txt')
end
self._txt = txt
else
txt = self._txt
end
while n > 0 and txt do
if not e then
e = 1
end
local oe = e
s, e = get_token(txt, e)
if not s then
c = nil
out = out..txt:sub(oe)
break
end
local strip = false
c, a = parse_token(txt:sub(s, e))
if c == "pause" or c == "cut" or c == "fading" then
n = n - 1
strip = true
elseif c == "pic" then
self._pic = a
strip = true
elseif c == "code" then
code = code + 1
if code >= self._code then
local f = stead.eval(a)
if not f then
error ("Wrong expression in cutscene: "..tostring(a))
end
self._code = self._code + 1
f()
end
strip = true
elseif c == "walk" then
if a and a ~= "" then
return stead.walk(a)
end
elseif c == "cls" then
out = ''
strip = true
end
if strip then
out = out..txt:sub(oe, s - 1)
elseif c then
out = out..txt:sub(oe, e)
else
out = put..txt:sub(oe)
end
e = e + 1
end
v._dsc = out
if c == 'pause' then
if not a or a == "" then
a = 1000
end
timer:set(tonumber(a))
elseif c == 'cut' then
self._state = self._state + 1
if not a or a == "" then
a = stead.cut_text
end
v._dsc = v._dsc .. "{cut|"..a.."}";
elseif c == "fading" then
if not a or a == "" then
a = game.gui.fading
end
self._fading = tonumber(a)
timer:set(10)
end
end
v.dsc = function(s)
if s._dsc then
return s._dsc
end
end
if not v.obj then
v.obj = {}
end
stead.table.insert(v.obj, 1, xact('cut', function() here():step(); return true; end ))
return room(v)
end
|