Skip to content

Commit

Permalink
Updated bindings. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Jan 3, 2025
1 parent 5730285 commit f6aabbd
Show file tree
Hide file tree
Showing 11 changed files with 644 additions and 108 deletions.
3 changes: 3 additions & 0 deletions Source/Node/DragonBone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ void DragonBone::DBArmatureProxy::dispatchDBEvent(const std::string& type, db::E
const std::string& animationName = value->animationState->getName();
_parent->emit("AnimationEnd"_slice, animationName, s_cast<Playable*>(_parent));
_parent->_lastCompletedAnimationName = animationName;
if (_parent->_currentAnimationName == animationName) {
_parent->_currentAnimationName.clear();
}
} else if (type == db::EventObject::LOOP_COMPLETE) {
auto animationName = value->animationState->getName();
_parent->emit("AnimationEnd"_slice, animationName, s_cast<Playable*>(_parent));
Expand Down
6 changes: 6 additions & 0 deletions Source/Node/Spine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ void Spine::SpineListener::callback(spine::AnimationState* state, spine::EventTy
case spine::EventType_Complete:
_owner->emit("AnimationEnd"_slice, animationName.toString(), s_cast<Playable*>(_owner));
_owner->_lastCompletedAnimationName = animationName.toString();
if (_owner->_currentAnimationName == animationName) {
_owner->_currentAnimationName.clear();
}
break;
case spine::EventType_Interrupt:
_owner->_lastCompletedAnimationName.clear();
if (_owner->_currentAnimationName == animationName) {
_owner->_currentAnimationName.clear();
}
break;
case spine::EventType_Start:
case spine::EventType_Dispose:
Expand Down
1 change: 1 addition & 0 deletions Source/Wasm/WasmRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ static Own<Value> Value_To(const dora_val_t& v) {
}

static int64_t Value_From(Value* v) {
if (!v) return 0;
switch (v->getType()) {
case ValueType::Integral:
return r_cast<int64_t>(new dora_val_t(v->toVal<int64_t>()));
Expand Down
26 changes: 13 additions & 13 deletions Tools/dora-wa/src/body.wa
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "dora"

func test_body() {
gravity := dora.Vec2{X: 0.0, Y: -10.0}
gravity := dora.NewVec2(0.0, -10.0)
const (
group_zero = 0
group_one = 1
Expand All @@ -16,12 +16,12 @@ func test_body() {
polygon_def.SetType(dora.BodyTypeDynamic)
polygon_def.SetLinearAcceleration(gravity)
polygon_def.AttachPolygonWithVertices(&[]dora.Vec2{
dora.Vec2{X: 60.0, Y: 0.0},
dora.Vec2{X: 30.0, Y: -30.0},
dora.Vec2{X: -30.0, Y: -30.0},
dora.Vec2{X: -60.0, Y: 0.0},
dora.Vec2{X: -30.0, Y: 30.0},
dora.Vec2{X: 30.0, Y: 30.0},
dora.NewVec2(60.0, 0.0),
dora.NewVec2(30.0, -30.0),
dora.NewVec2(-30.0, -30.0),
dora.NewVec2(-60.0, 0.0),
dora.NewVec2(-30.0, 30.0),
dora.NewVec2(30.0, 30.0),
}, 1.0, 0.4, 0.4)

disk_def := dora.NewBodyDef()
Expand All @@ -36,15 +36,15 @@ func test_body() {
world.SetShouldContact(group_one, group_two, true)
world.SetShowDebug(true)

body := dora.NewBody(terrain_def, world, dora.Vec2{X: 0.0, Y: 0.0}, 0.0)
body := dora.NewBody(terrain_def, world, dora.Vec2Zero, 0.0)
body.SetGroup(group_two)
world.AddChild(body.Node)

body_p := dora.NewBody(polygon_def, world, dora.Vec2{X: 0.0, Y: 500.0}, 15.0)
body_p := dora.NewBody(polygon_def, world, dora.NewVec2(0.0, 500.0), 15.0)
body_p.SetGroup(group_one)
world.AddChild(body_p.Node)

body_d := dora.NewBody(disk_def, world, dora.Vec2{X: 50.0, Y: 800.0}, 0.0)
body_d := dora.NewBody(disk_def, world, dora.NewVec2(50.0, 800.0), 0.0)
body_d.SetGroup(group_zero)
body_d.SetAngularRate(90.0)
world.AddChild(body_d.Node)
Expand All @@ -61,12 +61,12 @@ func test_body() {
width := dora.App.GetVisualSize().Width
dora.ImGui.SetNextWindowBgAlpha(0.35)
dora.ImGui.SetNextWindowPosOpts(
dora.Vec2{X: width - 10.0, Y: 10.0},
dora.NewVec2(width-10.0, 10.0),
dora.ImGuiCondAlways,
dora.Vec2{X: 1.0, Y: 0.0},
dora.NewVec2(1.0, 0.0),
)
dora.ImGui.SetNextWindowSizeOpts(
dora.Vec2{X: 240.0, Y: 0.0},
dora.NewVec2(240.0, 0.0),
dora.ImGuiCondFirstUseEver,
)
dora.ImGui.BeginOpts("Body", window_flags, func() {
Expand Down
28 changes: 14 additions & 14 deletions Tools/dora-wa/src/contact.wa
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "dora"
import "strconv"

func test_contact() {
gravity := dora.Vec2{X: 0.0, Y: -10.0}
gravity := dora.NewVec2(0.0, -10.0)
world := dora.NewPhysicsWorld()
world.SetShouldContact(0, 0, true)
world.SetShowDebug(true)
Expand All @@ -16,35 +16,35 @@ func test_contact() {
vertices := []dora.Vec2{}
for i := 0; i <= count; i++ {
angle := 2.0 * dora.Math.Pi * f32(i) / f32(count)
vertices = append(vertices, dora.Vec2{X: radius * dora.Math.Cos(angle), Y: radius * dora.Math.Sin(angle)})
vertices = append(vertices, dora.NewVec2(radius*dora.Math.Cos(angle), radius*dora.Math.Sin(angle)))
}
terrain_def.AttachChain(&vertices, 0.4, 0.0)
terrain_def.AttachDiskWithCenter(dora.Vec2{X: 0.0, Y: -270.0}, 30.0, 1.0, 0.0, 1.0)
terrain := dora.NewBody(terrain_def, world, dora.Vec2{X: 0.0, Y: 0.0}, 0.0)
terrain_def.AttachDiskWithCenter(dora.NewVec2(0.0, -270.0), 30.0, 1.0, 0.0, 1.0)
terrain := dora.NewBody(terrain_def, world, dora.NewVec2(0.0, 0.0), 0.0)
terrain.AddTo(world.Node)

platform_def := dora.NewBodyDef()
platform_def.AttachPolygonWithCenter(dora.Vec2{X: 0.0, Y: -80.0}, 120.0, 30.0, 0.0, 1.0, 0.0, 1.0)
platform := dora.NewBody(platform_def, world, dora.Vec2{X: 0.0, Y: 0.0}, 0.0)
platform_def.AttachPolygonWithCenter(dora.NewVec2(0.0, -80.0), 120.0, 30.0, 0.0, 1.0, 0.0, 1.0)
platform := dora.NewBody(platform_def, world, dora.NewVec2(0.0, 0.0), 0.0)
platform.OnContactFilter(func(other: dora.Body) => bool {
return other.GetVelocityY() < 0.0
})
platform.AddTo(world.Node)

draw_node := dora.NewLineWithVecColor(&[]dora.Vec2{
dora.Vec2{X: -20.0, Y: 0.0},
dora.Vec2{X: 20.0, Y: 0.0},
dora.NewVec2(-20.0, 0.0),
dora.NewVec2(20.0, 0.0),
dora.Vec2Zero,
dora.Vec2{X: 0.0, Y: -20.0},
dora.Vec2{X: 0.0, Y: 20.0},
dora.NewVec2(0.0, -20.0),
dora.NewVec2(0.0, 20.0),
}, dora.App.GetThemeColor())
draw_node.AddTo(world.Node)

disk_def := dora.NewBodyDef()
disk_def.SetType(dora.BodyTypeDynamic)
disk_def.SetLinearAcceleration(gravity)
disk_def.AttachDisk(20.0, 5.0, 0.8, 1.0)
disk := dora.NewBody(disk_def, world, dora.Vec2{X: 100.0, Y: 200.0}, 0.0)
disk := dora.NewBody(disk_def, world, dora.NewVec2(100.0, 200.0), 0.0)
disk.AddTo(world.Node)
disk.SetAngularRate(-1800.0)
disk.OnContactStart(func(other: dora.Body, point: dora.Vec2, normal: dora.Vec2, enabled: bool) {
Expand All @@ -67,12 +67,12 @@ func test_contact() {
width := dora.App.GetVisualSize().Width
dora.ImGui.SetNextWindowBgAlpha(0.35)
dora.ImGui.SetNextWindowPosOpts(
dora.Vec2{X: width - 10.0, Y: 10.0},
dora.NewVec2(width-10.0, 10.0),
dora.ImGuiCondAlways,
dora.Vec2{X: 1.0, Y: 0.0},
dora.NewVec2(1.0, 0.0),
)
dora.ImGui.SetNextWindowSizeOpts(
dora.Vec2{X: 240.0, Y: 0.0},
dora.NewVec2(240.0, 0.0),
dora.ImGuiCondFirstUseEver,
)
dora.ImGui.BeginOpts("Contact", window_flags, func() {
Expand Down
68 changes: 8 additions & 60 deletions Tools/dora-wa/src/entity_move.wa
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
import "dora"

func test_entity_move() {
/*
let window_flags =
ImGuiWindowFlag::NO_DECORATION |
ImGuiWindowFlag::AlwaysAutoResize |
ImGuiWindowFlag::NoSavedSettings |
ImGuiWindowFlag::NoFocusOnAppearing |
ImGuiWindowFlag::NO_NAV |
ImGuiWindowFlag::NoMove;
let mut imgui_node = Node::new();
imgui_node.schedule(Box::new(move |_| {
let width = App::get_visual_size().width;
ImGui::set_next_window_bg_alpha(0.35);
ImGui::set_next_window_pos_opts(&Vec2::new(width - 10.0, 10.0), ImGuiCond::Always, &Vec2::new(1.0, 0.0));
ImGui::set_next_window_size_opts(&Vec2::new(240.0, 0.0), ImGuiCond::FirstUseEver);
ImGui::begin_opts("ECS System", window_flags, || {
ImGui::text("ECS System (Rust)");
ImGui::separator();
ImGui::text_wrapped("Tap any place to move entities.");
if ImGui::button("Create Random Entity", &Vec2::zero()) {
let mut entity = Entity::new();
entity.set("image", "Image/logo.png");
entity.set("position", Vec2::new(
6.0 * (App::get_rand() % 100) as f32,
6.0 * (App::get_rand() % 100) as f32));
entity.set("direction", 1.0 * (App::get_rand() % 360) as f32);
let speed = 1.0 * (App::get_rand() % 20 + 1) as f32;
entity.set("speed", speed);
}
if ImGui::button("Destroy An Entity", &Vec2::zero()) {
let group = Group::new(&vec!["sprite", "position"]);
group.each(Box::new(|entity| {
let mut entity = entity.clone();
entity.remove("position");
let get_sprite = |e: &Entity| e.get("sprite")?.cast::<Sprite>();
if let Some(mut sprite) = get_sprite(&entity) {
sprite.run_action_def(
ActionDef::sequence(&vec![
ActionDef::scale(0.5, 0.5, 0.0, EaseType::InBack),
ActionDef::event("Destroy", "")
]), false);
sprite.slot("Destroy", Box::new(move |_| {
entity.destroy();
}));
}
true
}));
}
});
false
}));
*/

scene_group := dora.NewGroup(&[]string{"scene"})
position_group := dora.NewGroup(&[]string{"position"})
{
Expand Down Expand Up @@ -154,14 +102,14 @@ func test_entity_move() {
{
entity := dora.NewEntity()
entity.Set("image", "Image/logo.png")
entity.Set("position", dora.Vec2{X: 0.0, Y: 0.0})
entity.Set("position", dora.Vec2Zero)
entity.Set("direction", 45.0)
entity.Set("speed", 4.0)
}
{
entity := dora.NewEntity()
entity.Set("image", "Image/logo.png")
entity.Set("position", dora.Vec2{X: -100.0, Y: 200.0})
entity.Set("position", dora.NewVec2(-100.0, 200.0))
entity.Set("direction", 90.0)
entity.Set("speed", 10.0)
}
Expand All @@ -179,26 +127,26 @@ func test_entity_move() {
width := dora.App.GetVisualSize().Width
dora.ImGui.SetNextWindowBgAlpha(0.35)
dora.ImGui.SetNextWindowPosOpts(
dora.Vec2{X: width - 10.0, Y: 10.0},
dora.NewVec2(width-10.0, 10.0),
dora.ImGuiCondAlways,
dora.Vec2{X: 1.0, Y: 0.0},
dora.NewVec2(1.0, 0.0),
)
dora.ImGui.SetNextWindowSizeOpts(
dora.Vec2{X: 240.0, Y: 0.0},
dora.NewVec2(240.0, 0.0),
dora.ImGuiCondFirstUseEver,
)
dora.ImGui.BeginOpts("ECS System", window_flags, func() {
dora.ImGui.Text("ECS System (Wa)")
dora.ImGui.Separator()
dora.ImGui.TextWrapped("Tap any place to move entities.")
if dora.ImGui.Button("Create Random Entity", dora.Vec2{X: 0.0, Y: 0.0}) {
if dora.ImGui.Button("Create Random Entity", dora.Vec2Zero) {
entity := dora.NewEntity()
entity.Set("image", "Image/logo.png")
entity.Set("position", dora.Vec2{X: 6.0 * f32(dora.App.GetRand()%100), Y: 6.0 * f32(dora.App.GetRand()%100)})
entity.Set("position", dora.NewVec2(6.0*f32(dora.App.GetRand()%100), 6.0*f32(dora.App.GetRand()%100)))
entity.Set("direction", 1.0*f32(dora.App.GetRand()%360))
entity.Set("speed", 1.0*f32(dora.App.GetRand()%20+1))
}
if dora.ImGui.Button("Destroy An Entity", dora.Vec2{X: 0.0, Y: 0.0}) {
if dora.ImGui.Button("Destroy An Entity", dora.Vec2Zero) {
group := dora.NewGroup(&[]string{"sprite", "position"})
group.Each(func(entity: dora.Entity) => bool {
entity.Remove("position")
Expand Down
Loading

0 comments on commit f6aabbd

Please sign in to comment.