Modul:X: Unterschied zwischen den Versionen

Aus How to be a Hero
Zur Navigation springen Zur Suche springen
Murmelgrumpf (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Murmelgrumpf (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 86: Zeile 86:
end
end


function cut( limit, text )
 
function cut( limit, realtext )
realtext = text
srealtext = split(realtext, " ") --fiick|dich|halli(list)
srealtext = split(realtext, " ")
i = 2; --2
i = 2; --2
text = display(text) --fiick dich
limit = tonumber(limit) --11
stext = split(text, " ")--fiick|dich(list)
text = display(realtext) --fiick dich halli
stext = split(text, " ") --fiick|dich|halli(list)
if(table.getn(stext)==1) then
if(table.getn(stext)==1) then
if(string.len(stext[1])>limit) then
if(string.len(stext[1])>limit) then
Zeile 100: Zeile 103:
end
end
end
end
cuttext = stext[1]--fiick
realcuttext = srealtext[1]
cuttext = stext[1] --fiick
nextwo = stext[2]--dich
realcuttext = srealtext[1] --fiick
realnextwo = srealtext[2]--dich
nextwo = stext[2] --dich
realnextwo = srealtext[2] --dich
nextlen = string.len(nextwo)--4
nextlen = string.len(nextwo)--4
textlen = string.len(text)--10
textlen = string.len(text)--16
cuttextlen = string.len(cuttext)--5
cuttextlen = string.len(cuttext)--5
set = true;
set = true;
if(limit>=textlen)then --9>=10
return text.."%@%"
if(limit>=textlen)then --11>=16
elseif(cuttextlen>limit) then--5>9
return realtext.."%@%"
return "%@%"..text
elseif(cuttextlen>limit) then--5>11
elseif(cuttextlen+nextlen+1>=limit) then--5>9
return "%@%"..realtext
return cuttext.." "..nextwo.."%@%"
else
else
while (cuttextlen+nextlen+1<=textlen+2) do --
while (cuttextlen+nextlen+1<=textlen+2) do --5+4+1<=16+2(10<=18)|12
if(cuttextlen+nextlen>=limit and set) then --5+4>9(9>=9)
if(cuttextlen+nextlen+1>limit and set) then --5+4+1>11(10>11)|
set = false
set = false
cuttext = cuttext.."%@%"
cuttext = cuttext.."%@%" --
realcuttext = realcuttext.."%@%" --
else
else
cuttext = cuttext.." "
cuttext = cuttext.." " --"fiick "
realcuttext = realcuttext.." " --"fiick "
end
end
i = i + 1 --3
i = i + 1 --3
cuttext = cuttext..nextwo -- fick%@%dich
realcuttext = realcuttext..realnextwo
cuttext = cuttext..nextwo -- fiick dich
realcuttext = realcuttext..realnextwo -- fiick dich
nextwo = stext[i]-- halli
nextwo = stext[i]-- halli
realnextwo = stext[i]-- halli
realnextwo = srealtext[i]-- halli
nextlen = string.len(nextwo) -- 5
cuttextlen = string.len(cuttext) -- 11
if (realnextwo ~= nil) then
nextlen = string.len(nextwo) -- 5
end
cuttextlen = string.len(cuttext) -- 12
end
if (realnextwo ~= nil) then
realcuttext = realcuttext.." "..realnextwo
end
end
realcuttext = realcuttext.." "..realnextwo
return split(realcuttext, "%@%")
end
end
return realcuttext
end
end


function p.cutblock ( frame )
function p.cutblock ( frame )
Zeile 143: Zeile 166:
width = frame.args[2]
width = frame.args[2]
height = frame.args[1]
height = frame.args[1]
block = {}
block = ""
rest = ""
textlen = len(text)
tempsplit = {}
while (height>0) do
tempsplit = split(cut(width, text), "%@%")
block = block..tempsplit[1]
text = tempsplit[2]
height = height-1
end
 
return block.."%@%"..text
 
 
 
 





Version vom 19. Januar 2020, 18:43 Uhr

Die Dokumentation für dieses Modul kann unter Modul:X/Doku erstellt werden

local p = {} --local p = {} -- p steht für Paket (engl. package)

function split (inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

function p.cut( frame )
	
	realtext = frame.args[2] --fiick dich halli
	srealtext = split(realtext, " ") --fiick|dich|halli(list)
	i = 2; --2
	limit = tonumber(frame.args[1]) --11
	text = display(frame.args[2]) --fiick dich halli
	stext = split(text, " ") --fiick|dich|halli(list)
	
	if(table.getn(stext)==1) then
		if(string.len(stext[1])>limit) then
			return "%@%"..text
		else
			return text.."%@%"
		end
	end
	
	cuttext = stext[1] --fiick
	realcuttext = srealtext[1] --fiick
	
	nextwo = stext[2] --dich
	realnextwo = srealtext[2] --dich
	
	nextlen = string.len(nextwo)--4
	textlen = string.len(text)--16
	cuttextlen = string.len(cuttext)--5
	
	set = true;
	
	if(limit>=textlen)then --11>=16
		return realtext.."%@%"
	
	elseif(cuttextlen>limit) then--5>11
		return "%@%"..realtext
		
	

	else
	
		while (cuttextlen+nextlen+1<=textlen+2) do --5+4+1<=16+2(10<=18)|12
			
			if(cuttextlen+nextlen+1>limit and set) then --5+4+1>11(10>11)|
				set = false
				cuttext = cuttext.."%@%" --
				realcuttext = realcuttext.."%@%" --
				
			else
				cuttext = cuttext.." " --"fiick "
				realcuttext = realcuttext.." " --"fiick "
				
			end
			
			i = i + 1 --3
			
			cuttext = cuttext..nextwo -- fiick dich
			realcuttext = realcuttext..realnextwo -- fiick dich
			
			nextwo = stext[i]-- halli
			realnextwo = srealtext[i]-- halli
			
			if (realnextwo ~= nil) then
				nextlen = string.len(nextwo) -- 5
			end
			cuttextlen = string.len(cuttext) -- 12
			
			
		end
		if (realnextwo ~= nil) then
			realcuttext = realcuttext.." "..realnextwo
		end
	end
	return realcuttext
end


function cut( limit, realtext )
	
	
	srealtext = split(realtext, " ") --fiick|dich|halli(list)
	i = 2; --2
	limit = tonumber(limit) --11
	text = display(realtext) --fiick dich halli
	stext = split(text, " ") --fiick|dich|halli(list)
	
	if(table.getn(stext)==1) then
		if(string.len(stext[1])>limit) then
			return "%@%"..text
		else
			return text.."%@%"
		end
	end
	
	cuttext = stext[1] --fiick
	realcuttext = srealtext[1] --fiick
	
	nextwo = stext[2] --dich
	realnextwo = srealtext[2] --dich
	
	nextlen = string.len(nextwo)--4
	textlen = string.len(text)--16
	cuttextlen = string.len(cuttext)--5
	
	set = true;
	
	if(limit>=textlen)then --11>=16
		return realtext.."%@%"
	
	elseif(cuttextlen>limit) then--5>11
		return "%@%"..realtext
		
	

	else
	
		while (cuttextlen+nextlen+1<=textlen+2) do --5+4+1<=16+2(10<=18)|12
			
			if(cuttextlen+nextlen+1>limit and set) then --5+4+1>11(10>11)|
				set = false
				cuttext = cuttext.."%@%" --
				realcuttext = realcuttext.."%@%" --
				
			else
				cuttext = cuttext.." " --"fiick "
				realcuttext = realcuttext.." " --"fiick "
				
			end
			
			i = i + 1 --3
			
			cuttext = cuttext..nextwo -- fiick dich
			realcuttext = realcuttext..realnextwo -- fiick dich
			
			nextwo = stext[i]-- halli
			realnextwo = srealtext[i]-- halli
			
			if (realnextwo ~= nil) then
				nextlen = string.len(nextwo) -- 5
			end
			cuttextlen = string.len(cuttext) -- 12
			
			
		end
		if (realnextwo ~= nil) then
			realcuttext = realcuttext.." "..realnextwo
		end
	end
	return realcuttext
end


function p.cutblock ( frame )
	text = frame.args[3]
	width = frame.args[2]
	height = frame.args[1]
	block = ""
	textlen = len(text)
	tempsplit = {}
	
	
	while (height>0) do
		tempsplit = split(cut(width, text), "%@%")
		block = block..tempsplit[1]
		text = tempsplit[2]
		height = height-1
	end
	
	return block.."%@%"..text


end

function p.display ( frame )
	text = frame.args[1]
	text = text:gsub("'", "")
	text = text:gsub("<.*>", "")
	text = text:gsub("%[%[.*|", "")
	text = text:gsub("%[", "")
	text = text:gsub("%|", "")
	text = text:gsub("%]", "")

	return text
end

function display ( text )
	text = text:gsub("'", "")
	text = text:gsub("<.*>", "")
	text = text:gsub("%[%[.*|", "")
	text = text:gsub("%[", "")
	text = text:gsub("%|", "")
	text = text:gsub("%]", "")

	return text
end



return p