Skip to content

Commit

Permalink
Updated docs. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Oct 24, 2024
1 parent 0596150 commit 0a013bf
Show file tree
Hide file tree
Showing 41 changed files with 10,719 additions and 1,592 deletions.
15 changes: 12 additions & 3 deletions Assets/Script/Lib/Dora/en/Dora.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3486,7 +3486,7 @@ class Content {
* @returns A table containing the data in the Excel file. The keys are the sheet names and the values are tables containing the rows and columns of the sheet.
*/
loadExcel(filename: string, sheetNames?: string[]): {
[sheetName: string]: [column: string | number][]
[sheetName: string]: (/* column */ string | number)[][] | undefined
} | null;

/**
Expand Down Expand Up @@ -3588,7 +3588,7 @@ class Content {
* @returns A table containing the data in the Excel file. The keys are the sheet names and the values are tables containing the rows and columns of the sheet.
*/
loadExcelAsync(filename: string, sheetNames?: string[]): {
[sheetName: string]: [column: string | number][]
[sheetName: string]: (/* column */ string | number)[][]
} | null;

/**
Expand Down Expand Up @@ -3977,7 +3977,7 @@ class Playable extends Node {
* @param name The name of the slot to set.
* @param item The node to set the slot to.
*/
setSlot(name: string, item: Node): void;
setSlot(name: string, item: Node | null): void;

/**
* Gets the child node attached to the animation model.
Expand Down Expand Up @@ -4633,6 +4633,15 @@ interface EntityClass {
* Entity({ a: 1, b: "abc", c: Node() });
*/
(this: void, components: Record<string, Component>): Entity;

/**
* A method that creates a new entity with the specified components.
* And you can then get the newly created Entity object from groups and observers.
* @param components A table mapping component names (strings) to component values (Items).
* @example
* Entity<Item>({ a: 1, b: "abc", c: Node() });
*/
<T>(this: void, components: T): Entity;
}

const entityClass: EntityClass;
Expand Down
15 changes: 12 additions & 3 deletions Assets/Script/Lib/Dora/zh-Hans/Dora.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3483,7 +3483,7 @@ class Content {
* @returns 包含Excel文件中数据的表。键是表名,值是包含表的行和列的表。
*/
loadExcel(filename: string, sheetNames?: string[]): {
[sheetName: string]: [column: string | number][]
[sheetName: string]: (/* column */ string | number)[][] | undefined
} | null;

/**
Expand Down Expand Up @@ -3585,7 +3585,7 @@ class Content {
* @returns 包含Excel文件中数据的表。键是表名,值是包含表的行和列的表。
*/
loadExcelAsync(filename: string, sheetNames?: string[]): {
[sheetName: string]: [column: string | number][]
[sheetName: string]: (/* column */ string | number)[][]
} | null;

/**
Expand Down Expand Up @@ -3974,7 +3974,7 @@ class Playable extends Node {
* @param name 要设置的插槽的名称。
* @param item 要设置插槽的节点。
*/
setSlot(name: string, item: Node): void;
setSlot(name: string, item: Node | null): void;

/**
* 获取附加到动画模型的子节点。
Expand Down Expand Up @@ -4633,6 +4633,15 @@ interface EntityClass {
* Entity({ a: 1, b: "abc", c: Node() });
*/
(this: void, components: Record<string, Component>): Entity;

/**
* 用于创建具有指定组件的新实体。
* 在新实体创建以后,可以从实体组和观察者中访问新创建的Entity对象。
* @param components 将组件名称(字符串)映射到组件值的数值字典。
* @example
* Entity<Item>({ a: 1, b: "abc", c: Node() });
*/
<T>(this: void, components: T): Entity;
}

const entity: EntityClass;
Expand Down
293 changes: 143 additions & 150 deletions Assets/Script/Test/Entity MoveTS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,153 +17,146 @@ local Vec2 = ____Dora.Vec2 -- 4
local tolua = ____Dora.tolua -- 4
local sceneGroup = Group({"scene"}) -- 6
local positionGroup = Group({"position"}) -- 7
local function toNode(item) -- 9
return tolua.cast(item, "Node") -- 10
end -- 9
Observer("Add", {"scene"}):watch(function(_, scene) -- 13
scene:onTapEnded(function(touch) -- 14
local ____touch_0 = touch -- 15
local location = ____touch_0.location -- 15
positionGroup:each(function(entity) -- 16
entity.target = location -- 17
return false -- 18
end) -- 16
end) -- 14
return false -- 21
end) -- 13
Observer("Add", {"image"}):watch(function(entity, image) -- 24
sceneGroup:each(function(e) -- 25
local scene = toNode(e.scene) -- 26
if scene ~= nil then -- 26
local sprite = Sprite(image) -- 28
if sprite then -- 28
sprite:addTo(scene) -- 30
sprite:runAction(Scale(0.5, 0, 0.5, Ease.OutBack)) -- 31
entity.sprite = sprite -- 32
end -- 32
return true -- 34
end -- 34
return false -- 36
end) -- 25
return false -- 38
end) -- 24
Observer("Remove", {"sprite"}):watch(function(entity) -- 41
local sprite = toNode(entity.oldValues.sprite) -- 42
if sprite ~= nil then -- 42
sprite:removeFromParent() -- 43
end -- 43
return false -- 44
end) -- 41
Observer("Remove", {"target"}):watch(function(entity) -- 47
print("remove target from entity " .. tostring(entity.index)) -- 48
return false -- 49
end) -- 47
Group({"position", "direction", "speed", "target"}):watch(function(entity, position, _direction, speed, target) -- 52
if target:equals(position) then -- 52
return false -- 54
end -- 54
local dir = target:sub(position):normalize() -- 55
local angle = math.deg(math.atan(dir.x, dir.y)) -- 56
local newPos = position:add(dir:mul(speed)) -- 57
newPos = newPos:clamp(position, target) -- 58
entity.position = newPos -- 59
entity.direction = angle -- 60
if newPos:equals(target) then -- 60
entity.target = nil -- 62
end -- 62
return false -- 64
end) -- 53
Observer("AddOrChange", {"position", "direction", "sprite"}):watch(function(entity, position, direction, sprite) -- 67
sprite.position = position -- 69
local ____entity_oldValues_direction_3 = entity.oldValues.direction -- 70
if ____entity_oldValues_direction_3 == nil then -- 70
____entity_oldValues_direction_3 = sprite.angle -- 70
end -- 70
local lastDirection = ____entity_oldValues_direction_3 -- 70
if type(lastDirection) == "number" then -- 70
if math.abs(direction - lastDirection) > 1 then -- 70
sprite:runAction(Roll(0.3, lastDirection, direction)) -- 73
end -- 73
end -- 73
return false -- 76
end) -- 68
Entity({scene = Node()}) -- 86
local def = {image = "Image/logo.png", position = Vec2.zero, direction = 45, speed = 4} -- 88
Entity(def) -- 94
def = { -- 96
image = "Image/logo.png", -- 97
position = Vec2(-100, 200), -- 98
direction = 90, -- 99
speed = 10 -- 100
} -- 100
Entity(def) -- 102
local windowFlags = { -- 104
"NoDecoration", -- 105
"AlwaysAutoResize", -- 106
"NoSavedSettings", -- 107
"NoFocusOnAppearing", -- 108
"NoNav", -- 109
"NoMove" -- 110
} -- 110
Observer("Add", {"scene"}):watch(function(entity) -- 112
local scene = toNode(entity.scene) -- 113
if scene ~= nil then -- 113
scene:schedule(function() -- 115
local ____App_visualSize_4 = App.visualSize -- 116
local width = ____App_visualSize_4.width -- 116
ImGui.SetNextWindowBgAlpha(0.35) -- 117
ImGui.SetNextWindowPos( -- 118
Vec2(width - 10, 10), -- 118
"Always", -- 118
Vec2(1, 0) -- 118
) -- 118
ImGui.SetNextWindowSize( -- 119
Vec2(240, 0), -- 119
"FirstUseEver" -- 119
) -- 119
ImGui.Begin( -- 120
"ECS System", -- 120
windowFlags, -- 120
function() -- 120
ImGui.Text("ECS System (Typescript)") -- 121
ImGui.Separator() -- 122
ImGui.TextWrapped("Tap any place to move entities.") -- 123
if ImGui.Button("Create Random Entity") then -- 123
local def = { -- 125
image = "Image/logo.png", -- 126
position = Vec2( -- 127
6 * math.random(1, 100), -- 127
6 * math.random(1, 100) -- 127
), -- 127
direction = 1 * math.random(0, 360), -- 128
speed = 1 * math.random(1, 20) -- 129
} -- 129
Entity(def) -- 131
end -- 131
if ImGui.Button("Destroy An Entity") then -- 131
Group({"sprite", "position"}):each(function(e) -- 134
e.position = nil -- 135
local sprite = toNode(e.sprite) -- 136
if sprite ~= nil then -- 136
sprite:runAction(Sequence( -- 138
Scale(0.5, 0.5, 0, Ease.InBack), -- 140
Event("Destroy") -- 141
)) -- 141
sprite:slot( -- 144
"Destroy", -- 144
function() -- 144
e:destroy() -- 145
end -- 144
) -- 144
end -- 144
return true -- 148
end) -- 134
end -- 134
end -- 120
) -- 120
return false -- 152
end) -- 115
end -- 115
return false -- 155
end) -- 112
return ____exports -- 112
Observer("Add", {"scene"}):watch(function(_entity, scene) -- 9
scene:onTapEnded(function(touch) -- 10
local ____touch_0 = touch -- 11
local location = ____touch_0.location -- 11
positionGroup:each(function(entity) -- 12
entity.target = location -- 13
return false -- 14
end) -- 12
end) -- 10
return false -- 17
end) -- 9
Observer("Add", {"image"}):watch(function(entity, image) -- 20
sceneGroup:each(function(e) -- 21
local scene = tolua.cast(e.scene, "Node") -- 22
if scene then -- 22
local sprite = Sprite(image) -- 24
if sprite then -- 24
sprite:addTo(scene) -- 26
sprite:runAction(Scale(0.5, 0, 0.5, Ease.OutBack)) -- 27
entity.sprite = sprite -- 28
end -- 28
return true -- 30
end -- 30
return false -- 32
end) -- 21
return false -- 34
end) -- 20
Observer("Remove", {"sprite"}):watch(function(entity) -- 37
local sprite = tolua.cast(entity.oldValues.sprite, "Sprite") -- 38
if sprite ~= nil then -- 38
sprite:removeFromParent() -- 39
end -- 39
return false -- 40
end) -- 37
Observer("Remove", {"target"}):watch(function(entity) -- 43
print("remove target from entity " .. tostring(entity.index)) -- 44
return false -- 45
end) -- 43
Group({"position", "direction", "speed", "target"}):watch(function(entity, position, _direction, speed, target) -- 48
if target:equals(position) then -- 48
return false -- 50
end -- 50
local dir = target:sub(position):normalize() -- 51
local angle = math.deg(math.atan(dir.x, dir.y)) -- 52
local newPos = position:add(dir:mul(speed)) -- 53
entity.position = newPos:clamp(position, target) -- 54
entity.direction = angle -- 55
if newPos:equals(target) then -- 55
entity.target = nil -- 57
end -- 57
return false -- 59
end) -- 49
Observer("AddOrChange", {"position", "direction", "sprite"}):watch(function(entity, position, direction, sprite) -- 62
sprite.position = position -- 64
local ____entity_oldValues_direction_3 = entity.oldValues.direction -- 65
if ____entity_oldValues_direction_3 == nil then -- 65
____entity_oldValues_direction_3 = sprite.angle -- 65
end -- 65
local lastDirection = ____entity_oldValues_direction_3 -- 65
if type(lastDirection) == "number" then -- 65
if math.abs(direction - lastDirection) > 1 then -- 65
sprite:runAction(Roll(0.3, lastDirection, direction)) -- 68
end -- 68
end -- 68
return false -- 71
end) -- 63
Entity({scene = Node()}) -- 74
Entity({image = "Image/logo.png", position = Vec2.zero, direction = 45, speed = 4}) -- 83
Entity({ -- 90
image = "Image/logo.png", -- 91
position = Vec2(-100, 200), -- 92
direction = 90, -- 93
speed = 10 -- 94
}) -- 94
local windowFlags = { -- 97
"NoDecoration", -- 98
"AlwaysAutoResize", -- 99
"NoSavedSettings", -- 100
"NoFocusOnAppearing", -- 101
"NoNav", -- 102
"NoMove" -- 103
} -- 103
Observer("Add", {"scene"}):watch(function(entity) -- 105
local scene = tolua.cast(entity.scene, "Node") -- 106
if scene ~= nil then -- 106
scene:schedule(function() -- 108
local ____App_visualSize_4 = App.visualSize -- 109
local width = ____App_visualSize_4.width -- 109
ImGui.SetNextWindowBgAlpha(0.35) -- 110
ImGui.SetNextWindowPos( -- 111
Vec2(width - 10, 10), -- 111
"Always", -- 111
Vec2(1, 0) -- 111
) -- 111
ImGui.SetNextWindowSize( -- 112
Vec2(240, 0), -- 112
"FirstUseEver" -- 112
) -- 112
ImGui.Begin( -- 113
"ECS System", -- 113
windowFlags, -- 113
function() -- 113
ImGui.Text("ECS System (Typescript)") -- 114
ImGui.Separator() -- 115
ImGui.TextWrapped("Tap any place to move entities.") -- 116
if ImGui.Button("Create Random Entity") then -- 116
Entity({ -- 118
image = "Image/logo.png", -- 119
position = Vec2( -- 120
6 * math.random(1, 100), -- 120
6 * math.random(1, 100) -- 120
), -- 120
direction = 1 * math.random(0, 360), -- 121
speed = 1 * math.random(1, 20) -- 122
}) -- 122
end -- 122
if ImGui.Button("Destroy An Entity") then -- 122
Group({"sprite", "position"}):each(function(e) -- 126
e.position = nil -- 127
local sprite = tolua.cast(e.sprite, "Sprite") -- 128
if sprite ~= nil then -- 128
sprite:runAction(Sequence( -- 130
Scale(0.5, 0.5, 0, Ease.InBack), -- 132
Event("Destroy") -- 133
)) -- 133
sprite:slot( -- 136
"Destroy", -- 136
function() -- 136
e:destroy() -- 137
end -- 136
) -- 136
end -- 136
return true -- 140
end) -- 126
end -- 126
end -- 113
) -- 113
return false -- 144
end) -- 108
end -- 108
return false -- 147
end) -- 105
return ____exports -- 105
Loading

0 comments on commit 0a013bf

Please sign in to comment.