Changeset - a5f9404a0993
[Not reviewed]
snapshots
0 1 0
Silverwing - 5 years ago 2019-07-06 18:12:02

fix snapshots breaking dark rooms
1 file changed with 113 insertions and 111 deletions:
utils.lua
113
111
0 comments (0 inline, 0 general)
utils.lua
Show inline comments
 
@@ -2,36 +2,7 @@
 
	Общие утилиты для игр на Instead. Скорее всего будут повторно использоваться в следующих играх, если таковые будут.
 
]]
 
 
--[[
 
]]
 
ArrayUtils = {
 
	indexOf = function(array, item)
 
		for i = 1, #array do
 
			if (array[i] == item) then
 
				return i;
 
			end;
 
		end;
 
		return 0;
 
	end;
 
};
 
 
--[[
 
	
 
]]
 
PartyUtils = {
 
	addToParty = function(object)
 
		if (object.home) then 
 
			if (ArrayUtils.indexOf(pl.party, object.nam) == 0) then
 
				move(object, object.home);
 
				table.insert(pl.party, object.nam);
 
			end;
 
		end;
 
	end;
 
};
 
 
--[[
 
    Translate utils
 
 ]]
 
--[[Translate utils]]
 
 
language = "ru"
 
 
@@ -42,6 +13,33 @@ translate = function(table, key)
 
end;
 
 
--[[
 
    ]]
 
ArrayUtils = {
 
    indexOf = function(array, item)
 
        for i = 1, #array do
 
            if (array[i] == item) then
 
                return i;
 
            end;
 
        end;
 
        return 0;
 
    end;
 
};
 
 
--[[
 
 
]]
 
PartyUtils = {
 
    addToParty = function(object)
 
        if (object.home) then
 
            if (ArrayUtils.indexOf(pl.party, object.nam) == 0) then
 
                move(object, object.home);
 
                table.insert(pl.party, object.nam);
 
            end;
 
        end;
 
    end;
 
};
 
 
--[[
 
    functions, design to simplify some typical actions while developing Instead game
 
]]
 
EngineUtils = {
 
@@ -68,40 +66,27 @@ EngineUtils = {
 
    end;
 
};
 
 
room = inherit(room, function(v)
 
    v.entered = stead.hook(v.entered, function(f, s, ...)
 
        if s.showhp then
 
            hp_indicator:enable();
 
        else
 
            hp_indicator:disable();
 
        end;
 
        return f(s, ...)
 
    end)
 
 
    return v;
 
end)
 
 
--[[
 
	internal space
 
]]
 
        internal space
 
    ]]
 
_kh = {
 
	vroom_enter = function(s)
 
    vroom_enter = function(s)
 
        local v = EngineUtils.getValue(s.where);
 
		if (v) then
 
			walk(v);
 
		else
 
			return false;
 
		end;
 
	end;
 
	vroom_save = function(s)
 
		if need then
 
			local t = stead.string.format("%s = kh_vroom(%s, %q, %s);\n",
 
				name, stead.tostring(s.disp),
 
					stead.deref(s.where), stead.deref(s.nam));
 
			h:write(t);
 
		end
 
		stead.savemembers(h, s, name, false);
 
	end;
 
        if (v) then
 
            walk(v);
 
        else
 
            return false;
 
        end;
 
    end;
 
    vroom_save = function(s)
 
        if need then
 
            local t = stead.string.format("%s = kh_vroom(%s, %q, %s);\n",
 
                name, stead.tostring(s.disp),
 
                stead.deref(s.where), stead.deref(s.nam));
 
            h:write(t);
 
        end
 
        stead.savemembers(h, s, name, false);
 
    end;
 
};
 
 
function toggle(obj)
 
@@ -112,7 +97,7 @@ function toggle(obj)
 
    end;
 
end;
 
 
function kh_vobj(nam, dsc, act, used) 
 
function kh_vobj(nam, dsc, act, used)
 
    return obj {
 
        nam = nam;
 
        dsc = dsc;
 
@@ -122,13 +107,13 @@ function kh_vobj(nam, dsc, act, used)
 
end;
 
 
function kh_vway(disp, dsc, target, seen_level)
 
	local temp = vway(disp, dsc, target);
 
	temp.seen_level = seen_level;
 
	return temp;
 
    local temp = vway(disp, dsc, target);
 
    temp.seen_level = seen_level;
 
    return temp;
 
end;
 
 
--[[
 
	vroom with additional functionality
 
    vroom with additional functionality
 
]]
 
function kh_vroom(disp, target, nam, seen_level)
 
    if (type(nam) == "number") then
 
@@ -138,55 +123,72 @@ function kh_vroom(disp, target, nam, see
 
    if (not nam) then
 
        nam = disp;
 
    end;
 
	return room {
 
		nam = nam;
 
		disp = disp;
 
		where = target;
 
		enter = _kh.vroom_enter;
 
		seen_level = seen_level;
 
	};
 
    return room {
 
        nam = nam;
 
        disp = disp;
 
        where = target;
 
        enter = _kh.vroom_enter;
 
        seen_level = seen_level;
 
    };
 
end;
 
 
dlg = inherit(dlg, function(v)
 
    v.hideinv = true;
 
    v.nosave = true;
 
    v.noautosave = true;
 
    return v;
 
end);
 
if not kh_utils_installed then
 
    room = inherit(room, function(v)
 
        v.entered = stead.hook(v.entered, function(f, s, ...)
 
            if s.showhp then
 
                hp_indicator:enable();
 
            else
 
                hp_indicator:disable();
 
            end;
 
            return f(s, ...)
 
        end)
 
 
obj = inherit(obj, function(v)
 
	v.disable_implicit = hook(v.disable, function(f, s, ...)
 
		s._disabled_implicit = true;
 
		return f(s, unpack({...}));
 
	end);
 
        return v;
 
    end);
 
 
    dlg = inherit(dlg, function(v)
 
        v.hideinv = true;
 
        v.nosave = true;
 
        v.noautosave = true;
 
        return v;
 
    end);
 
 
    obj = inherit(obj, function(v)
 
        v.disable_implicit = hook(v.disable, function(f, s, ...)
 
            s._disabled_implicit = true;
 
            return f(s, unpack({...}));
 
        end);
 
 
	v.disable = hook(v.disable, function(f, s, ...)
 
		s._disabled_explicit = true;
 
		return f(s, unpack({...}));
 
	end);
 
	
 
	v.enable_implicit = hook(v.enable, function(f, s, ...)
 
		s._disabled_implicit = false;
 
		if (s._disabled_explicit) then
 
			return s; --mimic original enable() behavior
 
		else
 
			return f(s, unpack({...}));
 
		end;
 
	end);
 
	
 
	v.enable = hook(v.enable, function(f, s, ...)
 
		s._disabled_explicit = false;
 
		if (s._disabled_implicit) then
 
			return s; --mimic original enable() behavior
 
		else
 
			return f(s, unpack({...}));
 
		end;
 
	end);
 
    
 
    v.toggle = toggle;
 
	
 
	return v;
 
end);
 
        v.disable = hook(v.disable, function(f, s, ...)
 
            s._disabled_explicit = true;
 
            return f(s, unpack({...}));
 
        end);
 
 
        v.enable_implicit = hook(v.enable, function(f, s, ...)
 
            s._disabled_implicit = false;
 
            if (s._disabled_explicit) then
 
                return s; --mimic original enable() behavior
 
            else
 
                return f(s, unpack({...}));
 
            end;
 
        end);
 
 
        v.enable = hook(v.enable, function(f, s, ...)
 
            s._disabled_explicit = false;
 
            if (s._disabled_implicit) then
 
                return s; --mimic original enable() behavior
 
            else
 
                return f(s, unpack({...}));
 
            end;
 
        end);
 
 
        v.toggle = toggle;
 
 
        return v;
 
    end);
 
 
    kh_utils_installed = true;
 
end;
 
 
--[[
 
	character object
0 comments (0 inline, 0 general)