Add Tween tests
Some checks failed
Lint / lint (push) Failing after 11s

This commit is contained in:
Julien Valverdé
2026-01-04 23:15:21 +01:00
parent a571bc8163
commit cc87f79974
9 changed files with 88 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
declare module "godot" {
interface SceneNodes {
"src/tween/Tween.tscn": {};
}
}

View File

@@ -0,0 +1,6 @@
import Tween from "../../../../src/tween/Tween";
declare module "godot" {
interface ResourceTypes {
"res://src/tween/Tween.tscn": PackedScene<Tween>;
}
}

View File

@@ -0,0 +1,10 @@
import Godot from "godot"
import { Component } from "react-godot-renderer"
export const Control = Component.fromClass(Godot.Control)
export const CenterContainer = Component.fromClass(Godot.CenterContainer)
export const HBoxContainer = Component.fromClass(Godot.HBoxContainer)
export const VBoxContainer = Component.fromClass(Godot.VBoxContainer)
export const Label = Component.fromClass(Godot.Label)
export const CheckBox = Component.fromClass(Godot.CheckBox)

View File

@@ -0,0 +1 @@
uid://c4p5ioay76skq

View File

@@ -0,0 +1,6 @@
import { Control } from "godot"
import { Class } from "react-godot-renderer"
import { TweenRoot } from "./TweenRoot"
export default class Tween extends Class.make(Control, TweenRoot) {}

View File

@@ -0,0 +1 @@
uid://cau87pj31qgqr

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cc4bbuq05f7us"]
[ext_resource type="Script" uid="uid://cau87pj31qgqr" path="res://src/tween/Tween.ts" id="1_cpsg0"]
[node name="Tween" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_cpsg0")

View File

@@ -0,0 +1,45 @@
import Godot, { Vector2 } from "godot"
import { useState } from "react"
import { CenterContainer, CheckBox, HBoxContainer, Label, VBoxContainer } from "../components"
export function TweenRoot() {
const [show, setShow] = useState(false)
return (
<CenterContainer
anchors_preset={Godot.Control.LayoutPreset.PRESET_FULL_RECT}
>
<VBoxContainer>
<HBoxContainer>
<CheckBox
button_pressed={show}
toggled={setShow}
/>
<Label text="Show" />
</HBoxContainer>
{show &&
<Label
anchors_preset={Godot.Control.LayoutPreset.PRESET_CENTER}
text="Hello World!"
ready={async function(this) {
// If the Control node is a child of a [Container] node, the scale will be reset to Vector2(1, 1) when the scene is instantiated.
// To set the Control's scale when it's instantiated, wait for one frame using await get_tree().process_frame then set its [member scale] property.
await this.get_tree().process_frame.as_promise()
this.scale = new Vector2(0, 0)
const tween = this.create_tween()
tween.tween_property(this, "scale", new Godot.Vector2(1, 1), 2)
tween.tween_callback(Godot.Callable.create(() => console.log("Tween done!")))
// await tween.finished.as_promise()
// console.log("Tween done!")
}}
/>
}
</VBoxContainer>
</CenterContainer>
)
}