Add files via upload
This commit is contained in:
parent
681178e5dc
commit
ac737d447a
15
client/GuiManager/Core/Clickable.int
Normal file
15
client/GuiManager/Core/Clickable.int
Normal file
@ -0,0 +1,15 @@
|
||||
function gui:Clickable()
|
||||
local x,y,w,h=love.graphics.getScissor()
|
||||
local mx=love.mouse.getX()
|
||||
local my=love.mouse.getY()
|
||||
if _GuiPro.HasStencel then
|
||||
local obj=_GuiPro.StencelHolder
|
||||
if self:isDescendant(obj) then
|
||||
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||
end
|
||||
end
|
||||
if not(x) then
|
||||
return true
|
||||
end
|
||||
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||
end
|
||||
1667
client/GuiManager/Core/Colors.int
Normal file
1667
client/GuiManager/Core/Colors.int
Normal file
File diff suppressed because it is too large
Load Diff
5
client/GuiManager/Core/DrawThings.int
Normal file
5
client/GuiManager/Core/DrawThings.int
Normal file
@ -0,0 +1,5 @@
|
||||
function DrawThings(items)
|
||||
for i=1,#items do
|
||||
items[i]:draw()
|
||||
end
|
||||
end
|
||||
85
client/GuiManager/Core/EventDefinitions.int
Normal file
85
client/GuiManager/Core/EventDefinitions.int
Normal file
@ -0,0 +1,85 @@
|
||||
function gui:OnClicked(func)
|
||||
table.insert(self.funcs,func)
|
||||
end
|
||||
function gui:OnReleased(func)
|
||||
table.insert(self.funcs2,func)
|
||||
end
|
||||
function gui:OnEnter(func)
|
||||
table.insert(self.funcs3,func)
|
||||
end
|
||||
function gui:OnExit(func)
|
||||
table.insert(self.funcs4,func)
|
||||
end
|
||||
function gui:OnUpdate(func)
|
||||
table.insert(self.funcs5,func)
|
||||
end
|
||||
function gui:OnDragStart(func)
|
||||
table.insert(self.func8,func)
|
||||
end
|
||||
function gui:OnDragging(func)
|
||||
table.insert(self.func6,func)
|
||||
end
|
||||
function gui:OnDragEnd(func)
|
||||
table.insert(self.func7,func)
|
||||
end
|
||||
function gui:WhileHovering(func)
|
||||
table.insert(self.func9,func)
|
||||
end
|
||||
function gui:OnMouseMoved(func)
|
||||
table.insert(self.func10,func)
|
||||
end
|
||||
function gui:getChildren()
|
||||
return self.Children
|
||||
end
|
||||
function gui:LClicked()
|
||||
return self.lclicked
|
||||
end
|
||||
function gui:RClicked()
|
||||
return self.rclicked
|
||||
end
|
||||
function gui:MClicked()
|
||||
return self.mclicked
|
||||
end
|
||||
function gui:Clicked()
|
||||
return (self.lclicked or self.rclicked)
|
||||
end
|
||||
function gui:Hovering()
|
||||
return self.hovering
|
||||
end
|
||||
function gui:FreeConnections()
|
||||
self.funcs={function(b,self) if b=="l" then self.LRE=true end end,function(b,self) if b=="r" then self.RRE=true end end,function(b,self) if b=="m" then self.MRE=true end end}
|
||||
self.funcs2={function(b,self) if b=="l" then self.LRE=false end end,function(b,self) if b=="r" then self.RRE=false end end,function(b,self) if b=="m" then self.MRE=false end end}
|
||||
self.funcs3={function(self) self.HE=true end}
|
||||
self.funcs4={function(self) self.HE=false end}
|
||||
self.funcs5={function(self) self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y end}
|
||||
end
|
||||
function gui:LClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("l",self)
|
||||
end
|
||||
end
|
||||
function gui:RClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("r",self)
|
||||
end
|
||||
end
|
||||
function gui:MClick()
|
||||
for i=1,#self.funcs do
|
||||
self.funcs[i]("m",self)
|
||||
end
|
||||
end
|
||||
function gui:LRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("l",self)
|
||||
end
|
||||
end
|
||||
function gui:RRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("r",self)
|
||||
end
|
||||
end
|
||||
function gui:MRelease()
|
||||
for i=1,#self.funcs2 do
|
||||
self.funcs2[i]("m",self)
|
||||
end
|
||||
end
|
||||
46
client/GuiManager/Core/UpdateThings.int
Normal file
46
client/GuiManager/Core/UpdateThings.int
Normal file
@ -0,0 +1,46 @@
|
||||
function UpdateThings(items)
|
||||
for i=#items,1,-1 do
|
||||
if items[i]:LClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:RClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:MClicked() then
|
||||
for g=1,#items[i].funcs do
|
||||
items[i].funcs[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
if not(items[i]:LClicked()) and items[i].LRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:RClicked()) and items[i].RRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:MClicked()) and items[i].MRE then
|
||||
for g=1,#items[i].funcs2 do
|
||||
items[i].funcs2[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
if items[i]:Hovering() and items[i].HE==false then
|
||||
for g=1,#items[i].funcs3 do
|
||||
items[i].funcs3[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif not(items[i]:Hovering()) and items[i].HE==true then
|
||||
for g=1,#items[i].funcs4 do
|
||||
items[i].funcs4[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
elseif items[i]:Hovering() then
|
||||
for g=1,#items[i].func9 do
|
||||
items[i].func9[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||
end
|
||||
end
|
||||
for g=1,#items[i].funcs5 do
|
||||
items[i].funcs5[g](items[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
25
client/GuiManager/Core/_GetAllChildren.int
Normal file
25
client/GuiManager/Core/_GetAllChildren.int
Normal file
@ -0,0 +1,25 @@
|
||||
function GetAllChildren(Object)
|
||||
local Stuff = {}
|
||||
function Seek(Items)
|
||||
for i=1,#Items do
|
||||
if Items[i].Visible==true then
|
||||
table.insert(Stuff,Items[i])
|
||||
local NItems = Items[i]:getChildren()
|
||||
if NItems ~= nil then
|
||||
Seek(NItems)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local Objs = Object:getChildren()
|
||||
for i=1,#Objs do
|
||||
if Objs[i].Visible==true then
|
||||
table.insert(Stuff,Objs[i])
|
||||
local Items = Objs[i]:getChildren()
|
||||
if Items ~= nil then
|
||||
Seek(Items)
|
||||
end
|
||||
end
|
||||
end
|
||||
return Stuff
|
||||
end
|
||||
21
client/GuiManager/Core/_GetAllChildren2.int
Normal file
21
client/GuiManager/Core/_GetAllChildren2.int
Normal file
@ -0,0 +1,21 @@
|
||||
function GetAllChildren2(Object)
|
||||
local Stuff = {}
|
||||
function Seek(Items)
|
||||
for i=1,#Items do
|
||||
table.insert(Stuff,Items[i])
|
||||
local NItems = Items[i]:getChildren()
|
||||
if NItems ~= nil then
|
||||
Seek(NItems)
|
||||
end
|
||||
end
|
||||
end
|
||||
local Objs = Object:getChildren()
|
||||
for i=1,#Objs do
|
||||
table.insert(Stuff,Objs[i])
|
||||
local Items = Objs[i]:getChildren()
|
||||
if Items ~= nil then
|
||||
Seek(Items)
|
||||
end
|
||||
end
|
||||
return Stuff
|
||||
end
|
||||
14
client/GuiManager/Core/eventable.int
Normal file
14
client/GuiManager/Core/eventable.int
Normal file
@ -0,0 +1,14 @@
|
||||
function gui:eventable()
|
||||
if self.important then
|
||||
return true
|
||||
end
|
||||
if _GuiPro.Hierarchy then
|
||||
if _GuiPro.TopHovered~=nil then
|
||||
return self:isDescendant(_GuiPro.TopHovered) or _GuiPro.TopHovered==self
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
3
client/GuiManager/Core/full.int
Normal file
3
client/GuiManager/Core/full.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:full()
|
||||
self:SetDualDim(nil,nil,nil,nil,nil,nil,1,1)
|
||||
end
|
||||
237
client/GuiManager/Core/newBase.int
Normal file
237
client/GuiManager/Core/newBase.int
Normal file
@ -0,0 +1,237 @@
|
||||
function gui.enableAutoWindowScaling(b)
|
||||
_GuiPro.DPI_ENABLED=b or true
|
||||
_defaultfont=love.graphics.newFont(12*love.window.getPixelScale())
|
||||
end
|
||||
function filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(name)~="string" then
|
||||
sh=sw
|
||||
sw=sy
|
||||
sy=sx
|
||||
sx=h
|
||||
h=w
|
||||
w=y
|
||||
y=x
|
||||
x=name
|
||||
end
|
||||
return x,y,w,h,sx,sy,sw,sh
|
||||
end
|
||||
function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
_GuiPro.count=_GuiPro.count+1
|
||||
local c = {}
|
||||
setmetatable(c, gui)
|
||||
if self==gui then
|
||||
c.Parent=_GuiPro
|
||||
else
|
||||
c.Parent=self
|
||||
end
|
||||
c.segments=nil
|
||||
c.ry=nil
|
||||
c.rx=nil
|
||||
c.DPI=1
|
||||
if _GuiPro.DPI_ENABLED then
|
||||
c.DPI=love.window.getPixelScale()
|
||||
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
|
||||
end
|
||||
c.centerFontY=true
|
||||
c.FormFactor="rectangle"
|
||||
c.Type=tp
|
||||
c.Active=true
|
||||
c.form="rectangle"
|
||||
c.Draggable=false
|
||||
c.Name=name or "Gui"..tp
|
||||
c:SetName(name)
|
||||
c.BorderSize=1
|
||||
c.BorderColor={0,0,0}
|
||||
c.VIS=true
|
||||
c.Visible=true
|
||||
c.oV=true
|
||||
c.Children={}
|
||||
c.hovering=false
|
||||
c.rclicked=false
|
||||
c.lclicked=false
|
||||
c.mclicked=false
|
||||
c.clicked=false
|
||||
c.Visibility=1
|
||||
c.ClipDescendants=false
|
||||
c.TextWrap=true
|
||||
c.scale={}
|
||||
c.scale.size={}
|
||||
c.scale.size.x=sw or 0
|
||||
c.scale.size.y=sh or 0
|
||||
c.offset={}
|
||||
c.offset.size={}
|
||||
c.offset.size.x=w or 0
|
||||
c.offset.size.y=h or 0
|
||||
c.scale.pos={}
|
||||
c.scale.pos.x=sx or 0
|
||||
c.scale.pos.y=sy or 0
|
||||
c.offset.pos={}
|
||||
c.offset.pos.x=x or 0
|
||||
c.offset.pos.y=y or 0
|
||||
c.width = 0
|
||||
c.height = 0
|
||||
c.LRE=false
|
||||
c.RRE=false
|
||||
c.MRE=false
|
||||
c.Color = {255, 255, 255}
|
||||
function c:setRoundness(rx,ry,segments)
|
||||
self.segments=segments
|
||||
self.ry=ry
|
||||
self.rx=rx
|
||||
end
|
||||
function c.stfunc()
|
||||
love.graphics.rectangle("fill", c.x, c.y, c.width, c.height,c.rx,c.ry,c.segments)
|
||||
end
|
||||
function c:hasRoundness()
|
||||
return (self.ry or self.rx)
|
||||
end
|
||||
c.funcs={function(b,self)
|
||||
if b=="l" then
|
||||
self.LRE=true
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="r" then
|
||||
self.RRE=true
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="m" then
|
||||
self.MRE=true
|
||||
end
|
||||
end}
|
||||
c.funcs2={function(b,self)
|
||||
if b=="l" then
|
||||
self.LRE=false
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="r" then
|
||||
self.RRE=false
|
||||
end
|
||||
end,
|
||||
function(b,self)
|
||||
if b=="m" then
|
||||
self.MRE=false
|
||||
end
|
||||
end}
|
||||
c.HE=false
|
||||
c.funcs3={function(self)
|
||||
self.HE=true
|
||||
end}
|
||||
c.funcs4={function(self)
|
||||
self.HE=false
|
||||
end}
|
||||
c.funcs5={}
|
||||
c.tid={}
|
||||
c.touchcount=0
|
||||
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
|
||||
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
|
||||
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
|
||||
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
|
||||
c.func6={}
|
||||
c.func7={function() _GuiPro.DragItem={} end}
|
||||
c.func8={function(self) _GuiPro.DragItem=self end}
|
||||
c.func9={}
|
||||
c.func10={}
|
||||
function c:ImageRule()
|
||||
if self.Image then
|
||||
local sx=self.width/self.ImageWidth
|
||||
local sy=self.height/self.ImageHeigth
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||
if self.width~=self.ImageWidth and self.height~=self.ImageHeigth then
|
||||
love.graphics.draw(self.Image,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||
else
|
||||
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:VideoRule()
|
||||
if self.Video then
|
||||
local sx=self.width/self.VideoWidth
|
||||
local sy=self.height/self.VideoHeigth
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.VideoVisibility*255)
|
||||
if self.width~=self.VideoWidth and self.height~=self.VideoHeigth then
|
||||
love.graphics.draw(self.Video,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||
else
|
||||
love.graphics.draw(self.Video,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:repeatImage(b,b2)
|
||||
if b then
|
||||
self.Image:setWrap("repeat","repeat")
|
||||
function self:ImageRule()
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation))
|
||||
end
|
||||
else
|
||||
sx=self.width/self.ImageWidth
|
||||
sy=self.height/self.ImageHeigth
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||
end
|
||||
end
|
||||
function c:Mutate(t)
|
||||
for i,v in pairs(t) do
|
||||
_GuiPro.self=self
|
||||
if type(i)=="number" then
|
||||
loadstring("_GuiPro.self:"..v)()
|
||||
else
|
||||
self[i]=v
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
c:WhileHovering(function(self)
|
||||
self.omx=self.nmx
|
||||
self.omy=self.nmy
|
||||
self.nmx=love.mouse.getX()
|
||||
self.nmy=love.mouse.getY()
|
||||
if self.omx~=self.nmx or self.omy~=self.nmy then
|
||||
for i=1,#self.func10 do
|
||||
if self and self.nmx and self.nmy and self.omx and self.omy then
|
||||
self.func10[i](self,self.nmx,self.nmy,self.omx,self.omy)
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.WasBeingDragged==true and love.mouse.isDown(self.dragbut or "m")==false and self.Type~="TextImageButtonFrameDrag" then
|
||||
for i=1,#self.func7 do
|
||||
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
end
|
||||
if _GuiPro.hasDrag==false and love.mouse.isDown(self.dragbut or "m") then
|
||||
for i=1,#self.func8 do
|
||||
self.func8[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
end
|
||||
if self.IsBeingDragged==true then
|
||||
_GuiPro.hasDrag=true
|
||||
self.WasBeingDragged=true
|
||||
elseif self.WasBeingDragged==true and self.IsBeingDragged==false then
|
||||
self.WasBeingDragged=false
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
if self.Draggable==true and love.mouse.isDown(self.dragbut or "m") and _GuiPro.hasDrag==false then
|
||||
for i=1,#self.func6 do
|
||||
self.func6[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
_GuiPro.hasDrag=true
|
||||
if self.FormFactor:lower()=="circle" or self.FormFactor:lower()=="c" or self.FormFactor:lower()=="cir" then
|
||||
self.IsBeingDragged=true
|
||||
x=(love.mouse.getX()-self.x)
|
||||
y=(love.mouse.getY()-self.y)
|
||||
self:Move(x,y)
|
||||
elseif self.FormFactor:lower()=="rectangle" or self.FormFactor:lower()=="r" or self.FormFactor:lower()=="rect" then
|
||||
self.IsBeingDragged=true
|
||||
x=(love.mouse.getX()-self.x)-self.width/2
|
||||
y=(love.mouse.getY()-self.y)-self.height/2
|
||||
self:Move(x,y)
|
||||
end
|
||||
else
|
||||
self.IsBeingDragged=false
|
||||
end
|
||||
end)
|
||||
table.insert(c.Parent.Children,c)
|
||||
return c
|
||||
end
|
||||
7
client/GuiManager/Core/patches.int
Normal file
7
client/GuiManager/Core/patches.int
Normal file
@ -0,0 +1,7 @@
|
||||
_GuiPro.mousedownfunc=love.mouse.isDown
|
||||
function love.mouse.isDown(b)
|
||||
if not(b) then
|
||||
return false
|
||||
end
|
||||
return _GuiPro.mousedownfunc(({["l"]=1,["r"]=2,["m"]=3})[b] or b)
|
||||
end
|
||||
204
client/GuiManager/Core/touchManager.int
Normal file
204
client/GuiManager/Core/touchManager.int
Normal file
@ -0,0 +1,204 @@
|
||||
--[[WORKING ON
|
||||
doubleTap - UnFinished!
|
||||
touchRendering - Broken
|
||||
]]
|
||||
function gui:TClickable(mx,my)
|
||||
local x,y,w,h=love.graphics.getScissor()
|
||||
if _GuiPro.HasStencel then
|
||||
local obj=_GuiPro.StencelHolder
|
||||
if self:isDescendant(obj) then
|
||||
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||
end
|
||||
end
|
||||
if not(x) then
|
||||
return true
|
||||
end
|
||||
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||
end
|
||||
function gui:touchable(t)
|
||||
local touches = love.touch.getTouches()
|
||||
local x,y=0,0
|
||||
for i, id in ipairs(touches) do
|
||||
if self.id==id then
|
||||
x, y = love.touch.getPosition(id)
|
||||
return (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height and self:TClickable(x,y) and self:eventable())
|
||||
end
|
||||
end
|
||||
self.id=-1
|
||||
end
|
||||
multi:newTask(function() -- A bit of post-loading haha
|
||||
gui.touchpressed=multi:newConnection()
|
||||
gui.touchreleased=multi:newConnection()
|
||||
gui.touchmoved=multi:newConnection()
|
||||
love.touchpressed=Library.convert(love.touchpressed or function() end)
|
||||
love.touchreleased=Library.convert(love.touchreleased or function() end)
|
||||
love.touchmoved=Library.convert(love.touchmoved or function() end)
|
||||
love.touchpressed:inject(function(id, x, y, dx, dy, pressure) gui.touchpressed:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||
love.touchreleased:inject(function(id, x, y, dx, dy, pressure) gui.touchreleased:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||
love.touchmoved:inject(function(id, x, y, dx, dy, pressure) gui.touchmoved:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||
_GuiPro.TouchReady=true
|
||||
_GuiPro.TouchRegister={}
|
||||
gui.touchpressed:connect(function(id, x, y, dx, dy, pressure)
|
||||
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||
if #v.tid==0 then
|
||||
if (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||
v:addTID(id)
|
||||
v.touchcount=1
|
||||
for i=1,#v.ToFuncP do
|
||||
v.ToFuncP[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||
end
|
||||
end
|
||||
elseif not(v:hasTID(id)) then
|
||||
if (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||
v:addTID(id)
|
||||
v.touchcount=v.touchcount+1
|
||||
for i=1,#v.ToFuncP do
|
||||
v.ToFuncP[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
gui.touchreleased:connect(function(id, x, y, dx, dy, pressure)
|
||||
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||
if v:hasTID(id) then
|
||||
v:removeTID(id)
|
||||
for i=1,#v.ToFuncR do
|
||||
v.ToFuncR[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
gui.touchmoved:connect(function(id, x, y, dx, dy, pressure)
|
||||
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||
if v:hasTID(id) and (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||
for i=1,#v.ToFuncM do
|
||||
v.ToFuncM[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||
end
|
||||
elseif v:hasTID(id) and not((x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable())) then
|
||||
v:removeTID(id)
|
||||
for i=1,#v.ToFuncR do
|
||||
v.ToFuncR[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
-- now that that is done lets set up some more post loading checks
|
||||
_GuiPro.int=multi:newProcess()
|
||||
_GuiPro.int:Start()
|
||||
_GuiPro.int:setJobSpeed(.001)
|
||||
_GuiPro.EXACT=0
|
||||
_GuiPro.LAX=.01
|
||||
_GuiPro.LAZY=.05
|
||||
-- now lets define the reg function
|
||||
function gui.Compare(a,b,v,tp)
|
||||
if tp==">" then
|
||||
if (a+v>b or a-v>b) then
|
||||
return true
|
||||
end
|
||||
elseif tp=="<" then
|
||||
if (a+v<b or a-v<b) then
|
||||
return true
|
||||
end
|
||||
elseif tp=="<=" then
|
||||
if (a+v<=b or a-v<=b) then
|
||||
return true
|
||||
end
|
||||
elseif tp==">=" then
|
||||
if (a+v>=b or a-v>=b) then
|
||||
return true
|
||||
end
|
||||
elseif tp=="==" then -- this one is gonna be tricky
|
||||
if (a>=b-v and a<=b+v) or (b>=a-v and b<=a+v) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
function gui:regesterTouch()
|
||||
local obj=self
|
||||
obj.ToFuncP={}
|
||||
obj.ToFuncM={}
|
||||
obj.ToFuncR={}
|
||||
obj.To2Func={}
|
||||
obj.ToDTFunc={}
|
||||
obj.touchRendering =_GuiPro.EXACT -- exact(0), lax(), #
|
||||
function obj:removeTID(id)
|
||||
for i=1,#self.tid do
|
||||
if self.tid[i]==id then
|
||||
table.remove(self.tid,i)
|
||||
self.touchcount=self.touchcount-1
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
function obj:hasTID(id)
|
||||
for i=1,#self.tid do
|
||||
if self.tid[i]==id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
obj.txl1=0
|
||||
obj.tyl1=0
|
||||
obj.txl2=0
|
||||
obj.tyl2=0
|
||||
obj.LS=0
|
||||
obj:OnUpdate(function(self)
|
||||
if self.touchcount==2 then
|
||||
local x1,y1=love.touch.getPosition( self.tid[1] )
|
||||
local x2,y2=love.touch.getPosition( self.tid[2] )
|
||||
local CS=math.sqrt((x2-x1)^2+(y2-y1)^2)
|
||||
if gui.Compare(CS,self.LS,self.touchRendering,">") then
|
||||
for i=1,#self.To2Func do
|
||||
self.To2Func[i](self,CS,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||
end
|
||||
elseif gui.Compare(CS,self.LS,self.touchRendering,"<") then
|
||||
for i=1,#self.To2Func do
|
||||
self.To2Func[i](self,-CS,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||
end
|
||||
elseif gui.Compare(CS,self.LS,self.touchRendering,"==") then
|
||||
for i=1,#self.To2Func do
|
||||
self.To2Func[i](self,0,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||
end
|
||||
end
|
||||
-- if self.txl1~=x1 or self.txl2~=x2 or self.tyl1~=y1 or self.tyl2~=y2 then
|
||||
-- for i=1,#self.To2Func do
|
||||
-- self.To2Func[i](self,0,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||
-- end
|
||||
-- end
|
||||
self.LS=CS
|
||||
self.txl1=x1
|
||||
self.txl2=x2
|
||||
self.tyl1=y1
|
||||
self.tyl2=y2
|
||||
end
|
||||
end)
|
||||
function obj:OnDoubleTap(func)
|
||||
table.insert(self.ToDTFunc,func)
|
||||
end
|
||||
function obj:On2TouchMoved(func)
|
||||
table.insert(self.To2Func,func)
|
||||
end
|
||||
function obj:addTID(id)
|
||||
table.insert(self.tid,id)
|
||||
end
|
||||
function obj:OnTouchPressed(func)
|
||||
table.insert(self.ToFuncP,func) -- event for touches
|
||||
end
|
||||
function obj:OnTouchReleased(func) -- event for touches
|
||||
table.insert(self.ToFuncR,func)
|
||||
end
|
||||
function obj:OnTouchMoved(func) -- event for touches
|
||||
table.insert(self.ToFuncM,func)
|
||||
end
|
||||
if _GuiPro.TouchReady then -- my sneaky test
|
||||
print("Registred: "..tostring(obj))
|
||||
table.insert(_GuiPro.TouchRegister,obj)
|
||||
else
|
||||
print("Attempting to register: "..tostring(obj))
|
||||
_GuiPro.int:newJob(function() table.insert(_GuiPro.TouchRegister,obj) end) -- a sneaky way to ensure that your object gets registered eventually, even if you call the method before the touch patch was activated.
|
||||
end
|
||||
end
|
||||
4
client/GuiManager/Drawing/AddDrawRuleB.int
Normal file
4
client/GuiManager/Drawing/AddDrawRuleB.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:AddDrawRuleB(rule)
|
||||
if not(self.DrawRulesB) then self.DrawRulesB={} end
|
||||
table.insert(self.DrawRulesB,fule)
|
||||
end
|
||||
4
client/GuiManager/Drawing/AddDrawRuleE.int
Normal file
4
client/GuiManager/Drawing/AddDrawRuleE.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:AddDrawRuleE(rule)
|
||||
if not(self.DrawRulesE) then self.DrawRulesE={} end
|
||||
table.insert(self.DrawRulesE,fule)
|
||||
end
|
||||
12
client/GuiManager/Drawing/draw.int
Normal file
12
client/GuiManager/Drawing/draw.int
Normal file
@ -0,0 +1,12 @@
|
||||
function gui:draw()
|
||||
if _GuiPro.rotate~=0 then
|
||||
love.graphics.rotate(math.rad(_GuiPro.rotate))
|
||||
end
|
||||
if self.FormFactor:lower()=="rectangle" then
|
||||
self:drawR()
|
||||
elseif self.FormFactor:lower()=="circle" then
|
||||
self:drawC()
|
||||
else
|
||||
error("Unsupported FormFactor: "..self.FormFactor.."!")
|
||||
end
|
||||
end
|
||||
89
client/GuiManager/Drawing/drawC.int
Normal file
89
client/GuiManager/Drawing/drawC.int
Normal file
@ -0,0 +1,89 @@
|
||||
function gui:drawC()
|
||||
if love.mouse.isDown("l")==false and love.mouse.isDown("m")==false and love.mouse.isDown("r")==false then
|
||||
_GuiPro.DragItem={}
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
if self.Visible==true and self.VIS==true then
|
||||
local b=true
|
||||
for i,v in pairs(_GuiPro.Clips) do
|
||||
if self:isDescendant(v)==true then
|
||||
b=false
|
||||
end
|
||||
end
|
||||
if b then
|
||||
love.graphics.setStencilTest( )
|
||||
_GuiPro.HasStencel=false
|
||||
_GuiPro.StencelHolder=nil
|
||||
end
|
||||
local x,y,r,s=(self.offset.pos.x or 0)+self.Parent.x,(self.offset.pos.y or 0)+self.Parent.y,self.offset.size.x or 0,self.offset.size.y or 360
|
||||
if self.CC then
|
||||
x,y=x+r,y+r
|
||||
end
|
||||
self.x,self.y=x,y
|
||||
_GuiPro.circleStencilFunction = function()
|
||||
love.graphics.circle("fill",x,y,r,s)
|
||||
end
|
||||
if math.sqrt((love.mouse.getX()-x)^2+(love.mouse.getY()-y)^2)<=r and self:eventable() and self:Clickable() and self.Active==true then
|
||||
self.hovering=true
|
||||
if love.mouse.isDown("l") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.lclicked=true
|
||||
elseif love.mouse.isDown("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.rclicked=true
|
||||
elseif love.mouse.isDown("m") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.mclicked=true
|
||||
else
|
||||
if string.find(self.Type, "Button") and _GuiPro.hasDrag==false then
|
||||
love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
self.hovering=false
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
if self.ClipDescendants==true then
|
||||
_GuiPro.Clips[tostring(self)]=self
|
||||
_GuiPro.HasStencel=true
|
||||
_GuiPro.StencelHolder=self
|
||||
love.graphics.stencil(_GuiPro.circleStencilFunction)
|
||||
love.graphics.setStencilTest("notequal",0)
|
||||
end
|
||||
love.graphics.circle("fill",x,y,r,s)
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility*254)
|
||||
for b=0,self.BorderSize-1 do
|
||||
love.graphics.circle("line",x,y,r+b,s)
|
||||
end
|
||||
if string.find(self.Type, "Text") then
|
||||
if self.text~=nil then
|
||||
if self.AutoScaleText then
|
||||
self.FontSize=math.floor(self.height/1.45833)
|
||||
end
|
||||
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility*254)
|
||||
love.graphics.setFont(self.Font)
|
||||
love.graphics.printf(self.text, x-(r/2)+(self.XTween), y-(r/2)+self.Tween, r, self.TextFormat)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
118
client/GuiManager/Drawing/drawR.int
Normal file
118
client/GuiManager/Drawing/drawR.int
Normal file
@ -0,0 +1,118 @@
|
||||
function gui:drawR()
|
||||
if love.mouse.isDown("l")==false and love.mouse.isDown("m")==false and love.mouse.isDown("r")==false then
|
||||
_GuiPro.DragItem={}
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
if self.Visible==true and self.VIS==true then
|
||||
local b=true
|
||||
for i,v in pairs(_GuiPro.Clips) do
|
||||
if self:isDescendant(v)==true then
|
||||
b=false
|
||||
end
|
||||
end
|
||||
if b==true then
|
||||
love.graphics.setStencilTest()
|
||||
love.graphics.setScissor()
|
||||
end
|
||||
self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x
|
||||
self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y
|
||||
self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x
|
||||
self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y
|
||||
if self.DrawRulesB then
|
||||
for dr=1,#self.DrawRulesB do
|
||||
self.DrawRulesB[dr](self)
|
||||
end
|
||||
end
|
||||
if (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height and self:Clickable() and self:eventable()) or self:touchable("r") and self.Active==true then
|
||||
self.hovering=true
|
||||
if love.mouse.isDown("l") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.lclicked=true
|
||||
elseif love.mouse.isDown("r") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.rclicked=true
|
||||
elseif love.mouse.isDown("m") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
if string.find(self.Type, "Button") then
|
||||
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.mclicked=true
|
||||
else
|
||||
if string.find(self.Type, "Button") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||
love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility*254)
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
end
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
else
|
||||
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||
self.hovering=false
|
||||
self.rclicked=false
|
||||
self.lclicked=false
|
||||
self.mclicked=false
|
||||
end
|
||||
if self.ClipDescendants==true then
|
||||
_GuiPro.Clips[tostring(self)]=self
|
||||
love.graphics.setScissor(self.x, self.y, self.width, self.height)
|
||||
end
|
||||
if self:hasRoundness() then
|
||||
love.graphics.stencil(self.stfunc, "replace", 1)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
end
|
||||
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||
if string.find(self.Type, "Image") then
|
||||
self:ImageRule()
|
||||
end
|
||||
if self.Type=="Video" then
|
||||
self:VideoRule()
|
||||
end
|
||||
if self:hasRoundness() then
|
||||
love.graphics.setStencilTest()
|
||||
end
|
||||
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility*254)
|
||||
for b=0,self.BorderSize-1 do
|
||||
love.graphics.rectangle("line", self.x-(b/2), self.y-(b/2), self.width+b, self.height+b,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||
end
|
||||
if string.find(self.Type, "Text") then
|
||||
if self.text~=nil then
|
||||
if self.AutoScaleText then
|
||||
self.FontSize=math.floor(self.height/1.45833)
|
||||
end
|
||||
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility*254)
|
||||
if self.Font==_defaultfont then
|
||||
love.graphics.setFont(self.Font)
|
||||
love.graphics.printf(self.text, self.x+2+(self.XTween*self.DPI)+((self.marginL or 0)*self.DPI or self.XTween*self.DPI), self.y+(self.FontHeight/2)+self.Tween*self.DPI, self.width+(0 or (self.marginR or 0)*self.DPI), self.TextFormat)
|
||||
else
|
||||
if type(self.Font)=="string" then
|
||||
self.Font=love.graphics.newFont(self.Font,self.FontSize)
|
||||
self.FontHeight=self.Font:getHeight()
|
||||
else
|
||||
love.graphics.setFont(self.Font)
|
||||
end
|
||||
if type(self.FontSize)=="string" then
|
||||
self.FontSize=tonumber(self.FontSize)
|
||||
love.graphics.setNewFont(self.FontSize)
|
||||
end
|
||||
love.graphics.printf(self.text, self.x+2+((self.marginL or 0)*self.DPI or self.XTween*self.DPI), self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween*self.DPI, self.width+(0 or (self.marginR or 0)*self.DPI), self.TextFormat)
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.DrawRulesE then
|
||||
for dr=1,#self.DrawRulesE do
|
||||
self.DrawRulesE[dr](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
37
client/GuiManager/Frame/newDropFrame.int
Normal file
37
client/GuiManager/Frame/newDropFrame.int
Normal file
@ -0,0 +1,37 @@
|
||||
function gui:newDropFrame(name,x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("DropFrame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.WasBeingDragged=false
|
||||
c.IsBeingDragged=false
|
||||
c.Draggable=false
|
||||
c.funcD={}
|
||||
function c:GetDroppedItems()
|
||||
local t=self:getChildren()
|
||||
local tab={}
|
||||
for i=1,#t do
|
||||
if t[i].Type=="TextImageButtonFrameDrag" then
|
||||
table.insert(tab,t[i])
|
||||
end
|
||||
end
|
||||
return tab
|
||||
end
|
||||
function c:OnDropped(func)
|
||||
table.insert(self.funcD,func)
|
||||
end
|
||||
c:OnUpdate(function(self)
|
||||
if _GuiPro.DragItem then
|
||||
if _GuiPro.DragItem.Type=="TextImageButtonFrameDrag" and love.mouse.isDown(_GuiPro.DragItem.dragbut or "m")==false and self:IsHovering() then
|
||||
local t=_GuiPro.DragItem
|
||||
_GuiPro.DragItem={}
|
||||
for i=1,#t.funcD do
|
||||
t.funcD[i](self,t)
|
||||
end
|
||||
for i=1,#self.funcD do
|
||||
self.funcD[i](self,t)
|
||||
end
|
||||
_GuiPro.hasDrag=false
|
||||
end
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
8
client/GuiManager/Frame/newFrame.int
Normal file
8
client/GuiManager/Frame/newFrame.int
Normal file
@ -0,0 +1,8 @@
|
||||
function gui:newFrame(name,x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("Frame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.WasBeingDragged=false
|
||||
c.IsBeingDragged=false
|
||||
c.Draggable=false
|
||||
return c
|
||||
end
|
||||
4
client/GuiManager/Frame/newFullFrame.int
Normal file
4
client/GuiManager/Frame/newFullFrame.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:newFullFrame(name)
|
||||
name=name or ""
|
||||
return self:newFrame(name,0,0,0,0,0,0,1,1)
|
||||
end
|
||||
59
client/GuiManager/Frame/newTabFrame.int
Normal file
59
client/GuiManager/Frame/newTabFrame.int
Normal file
@ -0,0 +1,59 @@
|
||||
function gui:newTabFrame(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=gui:newFrame(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.tabheight=20
|
||||
c.Holder=c:newFrame("Holder",0,c.tabheight,0,0,0,0,1,1)
|
||||
c.TabHolder=c:newFrame("TabHolder",0,0,0,c.tabheight,0,0,1)
|
||||
function c:setTabHeight(n)
|
||||
self.tabheight=n
|
||||
self.Holder:SetDualDim(0,-self.tabheight,0,0,0,0,1,1)
|
||||
end
|
||||
function c:addTab(name,colorT,colorH)
|
||||
if colorT and not(colorH) then
|
||||
colorH=colorT
|
||||
end
|
||||
local tab=self.TabHolder:newTextButton(name,name,0,0,0,0,0,0,0,1)
|
||||
tab.Tween=-3
|
||||
if colorT then
|
||||
tab.Color=colorT
|
||||
end
|
||||
local holder=self.Holder:newFrame(name,0,0,0,0,0,0,1,1)
|
||||
if colorH then
|
||||
holder.Color=colorH
|
||||
end
|
||||
tab.frame=holder
|
||||
tab:OnReleased(function(b,self)
|
||||
if b=="l" then
|
||||
local tt=self.Parent:getChildren()
|
||||
local th=self.Parent.Parent.Holder:getChildren()
|
||||
for i=1,#th do
|
||||
th[i].Visible=false
|
||||
end
|
||||
for i=1,#tt do
|
||||
tt[i].frame.Visible=false
|
||||
tt[i].BorderSize=1
|
||||
end
|
||||
self.BorderSize=0
|
||||
self.frame.Visible=true
|
||||
end
|
||||
end)
|
||||
local tt=self.TabHolder:getChildren()
|
||||
for i=1,#tt do
|
||||
tt[i].frame.Visible=false
|
||||
tt[i].BorderSize=1
|
||||
end
|
||||
tab.frame.Visible=true
|
||||
tab.BorderSize=0
|
||||
return tab,holder
|
||||
end
|
||||
c:OnUpdate(function(self)
|
||||
local th=self.TabHolder:getChildren()
|
||||
local l=self.width/#th
|
||||
for i=1,#th do
|
||||
th[i]:SetDualDim(l*(i-1),0,l)
|
||||
end
|
||||
if #th==0 then
|
||||
self:Destroy()
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
13
client/GuiManager/Image-Animation/SetImage.int
Normal file
13
client/GuiManager/Image-Animation/SetImage.int
Normal file
@ -0,0 +1,13 @@
|
||||
function gui:SetImage(i)
|
||||
if type(i)=="string" then
|
||||
self.Image=love.graphics.newImage(i)
|
||||
else
|
||||
self.Image=i
|
||||
end
|
||||
if self.Image~=nil then
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
end
|
||||
return self.ImageWidth,self.ImageHeigth
|
||||
end
|
||||
5
client/GuiManager/Image-Animation/UpdateImage.int
Normal file
5
client/GuiManager/Image-Animation/UpdateImage.int
Normal file
@ -0,0 +1,5 @@
|
||||
function gui:UpdateImage()
|
||||
self.ImageHeigth=self.Image:getHeight()
|
||||
self.ImageWidth=self.Image:getWidth()
|
||||
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||
end
|
||||
20
client/GuiManager/Image-Animation/getTile.int
Normal file
20
client/GuiManager/Image-Animation/getTile.int
Normal file
@ -0,0 +1,20 @@
|
||||
function gui:getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="string" then
|
||||
i=love.graphics.newImage(i)
|
||||
elseif type(i)=="userdata" then
|
||||
-- do nothing
|
||||
elseif string.find(self.Type,"Image",1,true) then
|
||||
local i,x,y,w,h=self.Image,i,x,y,w
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
--
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
57
client/GuiManager/Image-Animation/newAnim.int
Normal file
57
client/GuiManager/Image-Animation/newAnim.int
Normal file
@ -0,0 +1,57 @@
|
||||
function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.delay=delay or .05
|
||||
c.files={}
|
||||
c.AnimStart={}
|
||||
c.AnimEnd={}
|
||||
local _files=alphanumsort(love.filesystem.getDirectoryItems(file))
|
||||
for i=1,#_files do
|
||||
if string.sub(_files[i],-1,-1)~="b" then
|
||||
table.insert(c.files,love.graphics.newImage(file.."/".._files[i]))
|
||||
end
|
||||
end
|
||||
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||
c.step.parent=c
|
||||
c.rotation=0
|
||||
c.step:OnStart(function(step)
|
||||
for i=1,#step.parent.AnimStart do
|
||||
step.parent.AnimStart[i](step.parent)
|
||||
end
|
||||
end)
|
||||
c.step:OnStep(function(pos,step)
|
||||
step.parent:SetImage(step.parent.files[pos])
|
||||
end)
|
||||
c.step:OnEnd(function(step)
|
||||
for i=1,#step.parent.AnimEnd do
|
||||
step.parent.AnimEnd[i](step.parent)
|
||||
end
|
||||
end)
|
||||
function c:OnAnimStart(func)
|
||||
table.insert(self.AnimStart,func)
|
||||
end
|
||||
function c:OnAnimEnd(func)
|
||||
table.insert(self.AnimEnd,func)
|
||||
end
|
||||
function c:Pause()
|
||||
self.step:Pause()
|
||||
end
|
||||
function c:Resume()
|
||||
self.step:Resume()
|
||||
end
|
||||
function c:Reset()
|
||||
self.step.pos=1
|
||||
end
|
||||
function c:getFrames()
|
||||
return #self.files
|
||||
end
|
||||
function c:getFrame()
|
||||
return self.step.pos
|
||||
end
|
||||
function c:setFrame(n)
|
||||
return self:SetImage(self.files[n])
|
||||
end
|
||||
return c
|
||||
end
|
||||
52
client/GuiManager/Image-Animation/newAnimFromData.int
Normal file
52
client/GuiManager/Image-Animation/newAnimFromData.int
Normal file
@ -0,0 +1,52 @@
|
||||
function gui:newAnimFromData(data,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageAnimation","FromFile", x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.delay=delay or .05
|
||||
c.files=data
|
||||
c.AnimStart={}
|
||||
c.AnimEnd={}
|
||||
c:SetImage(c.files[1])
|
||||
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||
c.step.parent=c
|
||||
c.rotation=0
|
||||
c.step:OnStart(function(step)
|
||||
for i=1,#step.parent.AnimStart do
|
||||
step.parent.AnimStart[i](step.parent)
|
||||
end
|
||||
end)
|
||||
c.step:OnStep(function(pos,step)
|
||||
step.parent:SetImage(step.parent.files[pos])
|
||||
end)
|
||||
c.step:OnEnd(function(step)
|
||||
for i=1,#step.parent.AnimEnd do
|
||||
step.parent.AnimEnd[i](step.parent)
|
||||
end
|
||||
end)
|
||||
function c:OnAnimStart(func)
|
||||
table.insert(self.AnimStart,func)
|
||||
end
|
||||
function c:OnAnimEnd(func)
|
||||
table.insert(self.AnimEnd,func)
|
||||
end
|
||||
function c:Pause()
|
||||
self.step:Pause()
|
||||
end
|
||||
function c:Resume()
|
||||
self.step:Resume()
|
||||
end
|
||||
function c:Reset()
|
||||
self.step.pos=1
|
||||
end
|
||||
function c:getFrames()
|
||||
return #self.files
|
||||
end
|
||||
function c:getFrame()
|
||||
return self.step.pos
|
||||
end
|
||||
function c:setFrame(n)
|
||||
return self:SetImage(self.files[n])
|
||||
end
|
||||
return c
|
||||
end
|
||||
59
client/GuiManager/Image-Animation/newAnimFromTiles.int
Normal file
59
client/GuiManager/Image-Animation/newAnimFromTiles.int
Normal file
@ -0,0 +1,59 @@
|
||||
function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local im=love.graphics.newImage(file)
|
||||
local _x,_y=im:getDimensions()
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.delay=delay or .05
|
||||
c.files={}
|
||||
c.AnimStart={}
|
||||
c.AnimEnd={}
|
||||
for i=0,_y/yd-1 do
|
||||
for j=0,_x/xd-1 do
|
||||
table.insert(c.files,gui:getTile(im,j*xd,i*yd,xd,yd))
|
||||
end
|
||||
end
|
||||
c:SetImage(c.files[1])
|
||||
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||
c.step.parent=c
|
||||
c.rotation=0
|
||||
c.step:OnStart(function(step)
|
||||
for i=1,#step.parent.AnimStart do
|
||||
step.parent.AnimStart[i](step.parent)
|
||||
end
|
||||
end)
|
||||
c.step:OnStep(function(pos,step)
|
||||
step.parent:SetImage(step.parent.files[pos])
|
||||
end)
|
||||
c.step:OnEnd(function(step)
|
||||
for i=1,#step.parent.AnimEnd do
|
||||
step.parent.AnimEnd[i](step.parent)
|
||||
end
|
||||
end)
|
||||
function c:OnAnimStart(func)
|
||||
table.insert(self.AnimStart,func)
|
||||
end
|
||||
function c:OnAnimEnd(func)
|
||||
table.insert(self.AnimEnd,func)
|
||||
end
|
||||
function c:Pause()
|
||||
self.step:Pause()
|
||||
end
|
||||
function c:Resume()
|
||||
self.step:Resume()
|
||||
end
|
||||
function c:Reset()
|
||||
self.step.pos=1
|
||||
end
|
||||
function c:getFrames()
|
||||
return #self.files
|
||||
end
|
||||
function c:getFrame()
|
||||
return self.step.pos
|
||||
end
|
||||
function c:setFrame(n)
|
||||
return self:SetImage(self.files[n])
|
||||
end
|
||||
return c
|
||||
end
|
||||
3
client/GuiManager/Image-Animation/newFullImageLabel.int
Normal file
3
client/GuiManager/Image-Animation/newFullImageLabel.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:newFullImageLabel(i,name)
|
||||
return self:newImageLabel(i,name,0,0,0,0,0,0,1,1)
|
||||
end
|
||||
25
client/GuiManager/Image-Animation/newImageButton.int
Normal file
25
client/GuiManager/Image-Animation/newImageButton.int
Normal file
@ -0,0 +1,25 @@
|
||||
function gui:newImageButton(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageButton",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
else
|
||||
c.Image=i
|
||||
end
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.rotation=0
|
||||
if c.Image~=nil then
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageHeight=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
c:OnEnter(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorH)
|
||||
end)
|
||||
c:OnExit(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorN)
|
||||
end)
|
||||
return c
|
||||
end
|
||||
18
client/GuiManager/Image-Animation/newImageLabel.int
Normal file
18
client/GuiManager/Image-Animation/newImageLabel.int
Normal file
@ -0,0 +1,18 @@
|
||||
function gui:newImageLabel(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("ImageLabel",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
else
|
||||
c.Image=i
|
||||
end
|
||||
c.Visibility=0
|
||||
c.ImageVisibility=1
|
||||
c.rotation=0
|
||||
if c.Image~=nil then
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
return c
|
||||
end
|
||||
62
client/GuiManager/Image-Animation/newVideo.int
Normal file
62
client/GuiManager/Image-Animation/newVideo.int
Normal file
@ -0,0 +1,62 @@
|
||||
function gui:newVideo(name,i,x,y,w,h,sx,sy,sw,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("Video",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" then
|
||||
c.Video=love.graphics.newVideo(i)
|
||||
else
|
||||
c.Video=i
|
||||
end
|
||||
c.Visibility=0
|
||||
c.VideoVisibility=1
|
||||
c.rotation=0
|
||||
if c.Video~=nil then
|
||||
c.VideoHeigth=c.Video:getHeight()
|
||||
c.VideoWidth=c.Video:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.VideoWidth,c.VideoHeigth)
|
||||
end
|
||||
c.funcV={}
|
||||
function c:Play()
|
||||
self.handStart=true
|
||||
self.Video:play()
|
||||
end
|
||||
function c:Pause()
|
||||
self.Video:pause()
|
||||
end
|
||||
c.Resume=c.Play
|
||||
function c:Stop()
|
||||
self.handStart=false
|
||||
self:Pause()
|
||||
self:Rewind()
|
||||
for i=1,# self.funcV do
|
||||
self.funcV[i](self)
|
||||
end
|
||||
end
|
||||
function c:OnVideoStopped(func)
|
||||
table.insert(self.funcV,func)
|
||||
end
|
||||
function c:Rewind()
|
||||
self.Video:rewind()
|
||||
end
|
||||
function c:Restart()
|
||||
self:Rewind()
|
||||
self:Play()
|
||||
end
|
||||
function c:Seek(o)
|
||||
self.Video:seek(o)
|
||||
end
|
||||
function c:Tell()
|
||||
self.Video:tell()
|
||||
end
|
||||
function c:SetFilter(min, mag, anisotropy)
|
||||
self.Video:setFilter(min, mag, anisotropy)
|
||||
end
|
||||
function c:IsPlaying()
|
||||
return self.Video:isPlaying()
|
||||
end
|
||||
c:OnUpdate(function(self)
|
||||
if self.Video:isPlaying()==false and self.handStart == true then
|
||||
self:Stop()
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
51
client/GuiManager/Item/newDragItem.int
Normal file
51
client/GuiManager/Item/newDragItem.int
Normal file
@ -0,0 +1,51 @@
|
||||
function gui:newDragItem(t,i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextImageButtonFrameDrag",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.WasBeingDragged=false
|
||||
c.IsBeingDragged=false
|
||||
c.Draggable=true
|
||||
c.funcD={}
|
||||
if type(i)=="string" then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
c.ImageVisibility=1
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
elseif type(i)=="image" then
|
||||
c.Image=i
|
||||
c.ImageVisibility=1
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
c:OnDragStart(function(self,x,y)
|
||||
if _GuiPro.hasDrag==false then
|
||||
self:setParent(_GuiPro)
|
||||
self:SetDualDim(x,y)
|
||||
self:TopStack()
|
||||
end
|
||||
end)
|
||||
c.rotation=0
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.TextVisibility=1
|
||||
c.TextColor = {0, 0, 0}
|
||||
function c:OnDropped(func)
|
||||
table.insert(self.funcD,func)
|
||||
end
|
||||
c:OnUpdate(function(self)
|
||||
if love.mouse.isDown("m" or self.dragbut)==false and self==_GuiPro.DragItem and self.hovering==false then
|
||||
_GuiPro.DragItem={}
|
||||
for i=1,#self.func7 do
|
||||
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||
end
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
28
client/GuiManager/Item/newItem.int
Normal file
28
client/GuiManager/Item/newItem.int
Normal file
@ -0,0 +1,28 @@
|
||||
function gui:newItem(t,i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextImageButtonFrame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if type(i)=="string" then
|
||||
c.Image=love.graphics.newImage(i)
|
||||
else
|
||||
c.Image=i
|
||||
end
|
||||
c.rotation=0
|
||||
c.ImageVisibility=1
|
||||
c.Draggable=false
|
||||
if c.Image~=nil then
|
||||
c.ImageHeigth=c.Image:getHeight()
|
||||
c.ImageWidth=c.Image:getWidth()
|
||||
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||
end
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.TextColor = {0, 0, 0}
|
||||
return c
|
||||
end
|
||||
45
client/GuiManager/Misc/AdvTextBox.int
Normal file
45
client/GuiManager/Misc/AdvTextBox.int
Normal file
@ -0,0 +1,45 @@
|
||||
function gui:AdvTextBox(txt,x,y,w,h,sx,sy,sw,sh)
|
||||
name="AdvTextBox"
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("AdvTextBoxFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||
c.Draggable=true
|
||||
c.dragbut="r"
|
||||
c.BorderSize=0
|
||||
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||
c.funcO={}
|
||||
c.funcX={}
|
||||
c:OnDragStart(function(self)
|
||||
self:TopStack()
|
||||
end)
|
||||
--local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||
--temp.Tween=-5
|
||||
--temp.XTween=-2
|
||||
--temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||
--temp.Color=Color.Red
|
||||
c.tLink=c:newTextBox("puttext","TextBox",5,h-95,-40,30,0,1,1,1)
|
||||
c.tLink.Color=Color.light_gray
|
||||
c.tLink.ClearOnFocus=true
|
||||
c.tLink:OnFocus(function(self) self.ClearOnFocus=false end)
|
||||
local temp=c:newTextButton("OK","Ok",-35,h-65,30,30,1,1)
|
||||
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcO do self.Parent.funcO[i](self.Parent,self.Parent.tLink.text) end end)
|
||||
temp.Color=Color.Green
|
||||
temp.XTween=-2
|
||||
local temp=c:newTextButton("X","Cancel",-35,h-95,30,30,1,1)
|
||||
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent,self.Parent.tLink.text) end end)
|
||||
temp.Color=Color.Red
|
||||
temp.XTween=-2
|
||||
function c:Close()
|
||||
self.Visible=false
|
||||
end
|
||||
function c:Open()
|
||||
self.Visible=true
|
||||
end
|
||||
function c:OnOk(func)
|
||||
table.insert(self.funcO,func)
|
||||
end
|
||||
function c:OnX(func)
|
||||
table.insert(self.funcX,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
36
client/GuiManager/Misc/ApplyGradient.int
Normal file
36
client/GuiManager/Misc/ApplyGradient.int
Normal file
@ -0,0 +1,36 @@
|
||||
function _GuiPro.gradient(colors)
|
||||
local direction = colors.direction or "horizontal"
|
||||
colors.direction=nil
|
||||
trans = colors.trans or 255
|
||||
trans=math.floor(trans)
|
||||
if direction == "horizontal" then
|
||||
direction = true
|
||||
elseif direction == "vertical" then
|
||||
direction = false
|
||||
else
|
||||
error("Invalid direction '" .. tostring(direction) "' for gradient. Horizontal or vertical expected.")
|
||||
end
|
||||
local result = love.image.newImageData(direction and 1 or #colors, direction and #colors or 1)
|
||||
for __i, color in ipairs(colors) do
|
||||
local x, y
|
||||
if direction then
|
||||
x, y = 0, __i - 1
|
||||
else
|
||||
x, y = __i - 1, 0
|
||||
end
|
||||
result:setPixel(x, y, color[1], color[2], color[3], trans)
|
||||
end
|
||||
result = love.graphics.newImage(result)
|
||||
result:setFilter('linear', 'linear')
|
||||
return result
|
||||
end
|
||||
function _GuiPro.drawinrect(img, x, y, w, h, r, ox, oy, kx, ky)
|
||||
love.graphics.draw(img, x, y, r, w / img:getWidth(), h / img:getHeight(), ox, oy, kx, ky)
|
||||
end
|
||||
function gui:ApplyGradient(rules)
|
||||
self.Image=nil
|
||||
self.Type=self.Type.."w/GradImage"
|
||||
self.rotation=0
|
||||
self.ImageVisibility=rules.visibility or 1
|
||||
self:SetImage(_GuiPro.gradient(rules))
|
||||
end
|
||||
10
client/GuiManager/Misc/BottomStack.int
Normal file
10
client/GuiManager/Misc/BottomStack.int
Normal file
@ -0,0 +1,10 @@
|
||||
function gui:BottomStack()
|
||||
childs=self.Parent:getChildren()
|
||||
for i=1,#childs do
|
||||
if childs[i]==self then
|
||||
table.remove(self.Parent.Children,i)
|
||||
table.insert(self.Parent.Children,1,self)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
4
client/GuiManager/Misc/Center.int
Normal file
4
client/GuiManager/Misc/Center.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:Center()
|
||||
local x,y=self:getFullSize()
|
||||
self:SetDualDim(-math.floor(x/2),-math.floor(y/2),nil,nil,.5,.5)
|
||||
end
|
||||
9
client/GuiManager/Misc/Destroy.int
Normal file
9
client/GuiManager/Misc/Destroy.int
Normal file
@ -0,0 +1,9 @@
|
||||
function gui:Destroy()
|
||||
check=self.Parent:getChildren()
|
||||
local cc=0
|
||||
for cc=1,#check do
|
||||
if check[cc]==self then
|
||||
table.remove(self.Parent.Children,cc)
|
||||
end
|
||||
end
|
||||
end
|
||||
25
client/GuiManager/Misc/GetAllChildren.int
Normal file
25
client/GuiManager/Misc/GetAllChildren.int
Normal file
@ -0,0 +1,25 @@
|
||||
function gui:GetAllChildren()
|
||||
local Stuff = {}
|
||||
function Seek(Items)
|
||||
for i=1,#Items do
|
||||
if Items[i].Visible==true then
|
||||
table.insert(Stuff,Items[i])
|
||||
local NItems = Items[i]:getChildren()
|
||||
if NItems ~= nil then
|
||||
Seek(NItems)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local Objs = self:getChildren()
|
||||
for i=1,#Objs do
|
||||
if Objs[i].Visible==true then
|
||||
table.insert(Stuff,Objs[i])
|
||||
local Items = Objs[i]:getChildren()
|
||||
if Items ~= nil then
|
||||
Seek(Items)
|
||||
end
|
||||
end
|
||||
end
|
||||
return Stuff
|
||||
end
|
||||
3
client/GuiManager/Misc/GetChild.int
Normal file
3
client/GuiManager/Misc/GetChild.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:GetChild(name)
|
||||
return self.Children[name] or self
|
||||
end
|
||||
3
client/GuiManager/Misc/InGrid.int
Normal file
3
client/GuiManager/Misc/InGrid.int
Normal file
@ -0,0 +1,3 @@
|
||||
function InGrid(i,x,y,s)
|
||||
return math.floor((i-1)/x)*s,(i-1)*s-(math.floor((i-1)/y)*(s*x))
|
||||
end
|
||||
5
client/GuiManager/Misc/InGridX.int
Normal file
5
client/GuiManager/Misc/InGridX.int
Normal file
@ -0,0 +1,5 @@
|
||||
function InGridX(i,w,h,xs,ys)
|
||||
local xc,yc=math.floor(w/xs),math.floor(h/ys)
|
||||
local xi,yi=(i-1)%xc,math.floor((i-1)/xc)
|
||||
return xi*xs,yi*ys
|
||||
end
|
||||
5
client/GuiManager/Misc/InGridY.int
Normal file
5
client/GuiManager/Misc/InGridY.int
Normal file
@ -0,0 +1,5 @@
|
||||
function InGridY(i,w,h,xs,ys)
|
||||
local xc,yc=math.floor(w/xs),math.floor(h/ys)
|
||||
local xi,yi=math.floor((i-1)/yc),(i-1)%yc
|
||||
return xi*xs,yi*ys
|
||||
end
|
||||
3
client/GuiManager/Misc/IsHovering.int
Normal file
3
client/GuiManager/Misc/IsHovering.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:IsHovering()
|
||||
return (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height)
|
||||
end
|
||||
4
client/GuiManager/Misc/Move.int
Normal file
4
client/GuiManager/Misc/Move.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:Move(x,y)
|
||||
self.offset.pos.x=self.offset.pos.x+x
|
||||
self.offset.pos.y=self.offset.pos.y+y
|
||||
end
|
||||
32
client/GuiManager/Misc/SetDualDim.int
Normal file
32
client/GuiManager/Misc/SetDualDim.int
Normal file
@ -0,0 +1,32 @@
|
||||
function gui:SetDualDim(x, y, w, h, sx ,sy ,sw ,sh)
|
||||
if sx then
|
||||
self.scale.pos.x=sx
|
||||
end
|
||||
if sy then
|
||||
self.scale.pos.y=sy
|
||||
end
|
||||
if x then
|
||||
self.offset.pos.x=x
|
||||
end
|
||||
if y then
|
||||
self.offset.pos.y=y
|
||||
end
|
||||
if sw then
|
||||
self.scale.size.x=sw
|
||||
end
|
||||
if sh then
|
||||
self.scale.size.y=sh
|
||||
end
|
||||
if w then
|
||||
self.offset.size.x=w
|
||||
end
|
||||
if h then
|
||||
self.offset.size.y=h
|
||||
end
|
||||
if self.Image then
|
||||
self:SetImage(self.Image)
|
||||
end
|
||||
end
|
||||
function gui:setDualDim(...)
|
||||
self:SetDualDim(...)
|
||||
end
|
||||
5
client/GuiManager/Misc/SetHand.int
Normal file
5
client/GuiManager/Misc/SetHand.int
Normal file
@ -0,0 +1,5 @@
|
||||
_GuiPro.CursorN=love.mouse.getSystemCursor("arrow")
|
||||
_GuiPro.CursorH=love.mouse.getSystemCursor("hand")
|
||||
function gui:SetHand(img,x,y)
|
||||
_GuiPro.CursorN=love.mouse.newCursor(img,x,y)
|
||||
end
|
||||
3
client/GuiManager/Misc/SetHover.int
Normal file
3
client/GuiManager/Misc/SetHover.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:SetHover(img,x,y)
|
||||
_GuiPro.CursorH=love.mouse.newCursor(img,x,y)
|
||||
end
|
||||
4
client/GuiManager/Misc/SetName.int
Normal file
4
client/GuiManager/Misc/SetName.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui:SetName(name)
|
||||
self.Parent.Children[name]=self
|
||||
self.Name=name
|
||||
end
|
||||
10
client/GuiManager/Misc/TopStack.int
Normal file
10
client/GuiManager/Misc/TopStack.int
Normal file
@ -0,0 +1,10 @@
|
||||
function gui:TopStack()
|
||||
childs=self.Parent:getChildren()
|
||||
for i=1,#childs do
|
||||
if childs[i]==self then
|
||||
table.remove(self.Parent.Children,i)
|
||||
table.insert(self.Parent.Children,self)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
3
client/GuiManager/Misc/addDominance.int
Normal file
3
client/GuiManager/Misc/addDominance.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:addDominance()
|
||||
_GuiPro.TopHovered=self
|
||||
end
|
||||
6
client/GuiManager/Misc/addHotKey.int
Normal file
6
client/GuiManager/Misc/addHotKey.int
Normal file
@ -0,0 +1,6 @@
|
||||
function gui:addHotKey(key)
|
||||
local temp=self:newFrame(0,0,0,0)
|
||||
temp.Visible=false
|
||||
temp:setHotKey(key)
|
||||
return temp
|
||||
end
|
||||
7
client/GuiManager/Misc/alphanumsort.int
Normal file
7
client/GuiManager/Misc/alphanumsort.int
Normal file
@ -0,0 +1,7 @@
|
||||
function alphanumsort(o)
|
||||
local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)")
|
||||
return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n)
|
||||
end
|
||||
table.sort(o, function(a,b) return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)< tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
|
||||
return o
|
||||
end
|
||||
3
client/GuiManager/Misc/centerX.int
Normal file
3
client/GuiManager/Misc/centerX.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:centerX()
|
||||
self:SetDualDim(-(self.width/2),nil,nil,nil,.5)
|
||||
end
|
||||
3
client/GuiManager/Misc/centerY.int
Normal file
3
client/GuiManager/Misc/centerY.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:centerY()
|
||||
self:SetDualDim(nil,-(self.height/2),nil,nil,nil,.5)
|
||||
end
|
||||
3
client/GuiManager/Misc/disrespectHierarchy.int
Normal file
3
client/GuiManager/Misc/disrespectHierarchy.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:disrespectHierarchy()
|
||||
_GuiPro.Hierarchy=false
|
||||
end
|
||||
3
client/GuiManager/Misc/getChildren.int
Normal file
3
client/GuiManager/Misc/getChildren.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:getChildren()
|
||||
return self.Children
|
||||
end
|
||||
3
client/GuiManager/Misc/getColor.int
Normal file
3
client/GuiManager/Misc/getColor.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:getColor(cindex)
|
||||
return Color[cindex]
|
||||
end
|
||||
12
client/GuiManager/Misc/getFullSize.int
Normal file
12
client/GuiManager/Misc/getFullSize.int
Normal file
@ -0,0 +1,12 @@
|
||||
function gui:getFullSize()
|
||||
local maxx,maxy=-math.huge,-math.huge
|
||||
local temp = self:GetAllChildren()
|
||||
for i=1,#temp do
|
||||
if temp[i].width>maxx then
|
||||
maxx=temp[i].width+temp[i].offset.pos.x
|
||||
elseif temp[i].height>maxy then
|
||||
maxy=temp[i].height+temp[i].offset.pos.y
|
||||
end
|
||||
end
|
||||
return maxx,maxy
|
||||
end
|
||||
5
client/GuiManager/Misc/getHighest.int
Normal file
5
client/GuiManager/Misc/getHighest.int
Normal file
@ -0,0 +1,5 @@
|
||||
function gui:getHighest()
|
||||
if self.Children[#self.Children]~=nil then
|
||||
return self.Children[#self.Children]
|
||||
end
|
||||
end
|
||||
5
client/GuiManager/Misc/getLowest.int
Normal file
5
client/GuiManager/Misc/getLowest.int
Normal file
@ -0,0 +1,5 @@
|
||||
function gui:getLowest()
|
||||
if self.Children[1]~=nil then
|
||||
return self.Children[1]
|
||||
end
|
||||
end
|
||||
9
client/GuiManager/Misc/isDescendant.int
Normal file
9
client/GuiManager/Misc/isDescendant.int
Normal file
@ -0,0 +1,9 @@
|
||||
function gui:isDescendant(obj)
|
||||
local things=obj:GetAllChildren()
|
||||
for i=1,#things do
|
||||
if things[i]==self then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
3
client/GuiManager/Misc/isHighest.int
Normal file
3
client/GuiManager/Misc/isHighest.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:isHighest()
|
||||
return (self==self.Parent:getHighest())
|
||||
end
|
||||
3
client/GuiManager/Misc/isLowest.int
Normal file
3
client/GuiManager/Misc/isLowest.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:isLowest()
|
||||
return (self==self.Parent:getLowest())
|
||||
end
|
||||
6
client/GuiManager/Misc/massMutate.int
Normal file
6
client/GuiManager/Misc/massMutate.int
Normal file
@ -0,0 +1,6 @@
|
||||
function gui.massMutate(t,...)
|
||||
local mut={...}
|
||||
for i=1,#mut do
|
||||
mut[i]:Mutate(t)
|
||||
end
|
||||
end
|
||||
41
client/GuiManager/Misc/newCheckBox.int
Normal file
41
client/GuiManager/Misc/newCheckBox.int
Normal file
@ -0,0 +1,41 @@
|
||||
if love.filesystem.exists("CheckBoxes.png") then
|
||||
_GuiPro.UC=gui:getTile("CheckBoxes.png",0,0,16,16)
|
||||
_GuiPro.C=gui:getTile("CheckBoxes.png",16,0,16,16)
|
||||
_GuiPro.UCH=gui:getTile("CheckBoxes.png",0,16,16,16)
|
||||
_GuiPro.CH=gui:getTile("CheckBoxes.png",16,16,16,16)
|
||||
end
|
||||
function gui:newCheckBox(name,x,y)
|
||||
if not(_GuiPro.UC) then error("CheckBoxes.png not found! Cannot currently use checkbox without the data") end
|
||||
if type(name)~="String" then
|
||||
x,y,name=name,x,"CheckBox"
|
||||
end
|
||||
local c=self:newImageLabel(_GuiPro.UC,name, x, y, 16,16)
|
||||
c.Visibility=0
|
||||
c.check=false
|
||||
c:OnEnter(function(self)
|
||||
if self.check then
|
||||
self:SetImage(_GuiPro.CH)
|
||||
else
|
||||
self:SetImage(_GuiPro.UCH)
|
||||
end
|
||||
end)
|
||||
function c:isChecked()
|
||||
return self.check
|
||||
end
|
||||
c:OnExit(function(self)
|
||||
if self.check then
|
||||
self:SetImage(_GuiPro.C)
|
||||
else
|
||||
self:SetImage(_GuiPro.UC)
|
||||
end
|
||||
end)
|
||||
c:OnReleased(function(b,self)
|
||||
self.check=not(self.check)
|
||||
if self.check then
|
||||
self:SetImage(_GuiPro.CH)
|
||||
else
|
||||
self:SetImage(_GuiPro.UCH)
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
36
client/GuiManager/Misc/newMessageBox.int
Normal file
36
client/GuiManager/Misc/newMessageBox.int
Normal file
@ -0,0 +1,36 @@
|
||||
function gui:newMessageBox(txt,x,y,w,h,sx,sy,sw,sh)
|
||||
name="MessageBox"
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("MessageBoxFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||
c.Draggable=true
|
||||
c.dragbut="r"
|
||||
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||
c.BorderSize=0
|
||||
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||
c.funcO={}
|
||||
c.funcX={}
|
||||
c:OnDragStart(function(self)
|
||||
self:TopStack()
|
||||
end)
|
||||
local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||
temp.Tween=-5
|
||||
temp.XTween=-2
|
||||
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||
temp.Color=Color.Red
|
||||
local temp=c:newTextButton("OK","Ok",0,h-65,0,30,.25,1,.5)
|
||||
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcO do self.Parent.funcO[i](self.Parent) end end)
|
||||
temp.Color=Color.Green
|
||||
function c:Close()
|
||||
self.Visible=false
|
||||
end
|
||||
function c:Open()
|
||||
self.Visible=true
|
||||
end
|
||||
function c:OnOk(func)
|
||||
table.insert(self.funcO,func)
|
||||
end
|
||||
function c:OnX(func)
|
||||
table.insert(self.funcX,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
49
client/GuiManager/Misc/newPart.int
Normal file
49
client/GuiManager/Misc/newPart.int
Normal file
@ -0,0 +1,49 @@
|
||||
function gui:newPart(x, y,w ,h , sx ,sy ,sw ,sh)
|
||||
local c = {}
|
||||
setmetatable(c, gui)
|
||||
if self==gui then
|
||||
c.Parent=_GuiPro
|
||||
else
|
||||
c.Parent=self
|
||||
end
|
||||
c.funcs={}
|
||||
c.funcs2={}
|
||||
c.funcs3={}
|
||||
c.funcs4={}
|
||||
c.funcs5={}
|
||||
c.func6={}
|
||||
c.func7={}
|
||||
c.func8={}
|
||||
c.func9={}
|
||||
c.func10={}
|
||||
c.form="rectangle"
|
||||
c.Color = {255, 255, 255}
|
||||
c.scale={}
|
||||
c.scale.size={}
|
||||
c.scale.size.x=sw or 0
|
||||
c.scale.size.y=sh or 0
|
||||
c.offset={}
|
||||
c.offset.size={}
|
||||
c.offset.size.x=w or 0
|
||||
c.offset.size.y=h or 0
|
||||
c.scale.pos={}
|
||||
c.scale.pos.x=sx or 0
|
||||
c.scale.pos.y=sy or 0
|
||||
c.offset.pos={}
|
||||
c.offset.pos.x=x or 0
|
||||
c.offset.pos.y=y or 0
|
||||
c.VIS=true
|
||||
c.Visible=true
|
||||
c.Visibility=1
|
||||
c.BorderColor={0,0,0}
|
||||
c.BorderSize=0
|
||||
c.Type="Part"
|
||||
c.Name="GuiPart"
|
||||
_GuiPro.count=_GuiPro.count+1
|
||||
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
|
||||
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
|
||||
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
|
||||
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
|
||||
table.insert(c.Parent.Children,c)
|
||||
return c
|
||||
end
|
||||
45
client/GuiManager/Misc/newProgressBar.int
Normal file
45
client/GuiManager/Misc/newProgressBar.int
Normal file
@ -0,0 +1,45 @@
|
||||
function gui:newProgressBar(txt,x,y,w,h,sx,sy,sw,sh)
|
||||
name="newProgressBar"
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("newProgressBarFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||
c.Draggable=true
|
||||
c.dragbut="r"
|
||||
c.BorderSize=0
|
||||
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||
c.funcO={}
|
||||
c.funcX={}
|
||||
c:OnDragStart(function(self)
|
||||
self:TopStack()
|
||||
end)
|
||||
local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||
temp.Tween=-5
|
||||
temp.XTween=-2
|
||||
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||
temp.Color=Color.Red
|
||||
c.BarBG=c:newTextButton("",5,h-65,-10,30,0,1,1)
|
||||
c.BarBG:ApplyGradient{Color.Red,Color.light_red}
|
||||
c.Bar=c.BarBG:newTextLabel("",0,0,0,0,0,0,0,1)
|
||||
c.Bar:ApplyGradient{Color.Green,Color.light_green}
|
||||
c.BarDisp=c.BarBG:newTextLabel("0%","0%",0,0,0,0,0,0,1,1)
|
||||
c.BarDisp.Visibility=0
|
||||
c.BarDisp.Link=c.Bar
|
||||
c.BarDisp:OnUpdate(function(self)
|
||||
self.text=self.Link.scale.size.x*100 .."%"
|
||||
end)
|
||||
c.Func1={}
|
||||
function c:On100(func)
|
||||
table.insert(self.Func1,func)
|
||||
end
|
||||
c:OnUpdate(function(self)
|
||||
if self.Bar.scale.size.x*100>=100 then
|
||||
for P=1,#self.Func1 do
|
||||
self.Func1[P](self)
|
||||
end
|
||||
end
|
||||
end)
|
||||
function c:SetPercentage(n)
|
||||
self.Bar:SetDualDim(0,0,0,0,0,0,n/100,1)
|
||||
end
|
||||
return c
|
||||
end
|
||||
42
client/GuiManager/Misc/newScrollBar.int
Normal file
42
client/GuiManager/Misc/newScrollBar.int
Normal file
@ -0,0 +1,42 @@
|
||||
function gui:newScrollBar(color1,color2)
|
||||
local scrollbar=self:newFrame(-20,0,20,0,1,0,0,1)
|
||||
scrollbar.funcS={}
|
||||
scrollbar.Color=color1 or Color.saddle_brown
|
||||
scrollbar:OnClicked(function(b,self,x,y)
|
||||
love.mouse.setX(self.x+10)
|
||||
if y>=10 and y<=self.height-10 then
|
||||
self.mover:SetDualDim(0,y-10)
|
||||
end
|
||||
if y<10 then
|
||||
love.mouse.setY(10+self.y)
|
||||
end
|
||||
if y>self.height-10 then
|
||||
love.mouse.setY((self.height-10)+self.y)
|
||||
end
|
||||
for i=1,#self.funcS do
|
||||
self.funcS[i](self,self:getPosition())
|
||||
end
|
||||
end)
|
||||
scrollbar:OnEnter(function(self)
|
||||
self:addDominance()
|
||||
end)
|
||||
scrollbar:OnExit(function(self)
|
||||
self:removeDominance()
|
||||
end)
|
||||
scrollbar.mover=scrollbar:newTextButton("","",0,0,20,20)
|
||||
scrollbar.mover.Color=color2 or Color.light_brown
|
||||
function scrollbar:getPosition()
|
||||
return ((self.mover.offset.pos.y)/(self.height-20))*100
|
||||
end
|
||||
function scrollbar:setPosition(n)
|
||||
print((self.height-20),n)
|
||||
self.mover.offset.pos.y=((self.height-20)/(100/n))
|
||||
for i=1,#self.funcS do
|
||||
self.funcS[i](self,self:getPosition())
|
||||
end
|
||||
end
|
||||
function scrollbar:OnScroll(func)
|
||||
table.insert(self.funcS,func)
|
||||
end
|
||||
return scrollbar
|
||||
end
|
||||
98
client/GuiManager/Misc/newScrollMenu.int
Normal file
98
client/GuiManager/Misc/newScrollMenu.int
Normal file
@ -0,0 +1,98 @@
|
||||
function gui:newScrollMenu(title,tabN,onloop,x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local Main = self:newFrame(x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||
Title.Tween=-4
|
||||
Title.FontSize=12
|
||||
Title:OnReleased(function(b,self)
|
||||
self.Parent.Tick=not(self.Parent.Tick)
|
||||
end)
|
||||
local scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||
scroll:OnClicked(function(b,self,x,y)
|
||||
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||
if self.Parent.Mover.offset.pos.y<0 then
|
||||
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||
end
|
||||
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||
end
|
||||
local temp = #self.Parent.TList
|
||||
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||
end)
|
||||
Main:OnUpdate(function(self)
|
||||
if self.Tick==false then
|
||||
self.Visibility=0
|
||||
end
|
||||
end)
|
||||
scroll:OnUpdate(function(self)
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||
Main.Mover=Mover
|
||||
Main.TList=tabN
|
||||
Main.pos=1
|
||||
Main.Tick=true
|
||||
function Main:Update(title,tabN,onloop)
|
||||
ch=self:getChildren()
|
||||
for i=#ch,1,-1 do
|
||||
ch[i]:Destroy()
|
||||
end
|
||||
Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||
Title.Tween=-4
|
||||
Title.FontSize=12
|
||||
Title:OnReleased(function(b,self)
|
||||
self.Parent.Tick=not(self.Parent.Tick)
|
||||
end)
|
||||
scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||
scroll:OnClicked(function(b,self,x,y)
|
||||
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||
if self.Parent.Mover.offset.pos.y<0 then
|
||||
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||
end
|
||||
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||
end
|
||||
local temp = #self.Parent.TList
|
||||
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||
end)
|
||||
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||
Main.Mover=Mover
|
||||
Main.TList=tabN
|
||||
Main.pos=1
|
||||
Main.Tick=true
|
||||
scroll:OnUpdate(function(self)
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
for i=1,math.floor(Main.height/20)-1 do
|
||||
local temp=Main:newTextButton("","Item"..i,0,i*20,-20,20,0,0,1)
|
||||
temp.FontSize=10
|
||||
temp.Tween=-4
|
||||
temp.pos=i
|
||||
temp:OnUpdate(function(self)
|
||||
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
if onloop then
|
||||
onloop(temp,i)
|
||||
end
|
||||
end
|
||||
end
|
||||
io.write(tostring(Main.height).."\n")
|
||||
for i=1,math.floor(Main.height/20)-1 do
|
||||
local temp=Main:newTextButton("Item"..i,0,i*20,-20,20,0,0,1)
|
||||
temp.FontSize=10
|
||||
temp.Tween=-4
|
||||
temp.pos=i
|
||||
temp:OnUpdate(function(self)
|
||||
if self.Parent.TList[(self.Parent.pos+self.pos)-1]~=nil then
|
||||
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||
else
|
||||
self.text=""
|
||||
end
|
||||
self.Visible=self.Parent.Tick
|
||||
end)
|
||||
if onloop then
|
||||
onloop(temp,i)
|
||||
end
|
||||
end
|
||||
return Main
|
||||
end
|
||||
6
client/GuiManager/Misc/removeAllChildren.int
Normal file
6
client/GuiManager/Misc/removeAllChildren.int
Normal file
@ -0,0 +1,6 @@
|
||||
function gui:destroyAllChildren()
|
||||
local c=self.Children
|
||||
for i=1,#c do
|
||||
c[i]:Destroy()
|
||||
end
|
||||
end
|
||||
3
client/GuiManager/Misc/removeDominance.int
Normal file
3
client/GuiManager/Misc/removeDominance.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:removeDominance()
|
||||
_GuiPro.TopHovered=nil
|
||||
end
|
||||
3
client/GuiManager/Misc/respectHierarchy.int
Normal file
3
client/GuiManager/Misc/respectHierarchy.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:respectHierarchy()
|
||||
_GuiPro.Hierarchy=true
|
||||
end
|
||||
4
client/GuiManager/Misc/round.int
Normal file
4
client/GuiManager/Misc/round.int
Normal file
@ -0,0 +1,4 @@
|
||||
function gui.round(num, idp)
|
||||
local mult = 10^(idp or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
3
client/GuiManager/Misc/setBG.int
Normal file
3
client/GuiManager/Misc/setBG.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui.setBG(i)
|
||||
gui.ff:SetImage(i)
|
||||
end
|
||||
7
client/GuiManager/Misc/setColor.int
Normal file
7
client/GuiManager/Misc/setColor.int
Normal file
@ -0,0 +1,7 @@
|
||||
function gui:setColor(a,b,c)
|
||||
if type(a)=="string" then
|
||||
self.Color=Color[a]
|
||||
elseif type(a)=="number" then
|
||||
self.Color=Color.new(a,b,c)
|
||||
end
|
||||
end
|
||||
3
client/GuiManager/Misc/setDefualtFont.int
Normal file
3
client/GuiManager/Misc/setDefualtFont.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:setDefualtFont(font)
|
||||
_defaultfont = font
|
||||
end
|
||||
24
client/GuiManager/Misc/setHotKey.int
Normal file
24
client/GuiManager/Misc/setHotKey.int
Normal file
@ -0,0 +1,24 @@
|
||||
function gui:setHotKey(key)
|
||||
local tab=key:split("+")
|
||||
self.hotkeys=tab
|
||||
self.cooldown=false
|
||||
self.Alarm=multi:newAlarm(1)
|
||||
self.Alarm.parent=self
|
||||
self.args={}
|
||||
self.funcHK=multi:newConnection()
|
||||
self.Alarm:OnRing(function(alarm) alarm.parent.cooldown=false end)
|
||||
function self:OnHotKey(func)
|
||||
self.funcHK:connect(func)
|
||||
end
|
||||
self:OnUpdate(function(self)
|
||||
if self.cooldown then return end
|
||||
for i=1,#self.hotkeys do
|
||||
if not(love.keyboard.isDown(self.hotkeys[i])) then
|
||||
return
|
||||
end
|
||||
end
|
||||
self.cooldown=true
|
||||
self.funcHK:Fire(self)
|
||||
self.Alarm:Reset()
|
||||
end)
|
||||
end
|
||||
3
client/GuiManager/Misc/setNewFont.int
Normal file
3
client/GuiManager/Misc/setNewFont.int
Normal file
@ -0,0 +1,3 @@
|
||||
function gui:setNewFont(FontSize)
|
||||
self.Font=love.graphics.setNewFont(tonumber(FontSize))
|
||||
end
|
||||
14
client/GuiManager/Misc/setParent.int
Normal file
14
client/GuiManager/Misc/setParent.int
Normal file
@ -0,0 +1,14 @@
|
||||
function gui:setParent(parent,name)-- Needs fixing!!!
|
||||
local temp=self.Parent:getChildren()
|
||||
for i=1,#temp do
|
||||
if temp[i]==self then
|
||||
table.remove(self.Parent.Children,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
table.insert(parent.Children,self)
|
||||
self.Parent=parent
|
||||
if name then
|
||||
self:SetName(name)
|
||||
end
|
||||
end
|
||||
14
client/GuiManager/Misc/setVisibility.int
Normal file
14
client/GuiManager/Misc/setVisibility.int
Normal file
@ -0,0 +1,14 @@
|
||||
function gui:setVisiblity(val)
|
||||
self.Visible=val
|
||||
self.oV=val
|
||||
doto=self:GetAllChildren()
|
||||
if val==false then
|
||||
for i=1,#doto do
|
||||
doto[i].Visible=val
|
||||
end
|
||||
else
|
||||
for i=1,#doto do
|
||||
doto[i].Visible=doto[i].oV
|
||||
end
|
||||
end
|
||||
end
|
||||
6
client/GuiManager/Misc/setgetText.int
Normal file
6
client/GuiManager/Misc/setgetText.int
Normal file
@ -0,0 +1,6 @@
|
||||
function gui:setText(txt)
|
||||
self.text=txt
|
||||
end
|
||||
function gui:getText(txt)
|
||||
return self.text
|
||||
end
|
||||
98
client/GuiManager/Text/newTextBox.int
Normal file
98
client/GuiManager/Text/newTextBox.int
Normal file
@ -0,0 +1,98 @@
|
||||
function gui:newTextBox(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextBox",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.ClearOnFocus=false
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.ttext= t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
c.Active=false
|
||||
c.hidden=false
|
||||
c.funcF={function()
|
||||
love.keyboard.setTextInput(true)
|
||||
end}
|
||||
c.cooldown=false
|
||||
c.cooldown2=false
|
||||
c.funcE={function()
|
||||
love.keyboard.setTextInput(false)
|
||||
end}
|
||||
c.Enter=true
|
||||
c.Alarm=multi:newAlarm(.1)
|
||||
c.Alarm.parent=c
|
||||
c.Alarm:OnRing(function(alarm) alarm.parent.cooldown=false end)
|
||||
c.Alarm2=multi:newAlarm(.5)
|
||||
c.Alarm2.parent=c
|
||||
c.Alarm2:OnRing(function(alarm) alarm.parent.cooldown2=false end)
|
||||
function c:OnFocus(func)
|
||||
table.insert(self.funcF,func)
|
||||
end
|
||||
function c:OnEnter(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
c:OnClicked(function(b,self)
|
||||
for cc=1,#self.funcF do
|
||||
self.funcF[cc](self)
|
||||
end
|
||||
if self.Active==false then
|
||||
if self.ClearOnFocus==true then
|
||||
self.text=""
|
||||
self.ttext=""
|
||||
end
|
||||
for tb=1,#gui.TB do
|
||||
if gui.TB[tb]~=nil then
|
||||
gui.TB[tb].Active=false
|
||||
end
|
||||
end
|
||||
self.Active=true
|
||||
end
|
||||
end)
|
||||
c:OnUpdate(function(self)
|
||||
if love.keyboard.isDown("backspace") and self.Active and self.cooldown==false then
|
||||
self.text=string.sub(self.text,1,-2)
|
||||
self.ttext=string.sub(self.ttext,1,-2)
|
||||
self.cooldown=true
|
||||
c.Alarm:Reset()
|
||||
elseif love.keyboard.isDown("backspace")==false then
|
||||
self.cooldown=false
|
||||
end
|
||||
if love.keyboard.isDown("delete") and self.Active then
|
||||
self.text=string.sub(self.text,1,-2)
|
||||
self.ttext=string.sub(self.text,1,-2)
|
||||
elseif (love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) and love.keyboard.isDown("return") and self.cooldown2==false then
|
||||
self.text=self.text.."\n"
|
||||
self.ttext=self.ttext.."\n"
|
||||
self.cooldown2=true
|
||||
c.Alarm2:Reset()
|
||||
elseif (love.keyboard.isDown("return") or love.keyboard.isDown("enter") or love.keyboard.isDown("kpenter")) and self.Active and self.Enter and not(love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) then
|
||||
self.Active=false
|
||||
for cc=1,#self.funcE do
|
||||
self.funcE[cc](self,self.ttext)
|
||||
end
|
||||
end
|
||||
end)
|
||||
table.insert(gui.TB,c)
|
||||
return c
|
||||
end
|
||||
--TEXT BOX HELPER FUNCTION
|
||||
function love.textinput(t)
|
||||
for tb=1,#gui.TB do
|
||||
if gui.TB[tb]~=nil then
|
||||
if gui.TB[tb].Active then
|
||||
if gui.TB[tb].hidden then
|
||||
gui.TB[tb].text=gui.TB[tb].text.."*"
|
||||
gui.TB[tb].ttext=gui.TB[tb].ttext..t
|
||||
else
|
||||
gui.TB[tb].text=gui.TB[tb].text..t
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
22
client/GuiManager/Text/newTextButton.int
Normal file
22
client/GuiManager/Text/newTextButton.int
Normal file
@ -0,0 +1,22 @@
|
||||
function gui:newTextButton(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextButton",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
c:OnEnter(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorH)
|
||||
end)
|
||||
c:OnExit(function()
|
||||
love.mouse.setCursor(_GuiPro.CursorN)
|
||||
end)
|
||||
return c
|
||||
end
|
||||
16
client/GuiManager/Text/newTextLabel.int
Normal file
16
client/GuiManager/Text/newTextLabel.int
Normal file
@ -0,0 +1,16 @@
|
||||
function gui:newTextLabel(t,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
local c=self:newBase("TextLabel",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||
c.Tween=0
|
||||
c.XTween=0
|
||||
c.FontHeight=_defaultfont:getHeight()
|
||||
c.Font=_defaultfont
|
||||
c.FontSize=15
|
||||
c.TextFormat="center"
|
||||
c.text = t
|
||||
c.AutoScaleText=false
|
||||
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||
c.Color = {220, 220, 220}
|
||||
c.TextColor = {0, 0, 0}
|
||||
return c
|
||||
end
|
||||
57
client/GuiManager/init.lua
Normal file
57
client/GuiManager/init.lua
Normal file
@ -0,0 +1,57 @@
|
||||
_defaultfont = love.graphics.getFont()
|
||||
gui = {}
|
||||
gui.__index = gui
|
||||
gui.TB={}
|
||||
gui.Version="VERSION" -- Is it really ready for release?
|
||||
_GuiPro={GBoost=true,hasDrag=false,DragItem={},Children={},Visible=true,count=0,x=0,y=0,height=0,width=0,update=function(self) local things=GetAllChildren2(self) UpdateThings(things) end,draw=function(self) local things=GetAllChildren(self) DrawThings(things) end,getChildren=function(self) return self.Children end}
|
||||
_GuiPro.Clips={}
|
||||
_GuiPro.rotate=0
|
||||
setmetatable(_GuiPro, gui)
|
||||
function gui:LoadInterface(file)
|
||||
local add=".int"
|
||||
if string.find(file,".",1,true) then add="" end
|
||||
if love.filesystem.exists(file..add) then
|
||||
a,b=pcall(love.filesystem.load(file..add))
|
||||
if a then
|
||||
print("Loaded: "..file)
|
||||
else
|
||||
print("Error loading file: "..file)
|
||||
print(a,b)
|
||||
end
|
||||
else
|
||||
print("File does not exist!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
function gui.LoadAll(dir)
|
||||
files=love.filesystem.getDirectoryItems(dir)
|
||||
for i=1,#files do
|
||||
if string.sub(files[i],-4)==".int" then
|
||||
gui:LoadInterface(dir.."/"..files[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Start Of Load
|
||||
|
||||
--gui.LoadAll("GuiManager/LibCore")
|
||||
gui.LoadAll("GuiManager/Core")
|
||||
gui.LoadAll("GuiManager/Image-Animation")
|
||||
gui.LoadAll("GuiManager/Frame")
|
||||
gui.LoadAll("GuiManager/Item")
|
||||
gui.LoadAll("GuiManager/Misc")
|
||||
gui.LoadAll("GuiManager/Text")
|
||||
gui.LoadAll("GuiManager/Drawing")
|
||||
gui.LoadAll("GuiManager/Combos")
|
||||
--gui.LoadAll("GuiManager/WIP")
|
||||
multi.boost=2
|
||||
|
||||
-- End of Load
|
||||
gui:respectHierarchy()
|
||||
_GuiPro.width,_GuiPro.height=love.graphics.getDimensions()
|
||||
multi:newLoop():OnLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() _GuiPro:update() end)
|
||||
multi:onDraw(function() _GuiPro:draw() end)
|
||||
gui.ff=gui:newItem("",nil,"",0,0,0,0,0,0,1,1)
|
||||
gui.ff.Color={255,255,255}
|
||||
gui.ff:OnUpdate(function(self)
|
||||
self:BottomStack()
|
||||
end)
|
||||
212
client/Libs/AudioManager.lua
Normal file
212
client/Libs/AudioManager.lua
Normal file
@ -0,0 +1,212 @@
|
||||
audio = {}
|
||||
audio.__index = audio
|
||||
function audio:new(f,t)
|
||||
local obj={}
|
||||
setmetatable(obj, audio)
|
||||
obj.source=love.audio.newSource(f,t)
|
||||
obj.f=f
|
||||
obj.t=t or "stream"
|
||||
obj.endEvent=multi:newLoop()
|
||||
obj.endEvent.Pare=obj
|
||||
obj.wasPlaying=false
|
||||
obj.func={}
|
||||
obj.func2={}
|
||||
obj.func3={}
|
||||
obj.func4={}
|
||||
obj.endEvent:OnLoop(function(time,loop)
|
||||
if not(loop.Pare:isPlaying()) and loop.Pare.wasPlaying==true and not(loop.Pare:isPaused()) then
|
||||
for i=1,#loop.Pare.func do
|
||||
loop.Pare:stop()
|
||||
loop.Pare.wasPlaying=false
|
||||
loop.Pare.endEvent:Pause()
|
||||
loop.Pare.func[i](loop.Pare)
|
||||
end
|
||||
end
|
||||
end)
|
||||
obj.endEvent:Pause()
|
||||
return obj
|
||||
end
|
||||
function audio:clone()
|
||||
local _temp=audio:new(self.f,self.t)
|
||||
_temp.source=self.source:clone()
|
||||
return _temp
|
||||
end
|
||||
--Mutators
|
||||
function audio:play()
|
||||
if self:isPaused() then
|
||||
for i=1,#self.func4 do
|
||||
self.func4[i](self)
|
||||
end
|
||||
self:resume()
|
||||
else
|
||||
for i=1,#self.func3 do
|
||||
self.func3[i](self)
|
||||
end
|
||||
self.source:play()
|
||||
self.wasPlaying=true
|
||||
self.endEvent:Resume()
|
||||
end
|
||||
end
|
||||
function audio:stop()
|
||||
self.source:stop()
|
||||
self.wasPlaying=true
|
||||
self.endEvent:Pause()
|
||||
end
|
||||
function audio:pause()
|
||||
for i=1,#self.func2 do
|
||||
self.func2[i](self)
|
||||
end
|
||||
self.source:pause()
|
||||
end
|
||||
function audio:resume()
|
||||
self.source:resume()
|
||||
end
|
||||
function audio:rewind()
|
||||
self.source:rewind()
|
||||
end
|
||||
function audio:setAttenuationDistances(r,m)
|
||||
self.source:setAttenuationDistances(r,m)
|
||||
end
|
||||
function audio:setCone(innerAngle, outerAngle, outerVolume)
|
||||
self.source:setCone(innerAngle, outerAngle, outerVolume)
|
||||
end
|
||||
function audio:setDirection(x, y, z)
|
||||
self.source:setDirection(x, y, z)
|
||||
end
|
||||
function audio:setLooping(loop)
|
||||
self.source:setLooping(loop)
|
||||
end
|
||||
function audio:setPitch(pitch)
|
||||
self.source:setPitch(pitch)
|
||||
end
|
||||
function audio:setPosition(x, y, z)
|
||||
self.source:setPosition(x, y, z)
|
||||
end
|
||||
function audio:setRelative(enable)
|
||||
self.source:setRelative(enable)
|
||||
end
|
||||
function audio:setRolloff(rolloff)
|
||||
self.source:setRolloff(rolloff)
|
||||
end
|
||||
function audio:setVelocity(x, y, z)
|
||||
self.source:setVelocity(x, y, z)
|
||||
end
|
||||
function audio:setVolume(volume)
|
||||
self.source:setVolume(volume)
|
||||
end
|
||||
function audio:setVolumeLimits(min, max)
|
||||
self.source:setVolumeLimits(min, max)
|
||||
end
|
||||
function audio:seek(offset,unit)
|
||||
self.source:seek(offset,unit)
|
||||
end
|
||||
--Assessors
|
||||
function audio:isPlaying()
|
||||
return self.source:isPlaying()
|
||||
end
|
||||
function audio:isPaused()
|
||||
return self.source:isPaused()
|
||||
end
|
||||
function audio:isStopped()
|
||||
return self.source:isStopped()
|
||||
end
|
||||
function audio:isLooping()
|
||||
return self.source:isLooping()
|
||||
end
|
||||
function audio:isStatic()
|
||||
return self.source:isStatic()
|
||||
end
|
||||
function audio:isRelative()
|
||||
return self.source:isRelative()
|
||||
end
|
||||
function audio:getAttenuationDistances()
|
||||
return self.source:getAttenuationDistances()
|
||||
end
|
||||
function audio:getChannels()
|
||||
return self.source:getChannels()
|
||||
end
|
||||
function audio:getCone()
|
||||
return self.source:getCone()
|
||||
end
|
||||
function audio:getDirection()
|
||||
return self.source:getDirection()
|
||||
end
|
||||
function audio:getPitch()
|
||||
return self.source:getPitch()
|
||||
end
|
||||
function audio:getPosition()
|
||||
return self.source:getPosition()
|
||||
end
|
||||
function audio:getRolloff()
|
||||
return self.source:getRolloff()
|
||||
end
|
||||
function audio:getVelocity()
|
||||
return self.source:getVelocity()
|
||||
end
|
||||
function audio:getVolume()
|
||||
return self.source:getVolume()
|
||||
end
|
||||
function audio:getVolumeLimits()
|
||||
return self.source:getVolumeLimits()
|
||||
end
|
||||
function audio:tell(unit)
|
||||
return self.source:tell(unit)
|
||||
end
|
||||
function audio:type()
|
||||
return self.source:type()
|
||||
end
|
||||
function audio:typeOf()
|
||||
return self.source:typeOf()
|
||||
end
|
||||
--Events
|
||||
function audio:onResume(func)
|
||||
table.insert(self.func4,func)
|
||||
end
|
||||
function audio:onPlay(func)
|
||||
table.insert(self.func3,func)
|
||||
end
|
||||
function audio:onPause(func)
|
||||
table.insert(self.func2,func)
|
||||
end
|
||||
function audio:onStop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
--[[
|
||||
Object:type |Done
|
||||
Object:typeOf |Done
|
||||
Source:clone |Done
|
||||
Source:getAttenuationDistances |Done
|
||||
Source:getChannels |Done
|
||||
Source:getCone |Done
|
||||
Source:getDirection |Done
|
||||
Source:getPitch |Done
|
||||
Source:getPosition |Done
|
||||
Source:getRolloff |Done
|
||||
Source:getVelocity |Done
|
||||
Source:getVolume |Done
|
||||
Source:getVolumeLimits |Done
|
||||
Source:isLooping |Done
|
||||
Source:isPaused |Done
|
||||
Source:isPlaying |Done
|
||||
Source:isRelative |Done
|
||||
Source:isStatic |Done
|
||||
Source:isStopped |Done
|
||||
Source:pause |Done
|
||||
Source:play |Done
|
||||
Source:resume |Done
|
||||
Source:rewind |Done
|
||||
Source:seek |Done
|
||||
Source:setAttenuationDistances |Done
|
||||
Source:setCone |Done
|
||||
Source:setDirection |Done
|
||||
Source:setLooping |Done
|
||||
Source:setPitch |Done
|
||||
Source:setPosition |Done
|
||||
Source:setRelative |Done
|
||||
Source:setRolloff |Done
|
||||
Source:setVelocity |Done
|
||||
Source:setVolume |Done
|
||||
Source:setVolumeLimits |Done
|
||||
Source:stop |Done
|
||||
Source:tell |Done
|
||||
]]
|
||||
319
client/Libs/Library.lua
Normal file
319
client/Libs/Library.lua
Normal file
@ -0,0 +1,319 @@
|
||||
if table.unpack then
|
||||
unpack=table.unpack
|
||||
end
|
||||
function table.val_to_str ( v )
|
||||
if "string" == type( v ) then
|
||||
v = string.gsub( v, "\n", "\\n" )
|
||||
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
|
||||
return "'" .. v .. "'"
|
||||
end
|
||||
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
|
||||
else
|
||||
return "table" == type( v ) and table.tostring( v ) or
|
||||
tostring( v )
|
||||
end
|
||||
end
|
||||
|
||||
function table.key_to_str ( k )
|
||||
if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
|
||||
return k
|
||||
else
|
||||
return "[" .. table.val_to_str( k ) .. "]"
|
||||
end
|
||||
end
|
||||
|
||||
function table.tostring( tbl )
|
||||
local result, done = {}, {}
|
||||
for k, v in ipairs( tbl ) do
|
||||
table.insert( result, table.val_to_str( v ) )
|
||||
done[ k ] = true
|
||||
end
|
||||
for k, v in pairs( tbl ) do
|
||||
if not done[ k ] then
|
||||
table.insert( result,
|
||||
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
|
||||
end
|
||||
end
|
||||
return "{" .. table.concat( result, "," ) .. "}"
|
||||
end
|
||||
function table.merge(t1, t2)
|
||||
t1,t2= t1 or {},t2 or {}
|
||||
for k,v in pairs(t2) do
|
||||
if type(v) == "table" then
|
||||
if type(t1[k] or false) == "table" then
|
||||
table.merge(t1[k] or {}, t2[k] or {})
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
end
|
||||
Library={}
|
||||
function Library.optimize(func)
|
||||
local test=Library.convert(func)
|
||||
rawset(test,"link",{})
|
||||
rawset(test,"last","")
|
||||
rawset(test,"org",func)
|
||||
test:inject(function(...)
|
||||
rawset(test,"last",table.tostring({...}))
|
||||
if test.link[test.last]~=nil then
|
||||
return Library.forceReturn(unpack(test.link[test.last]))
|
||||
end
|
||||
return {...}
|
||||
end,1)
|
||||
test:inject(function(...)
|
||||
test.link[test.last]={test.org(...)}
|
||||
return test.org(...)
|
||||
end)
|
||||
return test
|
||||
end
|
||||
function Library.forceReturn(...)
|
||||
return {[0]="\1\7\6\3\2\99\125",...}
|
||||
end
|
||||
function Library.inject(lib,dat,arg)
|
||||
if type(lib)=="table" then
|
||||
if type(dat)=="table" then
|
||||
table.merge(lib,dat)
|
||||
elseif type(dat)=="string" then
|
||||
if lib.Version and dat:match("(%d-)%.(%d-)%.(%d-)") then
|
||||
lib.Version={dat:match("(%d+)%.(%d+)%.(%d+)")}
|
||||
elseif dat=="meta" and type(arg)=="table" then
|
||||
local _mt=getmetatable(lib) or {}
|
||||
local mt={}
|
||||
table.merge(mt,arg)
|
||||
table.merge(_mt,mt)
|
||||
setmetatable(lib,_mt)
|
||||
elseif dat=="compat" then
|
||||
lib["getVersion"]=function(self) return self.Version[1].."."..self.Version[2].."."..self.Version[3] end
|
||||
if not lib.Version then
|
||||
lib.Version={1,0,0}
|
||||
end
|
||||
elseif dat=="inhert" then
|
||||
if not(lib["!%"..arg.."%!"]) then print("Wrong Password!!") return end
|
||||
lib["!%"..arg.."%!"].__index=lib["!!%"..arg.."%!!"]
|
||||
end
|
||||
elseif type(dat)=="function" then
|
||||
for i,v in pairs(lib) do
|
||||
dat(lib,i,v)
|
||||
end
|
||||
end
|
||||
elseif type(lib)=="function" or type(lib)=="userdata" then
|
||||
if lib==unpack then
|
||||
print("function unpack cannot yet be injected!")
|
||||
return unpack
|
||||
elseif lib==pairs then
|
||||
print("function pairs cannot yet be injected!")
|
||||
return lib
|
||||
elseif lib==ipairs then
|
||||
print("function ipairs cannot yet be injected!")
|
||||
return lib
|
||||
elseif lib==type then
|
||||
print("function type cannot yet be injected!")
|
||||
return lib
|
||||
end
|
||||
temp={}
|
||||
local mt={
|
||||
__call=function(t,...)
|
||||
local consume,MainRet,init={},{},{...}
|
||||
local tt={}
|
||||
for i=1,#t.__Link do
|
||||
tt={}
|
||||
if t.__Link[i]==t.__Main then
|
||||
if #consume~=0 then
|
||||
MainRet={t.__Link[i](unpack(consume))}
|
||||
else
|
||||
MainRet={t.__Link[i](unpack(init))}
|
||||
end
|
||||
else
|
||||
if i==1 then
|
||||
consume=(t.__Link[i](unpack(init)))
|
||||
else
|
||||
if type(MainRet)=="table" then
|
||||
table.merge(tt,MainRet)
|
||||
end
|
||||
if type(consume)=="table" then
|
||||
table.merge(tt,consume)
|
||||
end
|
||||
consume={t.__Link[i](unpack(tt))}
|
||||
end
|
||||
if i==#t.__Link then
|
||||
return unpack(consume)
|
||||
end
|
||||
if consume then if consume[0]=="\1\7\6\3\2\99\125" then consume[0]=nil return unpack(consume) end end
|
||||
end
|
||||
end
|
||||
if type(MainRet)=="table" then
|
||||
table.merge(tt,MainRet)
|
||||
end
|
||||
if type(consume)=="table" then
|
||||
table.merge(tt,consume)
|
||||
end
|
||||
return unpack(tt)
|
||||
end,
|
||||
}
|
||||
temp.__Link={lib}
|
||||
temp.__Main=lib
|
||||
temp.__self=temp
|
||||
function temp:inject(func,i)
|
||||
if i then
|
||||
table.insert(self.__Link,i,func)
|
||||
else
|
||||
table.insert(self.__Link,func)
|
||||
end
|
||||
end
|
||||
function temp:consume(func)
|
||||
for i=1,#self.__Link do
|
||||
if self.__Link[i]==self.__Main then
|
||||
self.__Link[i]=func
|
||||
self.__self.__Main=func
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
setmetatable(temp,mt)
|
||||
Library.protect(temp,"lolz")
|
||||
return temp
|
||||
else
|
||||
return "arg1 must be a table or a function"
|
||||
end
|
||||
end
|
||||
function Library.parse(lib)
|
||||
for i,v in pairs(lib) do
|
||||
print(i,v)
|
||||
end
|
||||
end
|
||||
function Library.protect(lib,pass)
|
||||
pass=pass or "*"
|
||||
local mt={}
|
||||
local test={
|
||||
__index = lib,
|
||||
__newindex = function(tab, key, value)
|
||||
local t,b=key:find(tab["!%"..pass.."%!"].__pass,1,true)
|
||||
if t then
|
||||
local _k=key:sub(b+1)
|
||||
rawset(tab,_k,value)
|
||||
else
|
||||
error("Cannot alter a protected library!")
|
||||
end
|
||||
end,
|
||||
__metatable = false,
|
||||
__pass=pass or "*"
|
||||
}
|
||||
local _mt=getmetatable(lib) or {}
|
||||
table.merge(mt,_mt)
|
||||
table.merge(mt,test)
|
||||
lib["!%"..pass.."%!"]=test
|
||||
lib["!!%"..pass.."%!!"]=lib
|
||||
local temp=setmetatable({},mt)
|
||||
for i,v in pairs(_G) do
|
||||
if v==lib then
|
||||
_G[i]=temp
|
||||
Library(function(link)
|
||||
link[i]=v
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
function Library.unprotect(lib,pass)
|
||||
if not(lib["!%"..pass.."%!"]) then print("Wrong Password or Library is not Protected!") return end
|
||||
if lib["!%"..pass.."%!"].__pass==pass then
|
||||
lib["!%"..pass.."%!"].__newindex=lib["!!%"..pass.."%!!"]
|
||||
lib["!%"..pass.."%!"].__index=nil
|
||||
lib["!%"..pass.."%!"].__newindex=nil
|
||||
lib["!%"..pass.."%!"].__metatable = true
|
||||
setmetatable(lib["!!%"..pass.."%!!"],lib["!%"..pass.."%!"])
|
||||
for i,v in pairs(_G) do
|
||||
if v==lib then
|
||||
_G[i]=lib["!!%"..pass.."%!!"]
|
||||
end
|
||||
end
|
||||
lib["!!%"..pass.."%!!"]["!%"..pass.."%!"]=nil
|
||||
lib["!!%"..pass.."%!!"]["!!%"..pass.."%!!"]=nil
|
||||
else
|
||||
print("Wrong Password!!!")
|
||||
end
|
||||
end
|
||||
function Library.addPoll(lib,polldata,ref)
|
||||
lib.__polldata={}
|
||||
Library.inject(lib.__polldata,polldata)
|
||||
if type(ref)=="table" then
|
||||
Library.inject(ref,"meta",{__newindex=function(t,k,v)
|
||||
t[k].__polldata=polldata
|
||||
end})
|
||||
end
|
||||
end
|
||||
function Library.newPollData(t)
|
||||
local temp={}
|
||||
temp.__onPolled=function() end
|
||||
temp.__pollData=false
|
||||
temp.__advDisc=""
|
||||
temp.__pollcalls=-1 -- infinte
|
||||
for i,v in pairs(t) do
|
||||
if type(v)=="string" then
|
||||
temp.__advDisc=v
|
||||
elseif type(v)=="number" then
|
||||
temp.__pollcalls=v
|
||||
elseif type(v)=="table" then
|
||||
temp[v[1]]=v[2]
|
||||
elseif type(v)=="function" then
|
||||
temp.__onPolled=v
|
||||
elseif type(v)=="boolean" then
|
||||
temp.__pollData=v
|
||||
else
|
||||
temp.__userdata=v
|
||||
end
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function Library.convert(...)
|
||||
local temp,rets={...},{}
|
||||
for i=1,#temp do
|
||||
if type(temp[i])=="function" then
|
||||
table.insert(rets,Library.inject(temp[i]))
|
||||
else
|
||||
error("Takes only functions and returns in order from functions given. arg # "..i.." is not a function!!! It is a "..type(temp[i]))
|
||||
end
|
||||
end
|
||||
return unpack(rets)
|
||||
end
|
||||
function Library.convertIn(...)
|
||||
local temp,list={...},{}
|
||||
for i=1,#temp do
|
||||
if type(temp[i])=="table" then
|
||||
for k,v in pairs(temp[i]) do
|
||||
if type(v)=="function" then
|
||||
temp[i][k]=Library.inject(temp[i][k])
|
||||
end
|
||||
end
|
||||
else
|
||||
error("Takes only tables! Arg "..i.." isn't it is a "..type(temp[i]))
|
||||
end
|
||||
end
|
||||
end
|
||||
function Library.newInjectedFunction()
|
||||
return Library.convert(function(...) return unpack{...} end)
|
||||
end
|
||||
function Library.capulate(lib)
|
||||
Library.inject(lib,"meta",{
|
||||
__index=function(t,k,v)
|
||||
for i,_v in pairs(t) do
|
||||
if k:lower()==i:lower() then
|
||||
return t[i]
|
||||
end
|
||||
end
|
||||
end,
|
||||
__newindex=function(t,k,v)
|
||||
rawset(t,k:lower(),v)
|
||||
end
|
||||
})
|
||||
end
|
||||
local link={MainLibrary=Library}
|
||||
Library.inject(Library,"meta",{
|
||||
__Link=link,
|
||||
__call=function(self,func) func(link) end,
|
||||
})
|
||||
--Library.protect(Library,"N@#P!KLkk1(93320")
|
||||
1391
client/Libs/MultiManager.lua
Normal file
1391
client/Libs/MultiManager.lua
Normal file
File diff suppressed because it is too large
Load Diff
2
client/Libs/README.txt
Normal file
2
client/Libs/README.txt
Normal file
@ -0,0 +1,2 @@
|
||||
These libraries Namely the MultiManager, bin, and the Library, libraries will be documented because i plan on sharing them
|
||||
everything else will mostlikely not be documented
|
||||
598
client/Libs/T1.lua
Normal file
598
client/Libs/T1.lua
Normal file
@ -0,0 +1,598 @@
|
||||
require("love.timer")
|
||||
require("love.system")
|
||||
require("love.sound")
|
||||
require("love.physics")
|
||||
require("love.mouse")
|
||||
require("love.math")
|
||||
require("love.keyboard")
|
||||
require("love.joystick")
|
||||
require("love.image")
|
||||
require("love.font")
|
||||
require("love.filesystem")
|
||||
require("love.event")
|
||||
require("love.audio")
|
||||
require("love.graphics")
|
||||
require("love.window")
|
||||
_defaultfont = love.graphics.getFont()
|
||||
gui = {}
|
||||
function gui.getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="userdata" then
|
||||
-- do nothing
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
multi = {}
|
||||
multi.Version="4.0.0"
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
multi.Tasks={}
|
||||
multi.Tasks2={}
|
||||
multi.Garbage={}
|
||||
multi.Children={}
|
||||
multi.Paused={}
|
||||
multi.MasterId=0
|
||||
multi.Active=true
|
||||
multi.Id=-1
|
||||
multi.Type="MainInt"
|
||||
multi.Rest=0
|
||||
-- System
|
||||
os.sleep=love.timer.sleep
|
||||
function multi:newBase(ins)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then error("Can only create an object on multi or an interface obj") return false end
|
||||
local c = {}
|
||||
if self.Type=="int" then
|
||||
setmetatable(c, self.Parent)
|
||||
else
|
||||
setmetatable(c, self)
|
||||
end
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Act=function() end
|
||||
c.Parent=self
|
||||
if ins then
|
||||
table.insert(self.Mainloop,ins,c)
|
||||
else
|
||||
table.insert(self.Mainloop,c)
|
||||
end
|
||||
self.MasterId=self.MasterId+1
|
||||
return c
|
||||
end
|
||||
function multi:reboot(r)
|
||||
self.Mainloop={}
|
||||
self.Tasks={}
|
||||
self.Tasks2={}
|
||||
self.Garbage={}
|
||||
self.Children={}
|
||||
self.Paused={}
|
||||
self.MasterId=0
|
||||
self.Active=true
|
||||
self.Id=-1
|
||||
if r then
|
||||
for i,v in pairs(_G) do
|
||||
if type(i)=="table" then
|
||||
if i.Parent and i.Id and i.Act then
|
||||
i={}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:getChildren()
|
||||
return self.Mainloop
|
||||
end
|
||||
--Processor
|
||||
function multi:Do_Order()
|
||||
for _D=#self.Mainloop,1,-1 do
|
||||
if self.Mainloop[_D]~=nil then
|
||||
self.Mainloop[_D].Id=_D
|
||||
self.Mainloop[_D]:Act()
|
||||
end
|
||||
if self.Mainloop[_D].rem then
|
||||
table.remove(self.Mainloop,_D)
|
||||
end
|
||||
end
|
||||
if self.Rest>0 then
|
||||
os.sleep(self.Rest)
|
||||
end
|
||||
end
|
||||
function multi:benchMark(sec)
|
||||
local temp=self:newLoop(function(t,self)
|
||||
if os.clock()-self.init>self.sec then
|
||||
print(self.c.." steps in "..self.sec.." second(s)")
|
||||
self.tt(self.sec)
|
||||
self:Destroy()
|
||||
else
|
||||
self.c=self.c+1
|
||||
end
|
||||
end)
|
||||
function temp:OnBench(func)
|
||||
self.tt=func
|
||||
end
|
||||
self.tt=function() end
|
||||
temp.sec=sec
|
||||
temp.init=os.clock()
|
||||
temp.c=0
|
||||
return temp
|
||||
end
|
||||
function multi:newInterface()
|
||||
if not(self.Type=="MainInt") then error("Can only create an interface on the multi obj") return false end
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
c.Parent=self
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Type="int"
|
||||
c.Mainloop={}
|
||||
c.Tasks={}
|
||||
c.Tasks2={}
|
||||
c.Garbage={}
|
||||
c.Children={}
|
||||
c.Paused={}
|
||||
c.MasterId=0
|
||||
c.Active=true
|
||||
c.Id=-1
|
||||
c.Rest=0
|
||||
function c:Start()
|
||||
if self.l then
|
||||
self.l:Resume()
|
||||
else
|
||||
self.l=self.Parent:newLoop(function(dt) c:uManager(dt) end)
|
||||
end
|
||||
end
|
||||
function c:Stop()
|
||||
if self.l then
|
||||
self.l:Pause()
|
||||
end
|
||||
end
|
||||
function c:Remove()
|
||||
self:Destroy()
|
||||
self.l:Destroy()
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Helpers
|
||||
function multi:FreeMainEvent()
|
||||
self.func={}
|
||||
end
|
||||
function multi:isPaused()
|
||||
return not(self.Active)
|
||||
end
|
||||
function multi:Pause(n)
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=false
|
||||
if not(n) then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Pause()
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
else
|
||||
if not(n) then
|
||||
self.Active=false
|
||||
if self.Parent.Mainloop[self.Id]~=nil then
|
||||
table.remove(self.Parent.Mainloop,self.Id)
|
||||
table.insert(self.Parent.Paused,self)
|
||||
self.Id=#self.Parent.Paused
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Resume()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=true
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Resume()
|
||||
end
|
||||
else
|
||||
if self:isPaused() then
|
||||
self.Active=true
|
||||
for i=1,#self.Parent.Paused do
|
||||
if self.Parent.Paused[i]==self then
|
||||
table.remove(self.Parent.Paused,i)
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Mainloop,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Destroy()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Destroy()
|
||||
end
|
||||
else
|
||||
self.rem=true
|
||||
end
|
||||
end
|
||||
function multi:hold(task)
|
||||
self:Pause()
|
||||
if type(task)=="number" then
|
||||
local alarm=self:newAlarm(task)
|
||||
while alarm.Active==true do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
alarm:Destroy()
|
||||
self:Resume()
|
||||
elseif type(task)=="function" then
|
||||
local env=self.Parent:newEvent(task)
|
||||
env:OnEvent(function(envt) envt:Pause() envt:Stop() end)
|
||||
while env.Active do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
env:Destroy()
|
||||
self:Resume()
|
||||
else
|
||||
print("Error Data Type!!!")
|
||||
end
|
||||
end
|
||||
function multi:oneTime(func,...)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then
|
||||
for _k=1,#self.Parent.Tasks2 do
|
||||
if self.Parent.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
else
|
||||
for _k=1,#self.Tasks2 do
|
||||
if self.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Constructors
|
||||
function multi:newEvent(task)
|
||||
local c=self:newBase()
|
||||
c.Type="Event"
|
||||
c.Task=task or function() end
|
||||
function c:Act()
|
||||
if self.Task(self) and self.Active==true then
|
||||
self:Pause()
|
||||
for _E=1,#self.func do
|
||||
self.func[_E](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEvent(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newAlarm(set)
|
||||
local c=self:newBase()
|
||||
c.Type="Alarm"
|
||||
c.timer=os.clock()
|
||||
c.set=set or 0
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Pause()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnRing(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTask(func)
|
||||
table.insert(self.Tasks,func)
|
||||
end
|
||||
function multi:newLoop(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Loop"
|
||||
if func then
|
||||
c.func={func}
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](os.clock()-self.Parent.Start,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnLoop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newStep(start,reset,count,skip)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="Step"
|
||||
c.pos=start or 1
|
||||
c.endAt=reset or math.huge
|
||||
c.skip=skip or 0
|
||||
c.spos=0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.start=start or 1
|
||||
if start~=nil and reset~=nil then
|
||||
if start>reset then
|
||||
think=-1
|
||||
end
|
||||
end
|
||||
function c:Act()
|
||||
if self~=nil then
|
||||
if self.spos==0 then
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
self.spos=self.spos+1
|
||||
if self.spos>=self.skip then
|
||||
self.spos=0
|
||||
end
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,1,func)
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Update(start,reset,count,skip)
|
||||
self.start=start or self.start
|
||||
self.endAt=reset or self.endAt
|
||||
self.skip=skip or self.skip
|
||||
self.count=count or self.count
|
||||
self:Resume()
|
||||
end
|
||||
c:OnStep(function(p,s)
|
||||
if s.count>0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
elseif s.count<0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
function multi:newTStep(start,reset,count,set)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="TStep"
|
||||
c.start=start or 1
|
||||
local reset = reset or math.huge
|
||||
c.endAt=reset
|
||||
c.pos=start or 1
|
||||
c.skip=skip or 0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.timer=os.clock()
|
||||
c.set=set or 1
|
||||
function c:Update(start,reset,count,set)
|
||||
self.start=start or self.start
|
||||
self.pos=start
|
||||
self.endAt=reset or self.endAt
|
||||
self.set=set or self.set
|
||||
self.count=count or self.count or 1
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Reset()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
if self.endAt==self.pos then
|
||||
for fe=1,#self.funcE do
|
||||
self.funcE[fe](self)
|
||||
end
|
||||
self.pos=self.start-1
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTrigger(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Trigger"
|
||||
c.trigfunc=func or function() end
|
||||
function c:Fire(...)
|
||||
self:trigfunc(self,...)
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Managers
|
||||
function multi:mainloop()
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
self.Start=os.clock()
|
||||
while self.Active do
|
||||
self:Do_Order()
|
||||
end
|
||||
end
|
||||
function multi._tFunc(self,dt)
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
print("once!")
|
||||
if dt then
|
||||
self.pump=true
|
||||
end
|
||||
self.pumpvar=dt
|
||||
self.Start=os.clock()
|
||||
end
|
||||
function multi:uManager(dt)
|
||||
self:oneTime(self._tFunc,self,dt)
|
||||
self:Do_Order()
|
||||
end
|
||||
multi.drawF={}
|
||||
function multi:dManager()
|
||||
for ii=1,#multi.drawF do
|
||||
multi.drawF[ii]()
|
||||
end
|
||||
end
|
||||
function multi:onDraw(func)
|
||||
table.insert(self.drawF,func)
|
||||
end
|
||||
function multi:lManager()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
Thread={}
|
||||
Thread.Name="Thread 1"
|
||||
Thread.ChannelThread = love.thread.getChannel("Easy1")
|
||||
Thread.ChannelMain = love.thread.getChannel("EasyMain")
|
||||
Thread.Global = {}
|
||||
function Thread:packTable(G)
|
||||
function escapeStr(str)
|
||||
local temp=""
|
||||
for i=1,#str do
|
||||
temp=temp.."\\"..string.byte(string.sub(str,i,i))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function ToStr(t)
|
||||
local dat="{"
|
||||
for i,v in pairs(t) do
|
||||
if type(i)=="number" then
|
||||
i="["..i.."]="
|
||||
else
|
||||
i=i.."="
|
||||
end
|
||||
if type(v)=="string" then
|
||||
dat=dat..i.."\""..v.."\","
|
||||
elseif type(v)=="number" then
|
||||
dat=dat..i..v..","
|
||||
elseif type(v)=="boolean" then
|
||||
dat=dat..i..tostring(v)..","
|
||||
elseif type(v)=="table" and not(G==v) then
|
||||
dat=dat..i..ToStr(v)..","
|
||||
--elseif type(v)=="table" and G==v then
|
||||
-- dat=dat..i.."assert(loadstring(\"return self\")),"
|
||||
elseif type(v)=="function" then
|
||||
dat=dat..i.."assert(loadstring(\""..escapeStr(string.dump(v)).."\")),"
|
||||
end
|
||||
end
|
||||
return string.sub(dat,1,-2).."}"
|
||||
end
|
||||
return "return "..ToStr(G)
|
||||
end
|
||||
function Thread:Send(name,var)
|
||||
arg3="1"
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3="table"
|
||||
end
|
||||
self.ChannelMain:push({name,var,arg3})
|
||||
end
|
||||
function Thread:UnPackChannel()
|
||||
local c=self.ChannelThread:getCount()
|
||||
for i=1,c do
|
||||
local temp=self.ChannelThread:pop()
|
||||
if temp[1] and temp[2] then
|
||||
if temp[1]=="func" and type(temp[2])=="string" then
|
||||
loadstring(temp[2])(temp[3])
|
||||
elseif temp[1]=="table" then
|
||||
_G[temp[3]]=loadstring(temp[2])()
|
||||
else
|
||||
_G[temp[1]]=temp[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
if #multi:getChildren()<2 then
|
||||
os.sleep(.05)
|
||||
end
|
||||
end
|
||||
function Thread:boost(func,name)
|
||||
self:Send(name,string.dump(func))
|
||||
end
|
||||
function Thread.mainloop()
|
||||
Thread:UnPackChannel()
|
||||
end
|
||||
Thread.MainThread=false
|
||||
multi:newLoop():OnLoop(Thread.mainloop)
|
||||
multi:mainloop()
|
||||
598
client/Libs/T2.lua
Normal file
598
client/Libs/T2.lua
Normal file
@ -0,0 +1,598 @@
|
||||
require("love.timer")
|
||||
require("love.system")
|
||||
require("love.sound")
|
||||
require("love.physics")
|
||||
require("love.mouse")
|
||||
require("love.math")
|
||||
require("love.keyboard")
|
||||
require("love.joystick")
|
||||
require("love.image")
|
||||
require("love.font")
|
||||
require("love.filesystem")
|
||||
require("love.event")
|
||||
require("love.audio")
|
||||
require("love.graphics")
|
||||
require("love.window")
|
||||
_defaultfont = love.graphics.getFont()
|
||||
gui = {}
|
||||
function gui.getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="userdata" then
|
||||
-- do nothing
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
multi = {}
|
||||
multi.Version="4.0.0"
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
multi.Tasks={}
|
||||
multi.Tasks2={}
|
||||
multi.Garbage={}
|
||||
multi.Children={}
|
||||
multi.Paused={}
|
||||
multi.MasterId=0
|
||||
multi.Active=true
|
||||
multi.Id=-1
|
||||
multi.Type="MainInt"
|
||||
multi.Rest=0
|
||||
-- System
|
||||
os.sleep=love.timer.sleep
|
||||
function multi:newBase(ins)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then error("Can only create an object on multi or an interface obj") return false end
|
||||
local c = {}
|
||||
if self.Type=="int" then
|
||||
setmetatable(c, self.Parent)
|
||||
else
|
||||
setmetatable(c, self)
|
||||
end
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Act=function() end
|
||||
c.Parent=self
|
||||
if ins then
|
||||
table.insert(self.Mainloop,ins,c)
|
||||
else
|
||||
table.insert(self.Mainloop,c)
|
||||
end
|
||||
self.MasterId=self.MasterId+1
|
||||
return c
|
||||
end
|
||||
function multi:reboot(r)
|
||||
self.Mainloop={}
|
||||
self.Tasks={}
|
||||
self.Tasks2={}
|
||||
self.Garbage={}
|
||||
self.Children={}
|
||||
self.Paused={}
|
||||
self.MasterId=0
|
||||
self.Active=true
|
||||
self.Id=-1
|
||||
if r then
|
||||
for i,v in pairs(_G) do
|
||||
if type(i)=="table" then
|
||||
if i.Parent and i.Id and i.Act then
|
||||
i={}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:getChildren()
|
||||
return self.Mainloop
|
||||
end
|
||||
--Processor
|
||||
function multi:Do_Order()
|
||||
for _D=#self.Mainloop,1,-1 do
|
||||
if self.Mainloop[_D]~=nil then
|
||||
self.Mainloop[_D].Id=_D
|
||||
self.Mainloop[_D]:Act()
|
||||
end
|
||||
if self.Mainloop[_D].rem then
|
||||
table.remove(self.Mainloop,_D)
|
||||
end
|
||||
end
|
||||
if self.Rest>0 then
|
||||
os.sleep(self.Rest)
|
||||
end
|
||||
end
|
||||
function multi:benchMark(sec)
|
||||
local temp=self:newLoop(function(t,self)
|
||||
if os.clock()-self.init>self.sec then
|
||||
print(self.c.." steps in "..self.sec.." second(s)")
|
||||
self.tt(self.sec)
|
||||
self:Destroy()
|
||||
else
|
||||
self.c=self.c+1
|
||||
end
|
||||
end)
|
||||
function temp:OnBench(func)
|
||||
self.tt=func
|
||||
end
|
||||
self.tt=function() end
|
||||
temp.sec=sec
|
||||
temp.init=os.clock()
|
||||
temp.c=0
|
||||
return temp
|
||||
end
|
||||
function multi:newInterface()
|
||||
if not(self.Type=="MainInt") then error("Can only create an interface on the multi obj") return false end
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
c.Parent=self
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Type="int"
|
||||
c.Mainloop={}
|
||||
c.Tasks={}
|
||||
c.Tasks2={}
|
||||
c.Garbage={}
|
||||
c.Children={}
|
||||
c.Paused={}
|
||||
c.MasterId=0
|
||||
c.Active=true
|
||||
c.Id=-1
|
||||
c.Rest=0
|
||||
function c:Start()
|
||||
if self.l then
|
||||
self.l:Resume()
|
||||
else
|
||||
self.l=self.Parent:newLoop(function(dt) c:uManager(dt) end)
|
||||
end
|
||||
end
|
||||
function c:Stop()
|
||||
if self.l then
|
||||
self.l:Pause()
|
||||
end
|
||||
end
|
||||
function c:Remove()
|
||||
self:Destroy()
|
||||
self.l:Destroy()
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Helpers
|
||||
function multi:FreeMainEvent()
|
||||
self.func={}
|
||||
end
|
||||
function multi:isPaused()
|
||||
return not(self.Active)
|
||||
end
|
||||
function multi:Pause(n)
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=false
|
||||
if not(n) then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Pause()
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
else
|
||||
if not(n) then
|
||||
self.Active=false
|
||||
if self.Parent.Mainloop[self.Id]~=nil then
|
||||
table.remove(self.Parent.Mainloop,self.Id)
|
||||
table.insert(self.Parent.Paused,self)
|
||||
self.Id=#self.Parent.Paused
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Resume()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=true
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Resume()
|
||||
end
|
||||
else
|
||||
if self:isPaused() then
|
||||
self.Active=true
|
||||
for i=1,#self.Parent.Paused do
|
||||
if self.Parent.Paused[i]==self then
|
||||
table.remove(self.Parent.Paused,i)
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Mainloop,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Destroy()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Destroy()
|
||||
end
|
||||
else
|
||||
self.rem=true
|
||||
end
|
||||
end
|
||||
function multi:hold(task)
|
||||
self:Pause()
|
||||
if type(task)=="number" then
|
||||
local alarm=self:newAlarm(task)
|
||||
while alarm.Active==true do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
alarm:Destroy()
|
||||
self:Resume()
|
||||
elseif type(task)=="function" then
|
||||
local env=self.Parent:newEvent(task)
|
||||
env:OnEvent(function(envt) envt:Pause() envt:Stop() end)
|
||||
while env.Active do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
env:Destroy()
|
||||
self:Resume()
|
||||
else
|
||||
print("Error Data Type!!!")
|
||||
end
|
||||
end
|
||||
function multi:oneTime(func,...)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then
|
||||
for _k=1,#self.Parent.Tasks2 do
|
||||
if self.Parent.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
else
|
||||
for _k=1,#self.Tasks2 do
|
||||
if self.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Constructors
|
||||
function multi:newEvent(task)
|
||||
local c=self:newBase()
|
||||
c.Type="Event"
|
||||
c.Task=task or function() end
|
||||
function c:Act()
|
||||
if self.Task(self) and self.Active==true then
|
||||
self:Pause()
|
||||
for _E=1,#self.func do
|
||||
self.func[_E](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEvent(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newAlarm(set)
|
||||
local c=self:newBase()
|
||||
c.Type="Alarm"
|
||||
c.timer=os.clock()
|
||||
c.set=set or 0
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Pause()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnRing(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTask(func)
|
||||
table.insert(self.Tasks,func)
|
||||
end
|
||||
function multi:newLoop(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Loop"
|
||||
if func then
|
||||
c.func={func}
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](os.clock()-self.Parent.Start,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnLoop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newStep(start,reset,count,skip)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="Step"
|
||||
c.pos=start or 1
|
||||
c.endAt=reset or math.huge
|
||||
c.skip=skip or 0
|
||||
c.spos=0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.start=start or 1
|
||||
if start~=nil and reset~=nil then
|
||||
if start>reset then
|
||||
think=-1
|
||||
end
|
||||
end
|
||||
function c:Act()
|
||||
if self~=nil then
|
||||
if self.spos==0 then
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
self.spos=self.spos+1
|
||||
if self.spos>=self.skip then
|
||||
self.spos=0
|
||||
end
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,1,func)
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Update(start,reset,count,skip)
|
||||
self.start=start or self.start
|
||||
self.endAt=reset or self.endAt
|
||||
self.skip=skip or self.skip
|
||||
self.count=count or self.count
|
||||
self:Resume()
|
||||
end
|
||||
c:OnStep(function(p,s)
|
||||
if s.count>0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
elseif s.count<0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
function multi:newTStep(start,reset,count,set)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="TStep"
|
||||
c.start=start or 1
|
||||
local reset = reset or math.huge
|
||||
c.endAt=reset
|
||||
c.pos=start or 1
|
||||
c.skip=skip or 0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.timer=os.clock()
|
||||
c.set=set or 1
|
||||
function c:Update(start,reset,count,set)
|
||||
self.start=start or self.start
|
||||
self.pos=start
|
||||
self.endAt=reset or self.endAt
|
||||
self.set=set or self.set
|
||||
self.count=count or self.count or 1
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Reset()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
if self.endAt==self.pos then
|
||||
for fe=1,#self.funcE do
|
||||
self.funcE[fe](self)
|
||||
end
|
||||
self.pos=self.start-1
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTrigger(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Trigger"
|
||||
c.trigfunc=func or function() end
|
||||
function c:Fire(...)
|
||||
self:trigfunc(self,...)
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Managers
|
||||
function multi:mainloop()
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
self.Start=os.clock()
|
||||
while self.Active do
|
||||
self:Do_Order()
|
||||
end
|
||||
end
|
||||
function multi._tFunc(self,dt)
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
print("once!")
|
||||
if dt then
|
||||
self.pump=true
|
||||
end
|
||||
self.pumpvar=dt
|
||||
self.Start=os.clock()
|
||||
end
|
||||
function multi:uManager(dt)
|
||||
self:oneTime(self._tFunc,self,dt)
|
||||
self:Do_Order()
|
||||
end
|
||||
multi.drawF={}
|
||||
function multi:dManager()
|
||||
for ii=1,#multi.drawF do
|
||||
multi.drawF[ii]()
|
||||
end
|
||||
end
|
||||
function multi:onDraw(func)
|
||||
table.insert(self.drawF,func)
|
||||
end
|
||||
function multi:lManager()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
Thread={}
|
||||
Thread.Name="Thread 2"
|
||||
Thread.ChannelThread = love.thread.getChannel("Easy2")
|
||||
Thread.ChannelMain = love.thread.getChannel("EasyMain")
|
||||
Thread.Global = {}
|
||||
function Thread:packTable(G)
|
||||
function escapeStr(str)
|
||||
local temp=""
|
||||
for i=1,#str do
|
||||
temp=temp.."\\"..string.byte(string.sub(str,i,i))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function ToStr(t)
|
||||
local dat="{"
|
||||
for i,v in pairs(t) do
|
||||
if type(i)=="number" then
|
||||
i="["..i.."]="
|
||||
else
|
||||
i=i.."="
|
||||
end
|
||||
if type(v)=="string" then
|
||||
dat=dat..i.."\""..v.."\","
|
||||
elseif type(v)=="number" then
|
||||
dat=dat..i..v..","
|
||||
elseif type(v)=="boolean" then
|
||||
dat=dat..i..tostring(v)..","
|
||||
elseif type(v)=="table" and not(G==v) then
|
||||
dat=dat..i..ToStr(v)..","
|
||||
--elseif type(v)=="table" and G==v then
|
||||
-- dat=dat..i.."assert(loadstring(\"return self\")),"
|
||||
elseif type(v)=="function" then
|
||||
dat=dat..i.."assert(loadstring(\""..escapeStr(string.dump(v)).."\")),"
|
||||
end
|
||||
end
|
||||
return string.sub(dat,1,-2).."}"
|
||||
end
|
||||
return "return "..ToStr(G)
|
||||
end
|
||||
function Thread:Send(name,var)
|
||||
arg3="2"
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3="table"
|
||||
end
|
||||
self.ChannelMain:push({name,var,arg3})
|
||||
end
|
||||
function Thread:UnPackChannel()
|
||||
local c=self.ChannelThread:getCount()
|
||||
for i=1,c do
|
||||
local temp=self.ChannelThread:pop()
|
||||
if temp[1] and temp[2] then
|
||||
if temp[1]=="func" and type(temp[2])=="string" then
|
||||
loadstring(temp[2])(temp[3])
|
||||
elseif temp[1]=="table" then
|
||||
_G[temp[3]]=loadstring(temp[2])()
|
||||
else
|
||||
_G[temp[1]]=temp[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
if #multi:getChildren()<2 then
|
||||
os.sleep(.05)
|
||||
end
|
||||
end
|
||||
function Thread:boost(func,name)
|
||||
self:Send(name,string.dump(func))
|
||||
end
|
||||
function Thread.mainloop()
|
||||
Thread:UnPackChannel()
|
||||
end
|
||||
Thread.MainThread=false
|
||||
multi:newLoop():OnLoop(Thread.mainloop)
|
||||
multi:mainloop()
|
||||
596
client/Libs/T3.lua
Normal file
596
client/Libs/T3.lua
Normal file
@ -0,0 +1,596 @@
|
||||
require("love.timer")
|
||||
require("love.system")
|
||||
require("love.sound")
|
||||
require("love.physics")
|
||||
require("love.mouse")
|
||||
require("love.math")
|
||||
require("love.keyboard")
|
||||
require("love.joystick")
|
||||
require("love.image")
|
||||
require("love.font")
|
||||
require("love.filesystem")
|
||||
require("love.event")
|
||||
require("love.audio")
|
||||
require("love.graphics")
|
||||
require("love.window")
|
||||
_defaultfont = love.graphics.getFont()
|
||||
gui = {}
|
||||
function gui.getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="userdata" then
|
||||
-- do nothing
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
multi = {}
|
||||
multi.Version="4.0.0"
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
multi.Tasks={}
|
||||
multi.Tasks2={}
|
||||
multi.Garbage={}
|
||||
multi.Children={}
|
||||
multi.Paused={}
|
||||
multi.MasterId=0
|
||||
multi.Active=true
|
||||
multi.Id=-1
|
||||
multi.Type="MainInt"
|
||||
multi.Rest=0
|
||||
-- System
|
||||
os.sleep=love.timer.sleep
|
||||
function multi:newBase(ins)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then error("Can only create an object on multi or an interface obj") return false end
|
||||
local c = {}
|
||||
if self.Type=="int" then
|
||||
setmetatable(c, self.Parent)
|
||||
else
|
||||
setmetatable(c, self)
|
||||
end
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Act=function() end
|
||||
c.Parent=self
|
||||
if ins then
|
||||
table.insert(self.Mainloop,ins,c)
|
||||
else
|
||||
table.insert(self.Mainloop,c)
|
||||
end
|
||||
self.MasterId=self.MasterId+1
|
||||
return c
|
||||
end
|
||||
function multi:reboot(r)
|
||||
self.Mainloop={}
|
||||
self.Tasks={}
|
||||
self.Tasks2={}
|
||||
self.Garbage={}
|
||||
self.Children={}
|
||||
self.Paused={}
|
||||
self.MasterId=0
|
||||
self.Active=true
|
||||
self.Id=-1
|
||||
if r then
|
||||
for i,v in pairs(_G) do
|
||||
if type(i)=="table" then
|
||||
if i.Parent and i.Id and i.Act then
|
||||
i={}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:getChildren()
|
||||
return self.Mainloop
|
||||
end
|
||||
--Processor
|
||||
function multi:Do_Order()
|
||||
for _D=#self.Mainloop,1,-1 do
|
||||
if self.Mainloop[_D]~=nil then
|
||||
self.Mainloop[_D].Id=_D
|
||||
self.Mainloop[_D]:Act()
|
||||
end
|
||||
if self.Mainloop[_D].rem then
|
||||
table.remove(self.Mainloop,_D)
|
||||
end
|
||||
end
|
||||
if self.Rest>0 then
|
||||
os.sleep(self.Rest)
|
||||
end
|
||||
end
|
||||
function multi:benchMark(sec)
|
||||
local temp=self:newLoop(function(t,self)
|
||||
if os.clock()-self.init>self.sec then
|
||||
print(self.c.." steps in "..self.sec.." second(s)")
|
||||
self.tt(self.sec)
|
||||
self:Destroy()
|
||||
else
|
||||
self.c=self.c+1
|
||||
end
|
||||
end)
|
||||
function temp:OnBench(func)
|
||||
self.tt=func
|
||||
end
|
||||
self.tt=function() end
|
||||
temp.sec=sec
|
||||
temp.init=os.clock()
|
||||
temp.c=0
|
||||
return temp
|
||||
end
|
||||
function multi:newInterface()
|
||||
if not(self.Type=="MainInt") then error("Can only create an interface on the multi obj") return false end
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
c.Parent=self
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Type="int"
|
||||
c.Mainloop={}
|
||||
c.Tasks={}
|
||||
c.Tasks2={}
|
||||
c.Garbage={}
|
||||
c.Children={}
|
||||
c.Paused={}
|
||||
c.MasterId=0
|
||||
c.Active=true
|
||||
c.Id=-1
|
||||
c.Rest=0
|
||||
function c:Start()
|
||||
if self.l then
|
||||
self.l:Resume()
|
||||
else
|
||||
self.l=self.Parent:newLoop(function(dt) c:uManager(dt) end)
|
||||
end
|
||||
end
|
||||
function c:Stop()
|
||||
if self.l then
|
||||
self.l:Pause()
|
||||
end
|
||||
end
|
||||
function c:Remove()
|
||||
self:Destroy()
|
||||
self.l:Destroy()
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Helpers
|
||||
function multi:FreeMainEvent()
|
||||
self.func={}
|
||||
end
|
||||
function multi:isPaused()
|
||||
return not(self.Active)
|
||||
end
|
||||
function multi:Pause(n)
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=false
|
||||
if not(n) then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Pause()
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
else
|
||||
if not(n) then
|
||||
self.Active=false
|
||||
if self.Parent.Mainloop[self.Id]~=nil then
|
||||
table.remove(self.Parent.Mainloop,self.Id)
|
||||
table.insert(self.Parent.Paused,self)
|
||||
self.Id=#self.Parent.Paused
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Resume()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=true
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Resume()
|
||||
end
|
||||
else
|
||||
if self:isPaused() then
|
||||
self.Active=true
|
||||
for i=1,#self.Parent.Paused do
|
||||
if self.Parent.Paused[i]==self then
|
||||
table.remove(self.Parent.Paused,i)
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Mainloop,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Destroy()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Destroy()
|
||||
end
|
||||
else
|
||||
self.rem=true
|
||||
end
|
||||
end
|
||||
function multi:hold(task)
|
||||
self:Pause()
|
||||
if type(task)=="number" then
|
||||
local alarm=self:newAlarm(task)
|
||||
while alarm.Active==true do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
alarm:Destroy()
|
||||
self:Resume()
|
||||
elseif type(task)=="function" then
|
||||
local env=self.Parent:newEvent(task)
|
||||
env:OnEvent(function(envt) envt:Pause() envt:Stop() end)
|
||||
while env.Active do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
env:Destroy()
|
||||
self:Resume()
|
||||
else
|
||||
print("Error Data Type!!!")
|
||||
end
|
||||
end
|
||||
function multi:oneTime(func,...)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then
|
||||
for _k=1,#self.Parent.Tasks2 do
|
||||
if self.Parent.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
else
|
||||
for _k=1,#self.Tasks2 do
|
||||
if self.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Constructors
|
||||
function multi:newEvent(task)
|
||||
local c=self:newBase()
|
||||
c.Type="Event"
|
||||
c.Task=task or function() end
|
||||
function c:Act()
|
||||
if self.Task(self) and self.Active==true then
|
||||
self:Pause()
|
||||
for _E=1,#self.func do
|
||||
self.func[_E](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEvent(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newAlarm(set)
|
||||
local c=self:newBase()
|
||||
c.Type="Alarm"
|
||||
c.timer=os.clock()
|
||||
c.set=set or 0
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Pause()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnRing(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTask(func)
|
||||
table.insert(self.Tasks,func)
|
||||
end
|
||||
function multi:newLoop(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Loop"
|
||||
if func then
|
||||
c.func={func}
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](os.clock()-self.Parent.Start,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnLoop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newStep(start,reset,count,skip)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="Step"
|
||||
c.pos=start or 1
|
||||
c.endAt=reset or math.huge
|
||||
c.skip=skip or 0
|
||||
c.spos=0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.start=start or 1
|
||||
if start~=nil and reset~=nil then
|
||||
if start>reset then
|
||||
think=-1
|
||||
end
|
||||
end
|
||||
function c:Act()
|
||||
if self~=nil then
|
||||
if self.spos==0 then
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
self.spos=self.spos+1
|
||||
if self.spos>=self.skip then
|
||||
self.spos=0
|
||||
end
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,1,func)
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Update(start,reset,count,skip)
|
||||
self.start=start or self.start
|
||||
self.endAt=reset or self.endAt
|
||||
self.skip=skip or self.skip
|
||||
self.count=count or self.count
|
||||
self:Resume()
|
||||
end
|
||||
c:OnStep(function(p,s)
|
||||
if s.count>0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
elseif s.count<0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
function multi:newTStep(start,reset,count,set)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="TStep"
|
||||
c.start=start or 1
|
||||
local reset = reset or math.huge
|
||||
c.endAt=reset
|
||||
c.pos=start or 1
|
||||
c.skip=skip or 0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.timer=os.clock()
|
||||
c.set=set or 1
|
||||
function c:Update(start,reset,count,set)
|
||||
self.start=start or self.start
|
||||
self.pos=start
|
||||
self.endAt=reset or self.endAt
|
||||
self.set=set or self.set
|
||||
self.count=count or self.count or 1
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Reset()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
if self.endAt==self.pos then
|
||||
for fe=1,#self.funcE do
|
||||
self.funcE[fe](self)
|
||||
end
|
||||
self.pos=self.start-1
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTrigger(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Trigger"
|
||||
c.trigfunc=func or function() end
|
||||
function c:Fire(...)
|
||||
self:trigfunc(self,...)
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Managers
|
||||
function multi:mainloop()
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
self.Start=os.clock()
|
||||
while self.Active do
|
||||
self:Do_Order()
|
||||
end
|
||||
end
|
||||
function multi._tFunc(self,dt)
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
print("once!")
|
||||
if dt then
|
||||
self.pump=true
|
||||
end
|
||||
self.pumpvar=dt
|
||||
self.Start=os.clock()
|
||||
end
|
||||
function multi:uManager(dt)
|
||||
self:oneTime(self._tFunc,self,dt)
|
||||
self:Do_Order()
|
||||
end
|
||||
multi.drawF={}
|
||||
function multi:dManager()
|
||||
for ii=1,#multi.drawF do
|
||||
multi.drawF[ii]()
|
||||
end
|
||||
end
|
||||
function multi:onDraw(func)
|
||||
table.insert(self.drawF,func)
|
||||
end
|
||||
function multi:lManager()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
Thread={}
|
||||
Thread.Name="Thread 3"
|
||||
Thread.ChannelThread = love.thread.getChannel("Easy3")
|
||||
Thread.ChannelMain = love.thread.getChannel("EasyMain")
|
||||
Thread.Global = {}
|
||||
function Thread:packTable(G)
|
||||
function escapeStr(str)
|
||||
local temp=""
|
||||
for i=1,#str do
|
||||
temp=temp.."\\"..string.byte(string.sub(str,i,i))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function ToStr(t)
|
||||
local dat="{"
|
||||
for i,v in pairs(t) do
|
||||
if type(i)=="number" then
|
||||
i="["..i.."]="
|
||||
else
|
||||
i=i.."="
|
||||
end
|
||||
if type(v)=="string" then
|
||||
dat=dat..i.."\""..v.."\","
|
||||
elseif type(v)=="number" then
|
||||
dat=dat..i..v..","
|
||||
elseif type(v)=="boolean" then
|
||||
dat=dat..i..tostring(v)..","
|
||||
elseif type(v)=="table" and not(G==v) then
|
||||
dat=dat..i..ToStr(v)..","
|
||||
--elseif type(v)=="table" and G==v then
|
||||
-- dat=dat..i.."assert(loadstring(\"return self\")),"
|
||||
elseif type(v)=="function" then
|
||||
dat=dat..i.."assert(loadstring(\""..escapeStr(string.dump(v)).."\")),"
|
||||
end
|
||||
end
|
||||
return string.sub(dat,1,-2).."}"
|
||||
end
|
||||
return "return "..ToStr(G)
|
||||
end
|
||||
function Thread:Send(name,var)
|
||||
arg3="3"
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3="table"
|
||||
end
|
||||
self.ChannelMain:push({name,var,arg3})
|
||||
end
|
||||
function Thread:UnPackChannel()
|
||||
local c=self.ChannelThread:getCount()
|
||||
for i=1,c do
|
||||
local temp=self.ChannelThread:pop()
|
||||
if temp[1] and temp[2] then
|
||||
if temp[1]=="func" and type(temp[2])=="string" then
|
||||
loadstring(temp[2])(temp[3])
|
||||
else
|
||||
_G[temp[1]]=temp[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
if #multi:getChildren()<2 then
|
||||
os.sleep(.05)
|
||||
end
|
||||
end
|
||||
function Thread:boost(func,name)
|
||||
self:Send(name,string.dump(func))
|
||||
end
|
||||
function Thread.mainloop()
|
||||
Thread:UnPackChannel()
|
||||
end
|
||||
Thread.MainThread=false
|
||||
multi:newLoop():OnLoop(Thread.mainloop)
|
||||
multi:mainloop()
|
||||
596
client/Libs/T4.lua
Normal file
596
client/Libs/T4.lua
Normal file
@ -0,0 +1,596 @@
|
||||
require("love.timer")
|
||||
require("love.system")
|
||||
require("love.sound")
|
||||
require("love.physics")
|
||||
require("love.mouse")
|
||||
require("love.math")
|
||||
require("love.keyboard")
|
||||
require("love.joystick")
|
||||
require("love.image")
|
||||
require("love.font")
|
||||
require("love.filesystem")
|
||||
require("love.event")
|
||||
require("love.audio")
|
||||
require("love.graphics")
|
||||
require("love.window")
|
||||
_defaultfont = love.graphics.getFont()
|
||||
gui = {}
|
||||
function gui.getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="userdata" then
|
||||
-- do nothing
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
multi = {}
|
||||
multi.Version="4.0.0"
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
multi.Tasks={}
|
||||
multi.Tasks2={}
|
||||
multi.Garbage={}
|
||||
multi.Children={}
|
||||
multi.Paused={}
|
||||
multi.MasterId=0
|
||||
multi.Active=true
|
||||
multi.Id=-1
|
||||
multi.Type="MainInt"
|
||||
multi.Rest=0
|
||||
-- System
|
||||
os.sleep=love.timer.sleep
|
||||
function multi:newBase(ins)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then error("Can only create an object on multi or an interface obj") return false end
|
||||
local c = {}
|
||||
if self.Type=="int" then
|
||||
setmetatable(c, self.Parent)
|
||||
else
|
||||
setmetatable(c, self)
|
||||
end
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Act=function() end
|
||||
c.Parent=self
|
||||
if ins then
|
||||
table.insert(self.Mainloop,ins,c)
|
||||
else
|
||||
table.insert(self.Mainloop,c)
|
||||
end
|
||||
self.MasterId=self.MasterId+1
|
||||
return c
|
||||
end
|
||||
function multi:reboot(r)
|
||||
self.Mainloop={}
|
||||
self.Tasks={}
|
||||
self.Tasks2={}
|
||||
self.Garbage={}
|
||||
self.Children={}
|
||||
self.Paused={}
|
||||
self.MasterId=0
|
||||
self.Active=true
|
||||
self.Id=-1
|
||||
if r then
|
||||
for i,v in pairs(_G) do
|
||||
if type(i)=="table" then
|
||||
if i.Parent and i.Id and i.Act then
|
||||
i={}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:getChildren()
|
||||
return self.Mainloop
|
||||
end
|
||||
--Processor
|
||||
function multi:Do_Order()
|
||||
for _D=#self.Mainloop,1,-1 do
|
||||
if self.Mainloop[_D]~=nil then
|
||||
self.Mainloop[_D].Id=_D
|
||||
self.Mainloop[_D]:Act()
|
||||
end
|
||||
if self.Mainloop[_D].rem then
|
||||
table.remove(self.Mainloop,_D)
|
||||
end
|
||||
end
|
||||
if self.Rest>0 then
|
||||
os.sleep(self.Rest)
|
||||
end
|
||||
end
|
||||
function multi:benchMark(sec)
|
||||
local temp=self:newLoop(function(t,self)
|
||||
if os.clock()-self.init>self.sec then
|
||||
print(self.c.." steps in "..self.sec.." second(s)")
|
||||
self.tt(self.sec)
|
||||
self:Destroy()
|
||||
else
|
||||
self.c=self.c+1
|
||||
end
|
||||
end)
|
||||
function temp:OnBench(func)
|
||||
self.tt=func
|
||||
end
|
||||
self.tt=function() end
|
||||
temp.sec=sec
|
||||
temp.init=os.clock()
|
||||
temp.c=0
|
||||
return temp
|
||||
end
|
||||
function multi:newInterface()
|
||||
if not(self.Type=="MainInt") then error("Can only create an interface on the multi obj") return false end
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
c.Parent=self
|
||||
c.Active=true
|
||||
c.func={}
|
||||
c.Id=0
|
||||
c.Type="int"
|
||||
c.Mainloop={}
|
||||
c.Tasks={}
|
||||
c.Tasks2={}
|
||||
c.Garbage={}
|
||||
c.Children={}
|
||||
c.Paused={}
|
||||
c.MasterId=0
|
||||
c.Active=true
|
||||
c.Id=-1
|
||||
c.Rest=0
|
||||
function c:Start()
|
||||
if self.l then
|
||||
self.l:Resume()
|
||||
else
|
||||
self.l=self.Parent:newLoop(function(dt) c:uManager(dt) end)
|
||||
end
|
||||
end
|
||||
function c:Stop()
|
||||
if self.l then
|
||||
self.l:Pause()
|
||||
end
|
||||
end
|
||||
function c:Remove()
|
||||
self:Destroy()
|
||||
self.l:Destroy()
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Helpers
|
||||
function multi:FreeMainEvent()
|
||||
self.func={}
|
||||
end
|
||||
function multi:isPaused()
|
||||
return not(self.Active)
|
||||
end
|
||||
function multi:Pause(n)
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=false
|
||||
if not(n) then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Pause()
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
else
|
||||
if not(n) then
|
||||
self.Active=false
|
||||
if self.Parent.Mainloop[self.Id]~=nil then
|
||||
table.remove(self.Parent.Mainloop,self.Id)
|
||||
table.insert(self.Parent.Paused,self)
|
||||
self.Id=#self.Parent.Paused
|
||||
end
|
||||
else
|
||||
self:hold(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Resume()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
self.Active=true
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Resume()
|
||||
end
|
||||
else
|
||||
if self:isPaused() then
|
||||
self.Active=true
|
||||
for i=1,#self.Parent.Paused do
|
||||
if self.Parent.Paused[i]==self then
|
||||
table.remove(self.Parent.Paused,i)
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Mainloop,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:Destroy()
|
||||
if self.Type=="int" or self.Type=="MainInt" then
|
||||
local c=self:getChildren()
|
||||
for i=1,#c do
|
||||
c[i]:Destroy()
|
||||
end
|
||||
else
|
||||
self.rem=true
|
||||
end
|
||||
end
|
||||
function multi:hold(task)
|
||||
self:Pause()
|
||||
if type(task)=="number" then
|
||||
local alarm=self:newAlarm(task)
|
||||
while alarm.Active==true do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
alarm:Destroy()
|
||||
self:Resume()
|
||||
elseif type(task)=="function" then
|
||||
local env=self.Parent:newEvent(task)
|
||||
env:OnEvent(function(envt) envt:Pause() envt:Stop() end)
|
||||
while env.Active do
|
||||
if love then
|
||||
self.Parent.lManager()
|
||||
else
|
||||
self.Parent.Do_Order()
|
||||
end
|
||||
end
|
||||
env:Destroy()
|
||||
self:Resume()
|
||||
else
|
||||
print("Error Data Type!!!")
|
||||
end
|
||||
end
|
||||
function multi:oneTime(func,...)
|
||||
if not(self.Type=="MainInt" or self.Type=="int") then
|
||||
for _k=1,#self.Parent.Tasks2 do
|
||||
if self.Parent.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Parent.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
else
|
||||
for _k=1,#self.Tasks2 do
|
||||
if self.Tasks2[_k]==func then
|
||||
return false
|
||||
end
|
||||
end
|
||||
table.insert(self.Tasks2,func)
|
||||
func(...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Constructors
|
||||
function multi:newEvent(task)
|
||||
local c=self:newBase()
|
||||
c.Type="Event"
|
||||
c.Task=task or function() end
|
||||
function c:Act()
|
||||
if self.Task(self) and self.Active==true then
|
||||
self:Pause()
|
||||
for _E=1,#self.func do
|
||||
self.func[_E](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEvent(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newAlarm(set)
|
||||
local c=self:newBase()
|
||||
c.Type="Alarm"
|
||||
c.timer=os.clock()
|
||||
c.set=set or 0
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Pause()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnRing(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTask(func)
|
||||
table.insert(self.Tasks,func)
|
||||
end
|
||||
function multi:newLoop(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Loop"
|
||||
if func then
|
||||
c.func={func}
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](os.clock()-self.Parent.Start,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnLoop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newStep(start,reset,count,skip)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="Step"
|
||||
c.pos=start or 1
|
||||
c.endAt=reset or math.huge
|
||||
c.skip=skip or 0
|
||||
c.spos=0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.start=start or 1
|
||||
if start~=nil and reset~=nil then
|
||||
if start>reset then
|
||||
think=-1
|
||||
end
|
||||
end
|
||||
function c:Act()
|
||||
if self~=nil then
|
||||
if self.spos==0 then
|
||||
if self.Active==true then
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
self.spos=self.spos+1
|
||||
if self.spos>=self.skip then
|
||||
self.spos=0
|
||||
end
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,1,func)
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Update(start,reset,count,skip)
|
||||
self.start=start or self.start
|
||||
self.endAt=reset or self.endAt
|
||||
self.skip=skip or self.skip
|
||||
self.count=count or self.count
|
||||
self:Resume()
|
||||
end
|
||||
c:OnStep(function(p,s)
|
||||
if s.count>0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
elseif s.count<0 and s.endAt==p then
|
||||
for fe=1,#s.funcE do
|
||||
s.funcE[fe](s)
|
||||
end
|
||||
s.pos=s.start-1
|
||||
end
|
||||
end)
|
||||
return c
|
||||
end
|
||||
function multi:newTStep(start,reset,count,set)
|
||||
local c=self:newBase()
|
||||
think=1
|
||||
c.Type="TStep"
|
||||
c.start=start or 1
|
||||
local reset = reset or math.huge
|
||||
c.endAt=reset
|
||||
c.pos=start or 1
|
||||
c.skip=skip or 0
|
||||
c.count=count or 1*think
|
||||
c.funcE={}
|
||||
c.timer=os.clock()
|
||||
c.set=set or 1
|
||||
function c:Update(start,reset,count,set)
|
||||
self.start=start or self.start
|
||||
self.pos=start
|
||||
self.endAt=reset or self.endAt
|
||||
self.set=set or self.set
|
||||
self.count=count or self.count or 1
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:Act()
|
||||
if self.Active then
|
||||
if os.clock()-self.timer>=self.set then
|
||||
self:Reset()
|
||||
for i=1,#self.func do
|
||||
self.func[i](self.pos,self)
|
||||
end
|
||||
if self.endAt==self.pos then
|
||||
for fe=1,#self.funcE do
|
||||
self.funcE[fe](self)
|
||||
end
|
||||
self.pos=self.start-1
|
||||
end
|
||||
self.pos=self.pos+self.count
|
||||
end
|
||||
end
|
||||
end
|
||||
function c:OnEnd(func)
|
||||
table.insert(self.funcE,func)
|
||||
end
|
||||
function c:Reset(n)
|
||||
if n then self.set=n end
|
||||
self.timer=os.clock()
|
||||
self:Resume()
|
||||
end
|
||||
function c:OnStep(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
return c
|
||||
end
|
||||
function multi:newTrigger(func)
|
||||
local c=self:newBase()
|
||||
c.Type="Trigger"
|
||||
c.trigfunc=func or function() end
|
||||
function c:Fire(...)
|
||||
self:trigfunc(self,...)
|
||||
end
|
||||
return c
|
||||
end
|
||||
--Managers
|
||||
function multi:mainloop()
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
self.Start=os.clock()
|
||||
while self.Active do
|
||||
self:Do_Order()
|
||||
end
|
||||
end
|
||||
function multi._tFunc(self,dt)
|
||||
for i=1,#self.Tasks do
|
||||
self.Tasks[i](self)
|
||||
end
|
||||
print("once!")
|
||||
if dt then
|
||||
self.pump=true
|
||||
end
|
||||
self.pumpvar=dt
|
||||
self.Start=os.clock()
|
||||
end
|
||||
function multi:uManager(dt)
|
||||
self:oneTime(self._tFunc,self,dt)
|
||||
self:Do_Order()
|
||||
end
|
||||
multi.drawF={}
|
||||
function multi:dManager()
|
||||
for ii=1,#multi.drawF do
|
||||
multi.drawF[ii]()
|
||||
end
|
||||
end
|
||||
function multi:onDraw(func)
|
||||
table.insert(self.drawF,func)
|
||||
end
|
||||
function multi:lManager()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
Thread={}
|
||||
Thread.Name="Thread 4"
|
||||
Thread.ChannelThread = love.thread.getChannel("Easy4")
|
||||
Thread.ChannelMain = love.thread.getChannel("EasyMain")
|
||||
Thread.Global = {}
|
||||
function Thread:packTable(G)
|
||||
function escapeStr(str)
|
||||
local temp=""
|
||||
for i=1,#str do
|
||||
temp=temp.."\\"..string.byte(string.sub(str,i,i))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function ToStr(t)
|
||||
local dat="{"
|
||||
for i,v in pairs(t) do
|
||||
if type(i)=="number" then
|
||||
i="["..i.."]="
|
||||
else
|
||||
i=i.."="
|
||||
end
|
||||
if type(v)=="string" then
|
||||
dat=dat..i.."\""..v.."\","
|
||||
elseif type(v)=="number" then
|
||||
dat=dat..i..v..","
|
||||
elseif type(v)=="boolean" then
|
||||
dat=dat..i..tostring(v)..","
|
||||
elseif type(v)=="table" and not(G==v) then
|
||||
dat=dat..i..ToStr(v)..","
|
||||
--elseif type(v)=="table" and G==v then
|
||||
-- dat=dat..i.."assert(loadstring(\"return self\")),"
|
||||
elseif type(v)=="function" then
|
||||
dat=dat..i.."assert(loadstring(\""..escapeStr(string.dump(v)).."\")),"
|
||||
end
|
||||
end
|
||||
return string.sub(dat,1,-2).."}"
|
||||
end
|
||||
return "return "..ToStr(G)
|
||||
end
|
||||
function Thread:Send(name,var)
|
||||
arg3="4"
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3="table"
|
||||
end
|
||||
self.ChannelMain:push({name,var,arg3})
|
||||
end
|
||||
function Thread:UnPackChannel()
|
||||
local c=self.ChannelThread:getCount()
|
||||
for i=1,c do
|
||||
local temp=self.ChannelThread:pop()
|
||||
if temp[1] and temp[2] then
|
||||
if temp[1]=="func" and type(temp[2])=="string" then
|
||||
loadstring(temp[2])(temp[3])
|
||||
else
|
||||
_G[temp[1]]=temp[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
if #multi:getChildren()<2 then
|
||||
os.sleep(.05)
|
||||
end
|
||||
end
|
||||
function Thread:boost(func,name)
|
||||
self:Send(name,string.dump(func))
|
||||
end
|
||||
function Thread.mainloop()
|
||||
Thread:UnPackChannel()
|
||||
end
|
||||
Thread.MainThread=false
|
||||
multi:newLoop():OnLoop(Thread.mainloop)
|
||||
multi:mainloop()
|
||||
158
client/Libs/ThreadManager.lua
Normal file
158
client/Libs/ThreadManager.lua
Normal file
@ -0,0 +1,158 @@
|
||||
Thread={}
|
||||
Thread.ChannelT1 = love.thread.getChannel("Easy1")
|
||||
Thread.ChannelT2 = love.thread.getChannel("Easy2")
|
||||
Thread.ChannelT3 = love.thread.getChannel("Easy3")
|
||||
Thread.ChannelT4 = love.thread.getChannel("Easy4")
|
||||
Thread.ChannelMain = love.thread.getChannel("EasyMain")
|
||||
Thread.Name = "Thread Main"
|
||||
Thread.n=0
|
||||
Thread.count=1
|
||||
function Thread:packTable(G)
|
||||
function escapeStr(str)
|
||||
local temp=""
|
||||
for i=1,#str do
|
||||
temp=temp.."\\"..string.byte(string.sub(str,i,i))
|
||||
end
|
||||
return temp
|
||||
end
|
||||
function ToStr(t)
|
||||
local dat="{"
|
||||
for i,v in pairs(t) do
|
||||
if type(i)=="number" then
|
||||
i="["..i.."]="
|
||||
else
|
||||
i=i.."="
|
||||
end
|
||||
if type(v)=="string" then
|
||||
dat=dat..i.."\""..v.."\","
|
||||
elseif type(v)=="number" then
|
||||
dat=dat..i..v..","
|
||||
elseif type(v)=="boolean" then
|
||||
dat=dat..i..tostring(v)..","
|
||||
elseif type(v)=="table" and not(G==v) then
|
||||
dat=dat..i..bin.ToStr(v)..","
|
||||
--elseif type(v)=="table" and G==v then
|
||||
-- dat=dat..i.."assert(loadstring(\"return self\")),"
|
||||
elseif type(v)=="function" then
|
||||
dat=dat..i.."assert(loadstring(\""..escapeStr(string.dump(v)).."\")),"
|
||||
end
|
||||
end
|
||||
return string.sub(dat,1,-2).."}"
|
||||
end
|
||||
return ToStr(G)
|
||||
end
|
||||
Thread.last={}
|
||||
function Thread:GetStatus()
|
||||
print(self.n.." Threads Exist!!!")
|
||||
for i=1,self.n do
|
||||
print("\tThread "..i.." Running: "..tostring(self["Thread"..i]:isRunning()))
|
||||
if not(self["Thread"..i]:isRunning()) then
|
||||
print("\t\t"..self["Thread"..i]:getError())
|
||||
end
|
||||
end
|
||||
end
|
||||
function Thread:Start(n)
|
||||
local x=love.system.getProcessorCount()
|
||||
if x>1 then
|
||||
x=x-1
|
||||
else
|
||||
x=1
|
||||
end
|
||||
n=n or x
|
||||
if n<1 then
|
||||
print("Must be atleast 1 thread running!!!")
|
||||
return
|
||||
end
|
||||
if n>4 then
|
||||
print("Must be no more than 4 threads running!!!")
|
||||
return
|
||||
end
|
||||
for i=1,n do
|
||||
self["Thread"..i]=love.thread.newThread("Libs/T"..i..".lua")
|
||||
self["Thread"..i]:start()
|
||||
end
|
||||
Thread.n=n
|
||||
end
|
||||
function Thread:RestartBroken()
|
||||
for i=1,self.n do
|
||||
if self["Thread"..i]:isRunning()==false then
|
||||
self["Thread"..i]:start()
|
||||
end
|
||||
Thread:Boost(Thread.last[1],Thread.last[2])
|
||||
end
|
||||
end
|
||||
function Thread:Send(name,var,arg3)
|
||||
if self.n>0 then
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3=name
|
||||
name="table"
|
||||
end
|
||||
self["ChannelT"..((self.count-1)%self.n)+1]:push({name,var,arg3})
|
||||
self.count=self.count+1
|
||||
end
|
||||
end
|
||||
function Thread:SendAll(name,var,arg3)
|
||||
if self.n>0 then
|
||||
for i=1,self.n do
|
||||
if type(var)=="table" then
|
||||
var=Thread:packTable(var)
|
||||
arg3=name
|
||||
name="table"
|
||||
end
|
||||
self["ChannelT"..i]:push({name,var,arg3})
|
||||
end
|
||||
end
|
||||
end
|
||||
function Thread:UnPackChannel()
|
||||
local c=self.ChannelMain:getCount()
|
||||
for i=1,c do
|
||||
local temp=self.ChannelMain:pop()
|
||||
if temp[3]=="table" then
|
||||
_G[temp[1]]=assert(loadstring(temp[2]))()
|
||||
else
|
||||
if Thread.OnDataRecieved then
|
||||
Thread.OnDataRecieved(temp[1],temp[2],temp[3])
|
||||
end
|
||||
_G[temp[1]]=temp[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
function Thread:Boost(func,name)
|
||||
if Thread.last[1]==nil then
|
||||
return
|
||||
end
|
||||
Thread.last={func,name}
|
||||
name=name or "nil"
|
||||
if self.n>0 then
|
||||
self:Send("func",string.dump(func),name)
|
||||
end
|
||||
end
|
||||
function Thread:SendLibs(func,name)
|
||||
name=name or "nil"
|
||||
if self.n>0 then
|
||||
self:SendAll("func",string.dump(func),name)
|
||||
end
|
||||
end
|
||||
function Thread.mainloop()
|
||||
if Thread.n>0 then
|
||||
Thread:UnPackChannel()
|
||||
end
|
||||
end
|
||||
Thread.MainThread=true
|
||||
local loop = multi:newLoop()
|
||||
loop:OnLoop(Thread.mainloop)
|
||||
OnThreadError=multi:newConnection()
|
||||
function love.threaderror(thread, errorstr)
|
||||
Thread:GetStatus()
|
||||
Thread:RestartBroken()
|
||||
Thread:GetStatus()
|
||||
OnThreadError:Fire(thread,errorstr)
|
||||
end
|
||||
multi:newTask(function()
|
||||
math.randomseed(math.floor(os.time()/2))
|
||||
for i=1,Thread.n do
|
||||
Thread["ChannelT"..i]:push({"randseed",math.random(-1000000,1000000)})
|
||||
Thread["ChannelT"..i]:push({"func",string.dump(function() math.randomseed(randseed) end),"randomizing"})
|
||||
end
|
||||
end)
|
||||
2675
client/Libs/bin.lua
Normal file
2675
client/Libs/bin.lua
Normal file
File diff suppressed because it is too large
Load Diff
103
client/Libs/lovebind.lua
Normal file
103
client/Libs/lovebind.lua
Normal file
@ -0,0 +1,103 @@
|
||||
os.sleep=love.timer.sleep
|
||||
function bin.load(file,s,r)
|
||||
content, size = love.filesystem.read(file)
|
||||
local temp=bin.new(content)
|
||||
temp.filepath=file
|
||||
return temp
|
||||
end
|
||||
function bin:tofile(filename)
|
||||
if not(filename) or self.Stream then return nil end
|
||||
love.filesystem.write(filename,self.data)
|
||||
end
|
||||
function bin.stream(file,l)
|
||||
error("Sorry streaming is not available when using love2d :(, I am looking for a solution though :)")
|
||||
end
|
||||
function love.run()
|
||||
if love.math then
|
||||
love.math.setRandomSeed(os.time())
|
||||
end
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
end
|
||||
if love.load then love.load(arg) end
|
||||
if love.timer then love.timer.step() end
|
||||
local dt = 0
|
||||
while true do
|
||||
-- Process events.
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
if multi.boost then
|
||||
for i=1,multi.boost-1 do
|
||||
multi:uManager(dt)
|
||||
end
|
||||
end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
end
|
||||
multi.drawF={}
|
||||
function multi:dManager()
|
||||
for ii=1,#multi.drawF do
|
||||
multi.drawF[ii]()
|
||||
end
|
||||
end
|
||||
function multi:onDraw(func,i)
|
||||
i=i or 1
|
||||
table.insert(self.drawF,i,func)
|
||||
end
|
||||
function multi:lManager()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for e,a,b,c,d in love.event.poll() do
|
||||
if e == "quit" then
|
||||
if not love.quit or not love.quit() then
|
||||
if love.audio then
|
||||
love.audio.stop()
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
love.handlers[e](a,b,c,d)
|
||||
end
|
||||
end
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
if love.update then love.update(dt) end
|
||||
multi:uManager(dt)
|
||||
if love.window and love.graphics and love.window.isCreated() then
|
||||
love.graphics.clear()
|
||||
love.graphics.origin()
|
||||
if love.draw then love.draw() end
|
||||
multi.dManager()
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if multi.draw then multi.draw() end
|
||||
love.graphics.present()
|
||||
end
|
||||
end
|
||||
BIN
client/Libs/test.dat
Normal file
BIN
client/Libs/test.dat
Normal file
Binary file not shown.
18
client/Libs/test.lua
Normal file
18
client/Libs/test.lua
Normal file
@ -0,0 +1,18 @@
|
||||
require("Library")
|
||||
local clock = os.clock
|
||||
function sleep(n) -- seconds
|
||||
local t0 = clock()
|
||||
while clock() - t0 <= n do end
|
||||
end
|
||||
function tester(test)
|
||||
sleep(1)
|
||||
return test*10
|
||||
end
|
||||
--~ require("bin")
|
||||
--~ test=bin.namedBlockManager()
|
||||
--~ test["name"]="Ryan"
|
||||
--~ test["age"]=21
|
||||
--~ test:tofile("test.dat")
|
||||
--~ test2=bin.namedBlockManager("test.dat")
|
||||
--~ print(test2["name"])
|
||||
--~ print(test2["age"])
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user