Skip to content

Commit

Permalink
add GetValue function
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta committed Mar 23, 2024
1 parent b032546 commit b855149
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ func Set[T any](e *Entry, ctype component.IComponentType, component *T) {

// SetValue sets the value of the component.
func SetValue[T any](e *Entry, ctype component.IComponentType, value T) {
c := Get[T](e, ctype)
*c = value
*Get[T](e, ctype) = value
}

// GetValue gets the value of the component.
func GetValue[T any](e *Entry, ctype component.IComponentType) T {
return *Get[T](e, ctype)
}

// Remove removes the component from the entry.
Expand Down
19 changes: 19 additions & 0 deletions entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import (
"github.com/yohamta/donburi"
)

func TestSetValue(t *testing.T) {
var (
transform = donburi.NewComponentType[transformData]()
)
world := donburi.NewWorld()
a := world.Create(transform)
entryA := world.Entry(a)

trData := transformData{
Position: vec2f{10, 20},
}
donburi.SetValue(entryA, transform, trData)
got := donburi.GetValue[transformData](entryA, transform)

if got != trData {
t.Errorf("got: %v, want: %v", got, trData)
}
}

func TestGetComponents(t *testing.T) {
var (
transform = donburi.NewComponentType[transformData]()
Expand Down

0 comments on commit b855149

Please sign in to comment.