summaryrefslogtreecommitdiff
path: root/engine/Dynamic/Descriptors
diff options
context:
space:
mode:
authorPhyscik <mynameisgennadiy@vk.com>2026-01-24 00:25:45 +0500
committerPhyscik <mynameisgennadiy@vk.com>2026-01-24 00:25:45 +0500
commitaa35ce4db5326928cf13c7604014fb7aaaedf203 (patch)
tree12cfdb8020220c9f9727a58c41afd9bf49b27d63 /engine/Dynamic/Descriptors
parent5e7333315ed55c237b28013711c4edefc0b56201 (diff)
Dynamic object loading
Diffstat (limited to 'engine/Dynamic/Descriptors')
-rw-r--r--engine/Dynamic/Descriptors/Objects.go78
-rw-r--r--engine/Dynamic/Descriptors/World.go2
2 files changed, 80 insertions, 0 deletions
diff --git a/engine/Dynamic/Descriptors/Objects.go b/engine/Dynamic/Descriptors/Objects.go
new file mode 100644
index 0000000..92a44d7
--- /dev/null
+++ b/engine/Dynamic/Descriptors/Objects.go
@@ -0,0 +1,78 @@
+package descriptors
+
+import (
+ "encoding/json"
+ "fmt"
+
+ components "github.com/DegustatorPonos/RuinesOfRafdolon/Components"
+ coreobjects "github.com/DegustatorPonos/RuinesOfRafdolon/CoreObjects"
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+const ObjectsDirName string = "Objects"
+
+type ObjectDescriptor struct {
+ Name string
+ Textures []*ObjectTextureBlock
+}
+
+// Maps objects by their IDs
+func MapObjectDescriptors(loaded []*ObjectDescriptor) map[string]*ObjectDescriptor {
+ var outp = make(map[string]*ObjectDescriptor, 0)
+ for _, v := range loaded {
+ outp[v.Name] = v
+ }
+ return outp
+}
+
+func (base *ObjectDescriptor) IsValid() error {
+ if base.Textures == nil {
+ return fmt.Errorf("The textures are not specified")
+ }
+ for i, v := range base.Textures {
+ // The texture was not specified
+ if v.TextureId == nil && len(v.Name) == 0 {
+ return fmt.Errorf("The texture #%d was not specified (neither texture name nor ID)", i)
+ }
+ }
+ return nil
+}
+
+func (base *ObjectDescriptor) Parse() coreobjects.DynamicObject {
+ var outp = coreobjects.DynamicObject{
+ Textures: make([]*coreobjects.TextureBlock, len(base.Textures)),
+ }
+ for i, v := range base.Textures {
+ var texture, err = v.GetTexture()
+ if err != nil {
+ rl.TraceLog(rl.LogWarning, "Failed to get the required by the object %s texture: %s", base.Name, err.Error())
+ continue
+ }
+ outp.Textures[i] = &coreobjects.TextureBlock {
+ Texture: texture,
+ Offset: v.Offset,
+ }
+ }
+ return outp
+}
+
+type ObjectTextureBlock struct {
+ Name string
+ TextureId *uint64
+ Offset rl.Vector2
+}
+
+func (base *ObjectTextureBlock) GetTexture() (*rl.Texture2D, error) {
+ if base.TextureId != nil {
+ return components.Resources.Textures.GetTexture(*base.TextureId)
+ }
+ return components.Resources.Textures.GetTextureByName(base.Name)
+}
+
+func (base *ObjectDescriptor) String() string {
+ var outp, jsonErr = json.Marshal(base)
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse settings: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/Dynamic/Descriptors/World.go b/engine/Dynamic/Descriptors/World.go
index 0a6a7d9..c449ab0 100644
--- a/engine/Dynamic/Descriptors/World.go
+++ b/engine/Dynamic/Descriptors/World.go
@@ -5,6 +5,8 @@ import (
rl "github.com/gen2brain/raylib-go/raylib"
)
+const WorldsDirName string = "Worlds"
+
type WorldDescriptor struct {
Name string
// Deprecated