Files @ 77aa01170934
Branch filter:

Location: games/Awakening/utils.lua

Silverwing
lseryanotrr finished
--[[
	Общие утилиты для игр на 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;
};

--[[
	functions, design to simplify some typical actions while developing Instead game
]]
EngineUtils = {
	getValue = function(source, param)
		local value = "";
		if (type(source) == "function") then
			value = source(param);
		else
			value = source;
		end;
		
		return value;
	end;
};

--[[
	internal space
]]
_kh = {
	vroom_enter = function(s)  
		walk(EngineUtils.getValue(s.where));
	end;
	vroom_save = function(s)
		if need then
			local t = stead.string.format("%s = kh_vroom(%s, %q, %s);\n",
				name, stead.tostring(self.disp), 
					stead.deref(self.where), stead.deref(self.nam));
			h:write(t);
		end
		stead.savemembers(h, self, name,false);
	end;
};

--[[
	vroom with additional functionality
]]
function kh_vroom(disp, target, nam)
	if (not nam) then
		nam = disp;
	end;
	return room {
		nam = nam;
		disp = disp;
		where = target;
		enter = _kh.vroom_enter;
		--enter = _kh.vroom_enter;
		--save = _kh.vroom_save;
	};
end;