censored/engine.lua

158 lines
3.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function room_scene(self) return true; end
function par(space,...)
local i, res
local a = {...};
for i = 1, stead.table.maxn(a) do
if type(a[i]) == 'string' then
if res == nil then res = "" end
res = res..a[i];
end
end
return res;
end
stead.par = par
word = function(word)
return obj{
nam = '',
_word = word,
_enabled = true,
dsc = function(this)
value = ""
if (this._enabled == true) then
value = this._word
else
value = string.rep("",string.len(this._word)/2)
end
return "{".. value .."}"
end,
act = function(this)
this._enabled = not this._enabled
return true
end
}
end
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
function string.split(str, pat)
local t = {}
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
sentence = function(text)
text = string.gsub(text, '%!', ' exclamation space ')
text = string.gsub(text, '%,', ' comma ')
text = string.gsub(text, '%:', ' colon ')
text = string.gsub(text, '%.', ' dot space')
text = string.gsub(text, '%(', ' space opening_bracket ')
text = string.gsub(text, '%)', ' closing_bracket space ')
text = string.gsub(text, '%?', ' question space ')
text = string.gsub(text, '%-%-', ' space dash ')
text = string.gsub(text, '%^%^', ' newline ')
array = string.split(text, " ")
objects = {}
local j = 1
for i,v in ipairs(array) do
if (table.contains({'colon', 'dot', 'newline', 'opening_bracket', 'closing_bracket', 'space', 'dash', 'exclamation', 'question', 'comma'},v) == false and string.match (v, "%S")) then
if(i > 1) then
table.insert(objects, j, 'space')
j = j + 1
end
table.insert(objects, j, word(v))
j = j + 1
else
if (string.match (v, "%S")) then
table.insert(objects, j, v)
j = j + 1
end
end
end
local value = obj{
nam = '',
dsc = '',
obj = objects
}
return value
end
newline = vobj("^^", "^^")
space = vobj(" ", " ")
opening_bracket = vobj(" ", "(")
closing_bracket = vobj(" ", ")")
dash = vobj("--", "--")
comma = vobj(",", ",")
dot = vobj(".", ".")
exclamation = vobj("!", "!")
question = vobj("?", "?")
colon = vobj(":", ":")
signed = vobj(" ", txtr("Проверено: цензор ███████████^^"))
function headline(text)
return obj{
nam="",
_selected = false,
dsc = function(this)
if (this._selected) then
return "• {" .. txtb(text) .. "}" .. "\t\t\t" .. [[^]]
end
return "• {" .. text .. "}" .. "\t\t\t" .. [[^]]
end,
act = function(this)
this._selected = not this._selected
return true
end,
}
end
function news(v)
if v.news == nil then v.news = {} end
if v.dsc == nil then v.dsc = "" end
if v.way == nil then v.way = {} end
if v.obj == nil then v.obj = {} end
if v.look == nil then v.look = room_look end
if v.save == nil then v.save = room_save end
if v.scene == nil then v.scene = room_scene end
v.way = list(v.way);
v.location_type = true
for i,text in ipairs(v.news) do
table.insert(v.obj, i, headline(text))
end
table.insert(v.obj, table.maxn(v.obj)+1, 'sign_newspaper_1')
v = obj(v);
return v;
end
function is_activated(previous, current, room)
for i,v in ipairs(room.obj) do
if v ~= nil then
for j,word in ipairs(v.obj) do
if (word ~= nil) then
if (word._word == previous) then
if (v.obj[j+2]._word == current) then --следующее слово _после пробела_
return v.obj[j+2]._enabled;
end
end
end
end
end
end
end