Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do
- local camera2D = AK.Cam2D
- camera2D.__index = camera2D
- local CSSCut = {
- ["text"] = function(object,value)
- if object.textRenderer ~= nil then
- object.textRenderer:SetText( value )
- else
- local child = object:GetChildren()
- if #child == 1 then
- local child_object = child[1]
- if child_object.textRenderer ~= nil then
- child_object.textRenderer:SetText( value )
- end
- end
- end
- end,
- ["font"] = function(object,value)
- if object.textRenderer ~= nil then
- object.textRenderer:SetFont( CS.FindAsset( value ) )
- else
- local child = object:GetChildren()
- if #child == 1 then
- local child_object = child[1]
- if child_object.textRenderer ~= nil then
- child_object.textRenderer:SetFont( CS.FindAsset( value ) )
- end
- end
- end
- end,
- ["align"] = function(object,value)
- local var
- if value == "left" then
- var = TextRenderer.Alignment.Left
- elseif value == "right" then
- var = TextRenderer.Alignment.Right
- else
- var = TextRenderer.Alignment.Center
- end
- if object.textRenderer ~= nil then
- object.textRenderer:SetAlignment( var )
- else
- local child = object:GetChildren()
- if #child == 1 then
- local child_object = child[1]
- if child_object.textRenderer ~= nil then
- child_object.textRenderer:SetAlignment( var )
- end
- end
- end
- end,
- ["scale"] = function(object,value,primary)
- primary = primary or false
- if type(value) == "string" then
- local _,_,a,b,c = string.find(value, '(.*)[%s](.*)[%s](.*)')
- local scale = object.Scale
- a = tonumber(a) or scale.x
- b = tonumber(b) or scale.y
- c = tonumber(c) or scale.z
- if a > 1 then a = a / 100 elseif a < 0 then a = 0 end
- if b > 1 then b = b / 100 elseif b < 0 then b = 0 end
- if c > 1 then c = c / 100 elseif c < 0 then c = 0 end
- object.transform:SetLocalScale( Vector3:New( a , b , c ) )
- elseif type(value) == "number" then
- if value > 1 then value = value / 100 elseif value < 0 then value = 0 end
- object.transform:SetLocalScale( Vector3:New( value ) )
- elseif type(value) == "table" then
- value = value or {}
- value[1] = value[1] or 1
- value[2] = value[2] or 1
- value[3] = value[3] or 1
- -- On vérifie les valeurs
- if value[1] > 1 then value[1] = value[1] / 100 elseif value[1] < 0 then value[1] = 0 end
- if value[2] > 1 then value[2] = value[1] / 100 elseif value[2] < 0 then value[2] = 0 end
- if value[3] > 1 then value[3] = value[1] / 100 elseif value[3] < 0 then value[3] = 0 end
- object.transform:SetLocalScale( Vector3:New( unpack(value) ) )
- end
- end,
- ["model"] = function(object,value,primary)
- primary = primary or false
- if object.modelRenderer ~= nil then
- object.modelRenderer:SetModel( CS.FindAsset( value , "Model" ) )
- end
- end,
- ["opacity"] = function(object,value,primary)
- primary = primary or false
- if type(value) == "number" then
- local component
- if object.modelRenderer ~= nil then
- component = object.modelRenderer
- elseif object.mapRenderer ~= nil then
- component = object.mapRenderer
- elseif object.textRenderer ~= nil then
- component = object.textRenderer
- end
- component:SetOpacity( value )
- end
- end,
- ["zindex"] = function(object,value)
- if type(value) == "number" then
- if value >= 0 and value <= 150 then
- AK.UI:Zindex(object.Name,value,true)
- end
- elseif type(value) == "string" then
- if value == "inherit" then
- local parent = object:GetParent()
- if parent ~= nil then
- AK.UI:Zindex(object.Name,parent.Pos.z,true)
- end
- end
- end
- end,
- ["show"] = function(object,value)
- if type(value) == "number" then
- AK.UI:Show(object.Name,value)
- end
- end,
- ["hide"] = function(object,value)
- if type(value) == "number" then
- AK.UI:Hide(object.Name,value)
- end
- end,
- ["button_reset"] = function(object,value)
- if type(value) == "boolean" then
- local comp = object.behavior
- if value then
- comp.default_value = true
- elseif not value then
- comp.default_value = false
- end
- end
- end
- }
- -- > Sub Action stylesheets
- local CSSubAction = {
- ["echo"] = function(object,value)
- local echo = tostring(value)
- if echo == "pos" then
- echo = object.Pos
- elseif echo == "scale" then
- echo = object.Scale
- end
- print(echo)
- end,
- ["play"] = function(object,value)
- if type(value) == "string" then
- if value == "this" then
- AK.UI:Anim(object.Name)
- else
- AK.UI:Anim(value)
- end
- elseif type(value) == "table" then
- for i=1,#value do
- if value[i] == "this" then
- AK.UI:Anim(object.Name)
- else
- AK.UI:Anim(value[i])
- end
- end
- end
- end,
- ["switch"] = function(object,value)
- if type(value) == "string" then
- local _,_,a,b = string.find(value, '(%a*)[%s]?(%a*)')
- local result = {a,b,c}
- if #result == 1 then
- AK.UI:Switch(value)
- elseif #result == 2 then
- if AK.UI.ModuleActive == a then
- AK.UI:Switch(c)
- elseif AK.UI.ModuleActive == c then
- AK.UI:Switch(a)
- else
- AK.UI:Switch(a)
- -- do nothing
- end
- end
- end
- end,
- ["append"] = function(object,value)
- if type(value) == "string" then
- local asset = CS.FindAsset( value , "Scene" )
- if asset ~= nil then
- CS.LoadScene( asset )
- end
- end
- end,
- ["load"] = function(object,value)
- if type(value) == "string" then
- local asset = CS.AppendScene( value , "Scene" )
- if asset ~= nil then
- CS.AppendScene( asset )
- end
- end
- end,
- ["instantiate"] = function(object,value)
- if type(value) == "table" then
- value = value or {}
- local asset = CS.FindAsset( value[2] , "Scene" )
- if asset ~= nil then
- AK.UI[value[1]] = CS.Instantiate( value[1].."_key" , asset )
- end
- end
- end,
- ["destroy"] = function(object,value)
- if type(value) == "string" then
- if AK.UI[value] ~= nil then
- CS.Destroy( AK.UI[value] )
- AK.UI[value] = nil
- end
- end
- end,
- ["exit"] = function(object,value)
- if type(value) == "boolean" then
- if value then
- CS.Exit()
- end
- elseif type(value) == "table" then
- value = value or {}
- value[1] = value[1] or true
- value[2] = value[2] or Nil
- if value[1] then
- value[2]()
- CS.Exit()
- end
- end
- end,
- ["atob"] = function(object,value)
- if type(value) == "string" then
- local _,_,a,b = string.find(value, '(%a*)[%s]?(%a*)')
- local result = {a,b}
- if #result == 1 then
- AK.UI:AtoB(object.Name,a)
- elseif #result == 2 then
- AK.UI:AtoB(a,b)
- end
- elseif type(value) == "table" then
- end
- end,
- ["show"] = CSSCut["show"],
- ["hide"] = CSSCut["hide"],
- ["zindex"] = CSSCut["zindex"],
- ["scale"] = CSSCut["scale"],
- ["model"] = CSSCut["model"],
- ["opacity"] = CSSCut["opacity"],
- ["text"] = CSSCut["text"],
- ["font"] = CSSCut["font"],
- ["align"] = CSSCut["align"],
- ["button_resetset"] = CSSCut["button_reset"]
- }
- -- > Head action stylesheets
- local CSSAction = {
- -- model
- ["model"] = CSSCut["model"],
- ["animation"] = function(object,value)
- if type(value) == "string" and object.modelRenderer ~= nil then
- object.modelRenderer:SetAnimation( CS.FindAsset( value, "Animation" ) )
- end
- end,
- -- Map
- ["map"] = function(object,value)
- if value ~= nil and object.mapRenderer ~= nil then
- object.mapRenderer:SetMap( CS.FindAsset( value , "Map" ) )
- end
- end,
- ["tile"] = function(object,value)
- if value ~= nil and object.mapRenderer ~= nil then
- object.mapRenderer:SetTileSet( CS.FindAsset( value , "TileSet" ) )
- end
- end,
- -- Input action
- ["onclick"] = function(object,value)
- if type(value) == "table" then
- for k,v in pairs(CSSubAction) do
- for a,b in pairs(value) do
- if a == k then
- object:OnClick( function()
- v(object,b)
- end )
- end
- end
- end
- elseif type(value) == "function" then
- object:OnClick( value )
- end
- end,
- ["outclick"] = function(object,value)
- if type(value) == "table" then
- for k,v in pairs(CSSubAction) do
- for a,b in pairs(value) do
- if a == k then
- object:OutClick( function()
- v(object,b)
- end )
- end
- end
- end
- elseif type(value) == "function" then
- object:OutClick( value )
- end
- end,
- ["onfocus"] = function(object,value)
- end,
- ["outfocus"] = function(object,value)
- end,
- ["onhover"] = function(object,value)
- if type(value) == "table" then
- for k,v in pairs(CSSubAction) do
- for a,b in pairs(value) do
- if a == k then
- object:OnHover( function()
- v(object,b)
- end )
- end
- end
- end
- elseif type(value) == "function" then
- object:OnHover( value )
- end
- end,
- ["outhover"] = function(object,value)
- if type(value) == "table" then
- for k,v in pairs(CSSubAction) do
- for a,b in pairs(value) do
- if a == k then
- object:OutHover( function()
- v(object,b)
- end )
- end
- end
- end
- elseif type(value) == "function" then
- object:OutHover( value )
- end
- end,
- ["next"] = function(object,value)
- if type(value) == "table" then
- for k,v in pairs(CSSubAction) do
- for a,b in pairs(value) do
- if a == k then
- object:OnNext( function()
- v(object,b)
- end )
- end
- end
- end
- elseif type(value) == "function" then
- object:OnNext( value )
- end
- end,
- -- > Input arguments
- ["input_valide"] = function(object,value)
- end,
- ["input_err"] = function(object,value)
- end,
- ["input_warning"] = function(object,value)
- end,
- -- Camera action
- ["projection"] = function(object,value)
- if type(value) == "string" then
- if object.camera ~= nil then
- if value == "perspective" then
- object.camera:SetProjectionMode( Camera.ProjectionMode.Perspective )
- else
- object.camera:SetProjectionMode( Camera.ProjectionMode.Orthographic )
- end
- end
- end
- end,
- ["fov"] = function(object,value)
- if type(value) == "number" then
- if object.camera ~= nil then
- object.camera:SetFOV( value )
- end
- end
- end,
- ["orthoscale"] = function(object,value)
- if type(value) == "number" then
- if object.camera ~= nil then
- object.camera:SetOrthographicScale( value )
- end
- end
- end,
- ["radarsize"] = function(object,value)
- if type(value) == "table" then
- if object.camera ~= nil then
- value = value or {}
- value[1] = value[1] or 1
- value[2] = value[2] or 1
- object.camera:SetRenderViewportSize( unpack(value) )
- end
- end
- end,
- ["radarposition"] = function(object,value)
- if type(value) == "table" then
- if object.camera ~= nil then
- value = value or {}
- value[1] = value[1] or 1
- value[2] = value[2] or 1
- object.camera:SetRenderViewportPosition( unpack(value) )
- end
- end
- end,
- -- Transform action
- ["scale"] = CSSCut["scale"],
- ["margin"] = function(object,value)
- if type(value) == "string" then
- local _,_,a,b = string.find(value, '(%d*)[%s]?(%d*)')
- local result = {a,b}
- result[1] = result[1] or 0
- result[2] = result[2] or 0
- local pos = object.Pos
- if #result == 1 then
- object.transform:SetPosition( Vector3:New( pos.x + result[1], pos.y + result[1], pos.z ) )
- elseif #result == 2 then
- object.transform:SetPosition( Vector3:New( pos.x + result[1], pos.y + result[2], pos.z ) )
- else
- -- do nothing
- end
- end
- end,
- ["position"] = function(object,value)
- if type(value) == "string" then
- if value == "inherit" then
- local parent = object:GetParent()
- if parent ~= nil then
- object.transform:SetPosition( parent.Pos )
- end
- elseif value == "center" then
- object.transform:SetPosition( Vector3:New( 0 , 0 , object.Pos.z ) )
- else
- -- do nothing
- end
- end
- end,
- -- GameObject
- ["parent"] = function(object,value)
- if value ~= nil and type(value) == "string" then
- local parent = CS.Get(value)
- if parent ~= nil then
- object:SetParent( parent )
- end
- end
- end,
- ["behavior"] = function(object,value)
- if type(value) == "table" then
- local comp = object.behavior
- if comp ~= nil then
- for k,v in pairs(value) do
- if comp.k ~= nil then
- comp.k = v
- end
- end
- end
- end
- end,
- -- Animation
- ["show"] = CSSCut["show"],
- ["hide"] = CSSCut["hide"],
- -- Triple contexte
- ["opacity"] = CSSCut["opacity"],
- ["zindex"] = CSSCut["zindex"],
- -- TextRenderer CSS
- ["text"] = CSSCut["text"],
- ["font"] = CSSCut["font"],
- ["align"] = CSSCut["align"];
- ["button_reset"] = CSSCut["button_reset"]
- }
- -- > UI build CSS function
- function camera2D:BuildCSS(autoapply)
- autoapply = autoapply or false
- local x = AK.CSS
- for k,v in pairs(x) do
- self.css[k] = v
- end
- if autoapply then
- self:ApplyCSS()
- end
- end
- function camera2D:ApplyCSS()
- local x = self.css
- for k,v in pairs(x) do
- local _,_,a,b,c,d,e = string.find(k, '(%a*)[%s]?(%a*)[%s]?(%a*)[%s]?(%a*)[%s]?(%a*)')
- --print(a,b,c,d,e)
- local result = {a,b,c,d,e}
- for _,values in pairs(result) do
- if values ~= nil and values ~= "" then
- local object = CS.Get(values)
- if object ~= nil then
- local pos = {{},{},nil}
- local posinit = false
- local fixedcontaint = {false,nil}
- local anim = {false,1,false,{0,0},{0,0}}
- for a,b in pairs(v) do
- if a == "script" then
- b = b or "OnClick"
- local comp = object:GetComponent("ScriptedBehavior")
- if comp == nil then
- self:AddScript(values,b)
- end
- elseif a == "left" or a == "right" then
- pos[1][1] = a
- pos[1][2] = b
- elseif a == "top" or a == "bottom" then
- pos[2][1] = a
- pos[2][2] = b
- elseif a == "resize" then
- pos[3] = b or false
- elseif a == "position" then
- posinit = true
- elseif a == "container" then
- if type(b) == "string" then
- --local new_parent = CS.Get(b)
- --object:SetParent(new_parent,false)
- fixedcontaint[1] = true
- fixedcontaint[2] = b
- end
- elseif a == "anim" then
- if type(b) == "table" then
- if #b >= 3 then
- if not anim[1] then
- anim[1] = true
- end
- anim[2] = b[1] or 1
- anim[3] = b[2] or false
- anim[4] = b[3] or {0,0}
- anim[5] = b[4] or {0,0}
- end
- end
- elseif a == "anim_pos" then
- if type(b) == "table" then
- if not anim[1] then
- anim[1] = true
- end
- anim[4][1] = b[1] or 0
- anim[4][2] = b[2] or 0
- end
- elseif a == "anim_scale" then
- if type(b) == "table" then
- if not anim[1] then
- anim[1] = true
- end
- anim[5][1] = b[1] or 0
- anim[5][2] = b[2] or 0
- end
- elseif a == "anim_speed" then
- anim[2] = b
- elseif a == "anim_resize" then
- anim[3] = b
- end
- self:TrimCSS(values,a,b)
- end
- if not posinit then
- if not fixedcontaint[1] then
- pos[3] = pos[3] or false
- self:Pos(values,pos[1],pos[2],pos[3])
- else
- if fixedcontaint[2] ~= nil then
- self:FixedPos(fixedcontaint[2],values,pos[1],pos[2])
- end
- end
- end
- if anim[1] then
- self:NewAnim(values,anim[2],anim[3],anim[4],anim[5])
- end
- end
- end
- end
- end
- end
- function camera2D:TrimCSS(object,K,V)
- local object = CS.Get(object)
- if type(V) == "string" and string.lower(K) ~= "text" then
- V = string.lower(V)
- end
- for a,b in pairs(CSSAction) do
- local _,_,key = string.find(K,"key",1)
- if key ~= nil then
- print(key)
- end
- if a == string.lower(K) then
- b(object,V,true)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement