-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
282 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package engine | ||
|
||
import ( | ||
"fmt" | ||
"github.com/yohamta/donburi" | ||
"github.com/yohamta/donburi/component" | ||
"github.com/yohamta/donburi/features/transform" | ||
"github.com/yohamta/donburi/filter" | ||
) | ||
|
||
func MustGetParent(entry *donburi.Entry) *donburi.Entry { | ||
parent, ok := transform.GetParent(entry) | ||
if !ok { | ||
panic("parent not found") | ||
} | ||
return parent | ||
} | ||
|
||
func MustFindChildWithComponent(parent *donburi.Entry, componentType component.IComponentType) *donburi.Entry { | ||
entry, ok := transform.FindChildWithComponent(parent, componentType) | ||
if !ok { | ||
panic(fmt.Sprintf("entry not found with component %T", componentType)) | ||
} | ||
return entry | ||
} | ||
|
||
func FindWithComponent(w donburi.World, componentType component.IComponentType) (*donburi.Entry, bool) { | ||
return donburi.NewQuery(filter.Contains(componentType)).First(w) | ||
} | ||
|
||
func MustFindWithComponent(w donburi.World, componentType component.IComponentType) *donburi.Entry { | ||
entry, ok := FindWithComponent(w, componentType) | ||
if !ok { | ||
panic(fmt.Sprintf("entry not found with component %T", componentType)) | ||
} | ||
return entry | ||
} | ||
|
||
type Component[T any] interface { | ||
donburi.IComponentType | ||
Get(entry *donburi.Entry) *T | ||
} | ||
|
||
func MustFindComponent[T any](w donburi.World, c Component[T]) *T { | ||
entry, ok := donburi.NewQuery(filter.Contains(c)).First(w) | ||
if !ok { | ||
panic("MustFindComponent: entry not found") | ||
} | ||
|
||
return c.Get(entry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package engine | ||
|
||
import ( | ||
"github.com/yohamta/donburi" | ||
"github.com/yohamta/donburi/component" | ||
"github.com/yohamta/donburi/features/transform" | ||
) | ||
|
||
func FindChildrenWithComponent(e *donburi.Entry, c component.IComponentType) []*donburi.Entry { | ||
if !e.Valid() { | ||
return nil | ||
} | ||
|
||
children, ok := transform.GetChildren(e) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
var result []*donburi.Entry | ||
for _, child := range children { | ||
if !child.Valid() { | ||
continue | ||
} | ||
|
||
if child.HasComponent(c) { | ||
result = append(result, child) | ||
} | ||
|
||
result = append(result, FindChildrenWithComponent(child, c)...) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package engine | ||
|
||
import "time" | ||
|
||
type IntRange struct { | ||
Min int | ||
Max int | ||
} | ||
|
||
func (r IntRange) Random() int { | ||
return RandomIntRange(r.Min, r.Max) | ||
} | ||
|
||
type FloatRange struct { | ||
Min float64 | ||
Max float64 | ||
} | ||
|
||
func (r FloatRange) Random() float64 { | ||
return RandomFloatRange(r.Min, r.Max) | ||
} | ||
|
||
type DurationRange struct { | ||
Min time.Duration | ||
Max time.Duration | ||
} | ||
|
||
func (r DurationRange) Random() time.Duration { | ||
return time.Duration(RandomIntRange(int(r.Min), int(r.Max))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+8.3 KB
(140%)
...codeproj/project.xcworkspace/xcuserdata/milosz.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.