Skip to content

Commit

Permalink
update Lua. add compiled Yuescript codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Mar 13, 2024
1 parent 65ac8af commit b9bbaf3
Show file tree
Hide file tree
Showing 135 changed files with 21,141 additions and 141 deletions.
1,664 changes: 1,664 additions & 0 deletions Assets/Script/Dev/Entry.lua

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions Assets/Script/Dev/Entry.yue
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,11 @@ footerWindow = threadLoop ->
return unless showEntry

:width, :height = App.visualSize
SetNextWindowSize Vec2 170, 50
SetNextWindowPos if width >= 600
Vec2 width - 170, height - 50
else
Vec2 width, height
SetNextWindowSize Vec2 50, 50
SetNextWindowPos Vec2 width - 50, height - 50
PushStyleColor "WindowBg", transparant, -> Begin "Show", windowFlags, ->
if width >= 600
Columns 2, false
NextColumn!
if changed, showFooter := Checkbox zh and "开发" or "Dev", showFooter
if isInEntry or width >= 540
if changed, showFooter := Checkbox "##dev", showFooter
config.showFooter = showFooter and 1 or 0

if isInEntry and
Expand Down
86 changes: 86 additions & 0 deletions Assets/Script/Example/Body.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-- [yue]: Script/Example/Body.yue
local Vec2 = dora.Vec2 -- 1
local BodyDef = dora.BodyDef -- 1
local PhysicsWorld = dora.PhysicsWorld -- 1
local Body = dora.Body -- 1
local threadLoop = dora.threadLoop -- 1
local App = dora.App -- 1
local ImGui = dora.ImGui -- 1
local gravity <const> = Vec2(0, -10) -- 3
local groupZero <const> = 0 -- 5
local groupOne <const> = 1 -- 6
local groupTwo <const> = 2 -- 7
local terrainDef -- 9
do -- 9
local _with_0 = BodyDef() -- 9
_with_0.type = "Static" -- 10
_with_0:attachPolygon(800, 10, 1, 0.8, 0.2) -- 11
terrainDef = _with_0 -- 9
end -- 9
local polygonDef -- 13
do -- 13
local _with_0 = BodyDef() -- 13
_with_0.type = "Dynamic" -- 14
_with_0.linearAcceleration = gravity -- 15
_with_0:attachPolygon({ -- 17
Vec2(60, 0), -- 17
Vec2(30, -30), -- 18
Vec2(-30, -30), -- 19
Vec2(-60, 0), -- 20
Vec2(-30, 30), -- 21
Vec2(30, 30) -- 22
}, 1, 0.4, 0.4) -- 16
polygonDef = _with_0 -- 13
end -- 13
local diskDef -- 25
do -- 25
local _with_0 = BodyDef() -- 25
_with_0.type = "Dynamic" -- 26
_with_0.linearAcceleration = gravity -- 27
_with_0:attachDisk(60, 1, 0.4, 0.4) -- 28
diskDef = _with_0 -- 25
end -- 25
do -- 30
local world = PhysicsWorld() -- 30
world.y = -200 -- 31
world.showDebug = true -- 32
world:setShouldContact(groupZero, groupOne, false) -- 34
world:setShouldContact(groupZero, groupTwo, true) -- 35
world:setShouldContact(groupOne, groupTwo, true) -- 36
world:addChild((function() -- 38
local _with_0 = Body(terrainDef, world, Vec2.zero) -- 38
_with_0.group = groupTwo -- 39
return _with_0 -- 38
end)()) -- 38
world:addChild((function() -- 41
local _with_0 = Body(polygonDef, world, Vec2(0, 500), 15) -- 41
_with_0.group = groupOne -- 42
return _with_0 -- 41
end)()) -- 41
world:addChild((function() -- 44
local _with_0 = Body(diskDef, world, Vec2(50, 800)) -- 44
_with_0.group = groupZero -- 45
_with_0.angularRate = 90 -- 46
return _with_0 -- 44
end)()) -- 44
end -- 30
local windowFlags = { -- 51
"NoDecoration", -- 51
"AlwaysAutoResize", -- 52
"NoSavedSettings", -- 53
"NoFocusOnAppearing", -- 54
"NoNav", -- 55
"NoMove" -- 56
} -- 50
return threadLoop(function() -- 57
local width -- 58
width = App.visualSize.width -- 58
ImGui.SetNextWindowBgAlpha(0.35) -- 59
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0)) -- 60
ImGui.SetNextWindowSize(Vec2(240, 0), "FirstUseEver") -- 61
return ImGui.Begin("Body", windowFlags, function() -- 62
ImGui.Text("Body") -- 63
ImGui.Separator() -- 64
return ImGui.TextWrapped("Basic usage to create physics bodies!") -- 65
end) -- 65
end) -- 65
72 changes: 72 additions & 0 deletions Assets/Script/Example/Camera.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- [yue]: Script/Example/Camera.yue
local Node = dora.Node -- 1
local Model = dora.Model -- 1
local Sprite = dora.Sprite -- 1
local Vec2 = dora.Vec2 -- 1
local once = dora.once -- 1
local Director = dora.Director -- 1
local cycle = dora.cycle -- 1
local Ease = dora.Ease -- 1
local threadLoop = dora.threadLoop -- 1
local App = dora.App -- 1
local ImGui = dora.ImGui -- 1
do -- 3
local _with_0 = Node() -- 3
_with_0:addChild((function() -- 4
local _with_1 = Model("Model/xiaoli.model") -- 4
_with_1.look = "happy" -- 5
_with_1:play("idle", true) -- 6
return _with_1 -- 4
end)()) -- 4
_with_0:addChild((function() -- 8
local _with_1 = Sprite("Image/logo.png") -- 8
_with_1.scaleX = 0.4 -- 9
_with_1.scaleY = 0.4 -- 10
_with_1.position = Vec2(200, -100) -- 11
_with_1.angleY = 45 -- 12
_with_1.z = -300 -- 13
return _with_1 -- 8
end)()) -- 8
_with_0:schedule(once(function() -- 15
local _with_1 = Director.currentCamera -- 15
cycle(1.5, function(dt) -- 16
_with_1.position = Vec2(200 * Ease:func(Ease.InOutQuad, dt), 0) -- 16
end) -- 16
cycle(0.1, function(dt) -- 17
_with_1.rotation = 25 * Ease:func(Ease.OutSine, dt) -- 17
end) -- 17
cycle(0.2, function(dt) -- 18
_with_1.rotation = 25 - 50 * Ease:func(Ease.InOutQuad, dt) -- 18
end) -- 18
cycle(0.1, function(dt) -- 19
_with_1.rotation = -25 + 25 * Ease:func(Ease.OutSine, dt) -- 19
end) -- 19
cycle(1.5, function(dt) -- 20
_with_1.position = Vec2(200 * Ease:func(Ease.InOutQuad, 1 - dt), 0) -- 20
end) -- 20
local zoom = _with_1.zoom -- 21
cycle(2.5, function(dt) -- 22
_with_1.zoom = zoom + Ease:func(Ease.InOutQuad, dt) -- 22
end) -- 22
return _with_1 -- 15
end)) -- 15
end -- 3
local windowFlags = { -- 27
"NoDecoration", -- 27
"AlwaysAutoResize", -- 28
"NoSavedSettings", -- 29
"NoFocusOnAppearing", -- 30
"NoNav", -- 31
"NoMove" -- 32
} -- 26
return threadLoop(function() -- 33
local width -- 34
width = App.visualSize.width -- 34
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0)) -- 35
ImGui.SetNextWindowSize(Vec2(240, 0), "FirstUseEver") -- 36
return ImGui.Begin("Camera", windowFlags, function() -- 37
ImGui.Text("Camera") -- 38
ImGui.Separator() -- 39
return ImGui.TextWrapped("View camera motions, use 3D camera as default!") -- 40
end) -- 40
end) -- 40
146 changes: 146 additions & 0 deletions Assets/Script/Example/ClipNode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
-- [yue]: Script/Example/ClipNode.yue
local math = _G.math -- 1
local Vec2 = dora.Vec2 -- 1
local DrawNode = dora.DrawNode -- 1
local Model = dora.Model -- 1
local Sequence = dora.Sequence -- 1
local X = dora.X -- 1
local Event = dora.Event -- 1
local ClipNode = dora.ClipNode -- 1
local Line = dora.Line -- 1
local App = dora.App -- 1
local Node = dora.Node -- 1
local threadLoop = dora.threadLoop -- 1
local ImGui = dora.ImGui -- 1
local StarVertices -- 3
StarVertices = function(radius, line) -- 3
if line == nil then -- 3
line = false -- 3
end -- 3
local a = math.rad(36) -- 4
local c = math.rad(72) -- 5
local f = math.sin(a) * math.tan(c) + math.cos(a) -- 6
local R = radius -- 7
local r = R / f -- 8
local _accum_0 = { } -- 9
local _len_0 = 1 -- 9
for i = 9, line and -1 or 0, -1 do -- 9
local angle = i * a -- 10
local cr = i % 2 == 1 and r or R -- 11
_accum_0[_len_0] = Vec2(cr * math.sin(angle), cr * math.cos(angle)) -- 12
_len_0 = _len_0 + 1 -- 12
end -- 12
return _accum_0 -- 12
end -- 3
local maskA -- 16
do -- 16
local _with_0 = DrawNode() -- 16
_with_0:drawPolygon(StarVertices(160)) -- 17
maskA = _with_0 -- 16
end -- 16
local targetA -- 19
do -- 19
local _with_0 = Model("Model/xiaoli.model") -- 19
_with_0.look = "happy" -- 20
_with_0.fliped = true -- 21
_with_0:play("walk", true) -- 22
_with_0:runAction(Sequence(X(1.5, -200, 200), Event("Turn"), X(1.5, 200, -200), Event("Turn"))) -- 23
_with_0:slot("ActionEnd", function(action) -- 29
return _with_0:runAction(action) -- 29
end) -- 29
_with_0:slot("Turn", function() -- 30
_with_0.fliped = not _with_0.fliped -- 30
end) -- 30
targetA = _with_0 -- 19
end -- 19
local clipNodeA -- 32
do -- 32
local _with_0 = ClipNode(maskA) -- 32
_with_0:addChild(targetA) -- 33
_with_0.inverted = true -- 34
clipNodeA = _with_0 -- 32
end -- 32
local frame -- 35
do -- 35
local _with_0 = Line(StarVertices(160, true), App.themeColor) -- 35
_with_0.visible = false -- 36
frame = _with_0 -- 35
end -- 35
local exampleA -- 37
do -- 37
local _with_0 = Node() -- 37
_with_0:addChild(clipNodeA) -- 38
_with_0:addChild(frame) -- 39
_with_0.visible = false -- 40
exampleA = _with_0 -- 37
end -- 37
local maskB -- 44
do -- 44
local _with_0 = Model("Model/xiaoli.model") -- 44
_with_0.look = "happy" -- 45
_with_0.fliped = true -- 46
_with_0:play("walk", true) -- 47
maskB = _with_0 -- 44
end -- 44
local targetB -- 49
do -- 49
local _with_0 = DrawNode() -- 49
_with_0:drawPolygon(StarVertices(160)) -- 50
_with_0:runAction(Sequence(X(1.5, -200, 200), X(1.5, 200, -200))) -- 51
_with_0:slot("ActionEnd", function(action) -- 55
return _with_0:runAction(action) -- 55
end) -- 55
targetB = _with_0 -- 49
end -- 49
local clipNodeB -- 57
do -- 57
local _with_0 = ClipNode(maskB) -- 57
_with_0:addChild(targetB) -- 58
_with_0.inverted = true -- 59
_with_0.alphaThreshold = 0.3 -- 60
clipNodeB = _with_0 -- 57
end -- 57
local exampleB -- 61
do -- 61
local _with_0 = Node() -- 61
_with_0:addChild(clipNodeB) -- 62
exampleB = _with_0 -- 61
end -- 61
local inverted = true -- 66
local withAlphaThreshold = true -- 67
local windowFlags = { -- 69
"NoDecoration", -- 69
"AlwaysAutoResize", -- 70
"NoSavedSettings", -- 71
"NoFocusOnAppearing", -- 72
"NoNav", -- 73
"NoMove" -- 74
} -- 68
return threadLoop(function() -- 75
local width -- 76
width = App.visualSize.width -- 76
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0)) -- 77
ImGui.SetNextWindowSize(Vec2(240, 0), "FirstUseEver") -- 78
return ImGui.Begin("Clip Node", windowFlags, function() -- 79
ImGui.Text("Clip Node") -- 80
ImGui.Separator() -- 81
ImGui.TextWrapped("Render children nodes with mask!") -- 82
do -- 83
local changed -- 83
changed, inverted = ImGui.Checkbox("Inverted", inverted) -- 83
if changed then -- 83
clipNodeA.inverted = inverted -- 84
clipNodeB.inverted = inverted -- 85
frame.visible = not inverted -- 86
end -- 83
end -- 83
do -- 87
local changed -- 87
changed, withAlphaThreshold = ImGui.Checkbox("With alphaThreshold", withAlphaThreshold) -- 87
if changed then -- 87
exampleB.visible = withAlphaThreshold -- 88
exampleA.visible = not withAlphaThreshold -- 89
end -- 87
end -- 87
end) -- 89
end) -- 89
Loading

0 comments on commit b9bbaf3

Please sign in to comment.