Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d3496d8c67 |
@@ -3,6 +3,8 @@ from sqlalchemy.dialects.postgresql import ENUM
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
import enum
|
||||
import json
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.database import Base
|
||||
|
||||
@@ -38,3 +40,32 @@ class Asset(Base):
|
||||
|
||||
owner = relationship("User", back_populates="assets")
|
||||
world = relationship("World", back_populates="assets")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Computed properties
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@property
|
||||
def has_gltf_metadata(self) -> bool:
|
||||
"""Return True when metadata_json contains glTF-specific keys.
|
||||
|
||||
glTF metadata is considered present when the stored JSON contains at
|
||||
least one of the keys that *extract_gltf_metadata* produces
|
||||
(mesh_count, vertex_count, has_animation, texture_refs,
|
||||
bounding_box_min, bounding_box_max).
|
||||
"""
|
||||
if not self.metadata_json:
|
||||
return False
|
||||
try:
|
||||
data: dict[str, Any] = json.loads(self.metadata_json)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return False
|
||||
gltf_keys = {
|
||||
"mesh_count",
|
||||
"vertex_count",
|
||||
"has_animation",
|
||||
"texture_refs",
|
||||
"bounding_box_min",
|
||||
"bounding_box_max",
|
||||
}
|
||||
return bool(gltf_keys & data.keys())
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
"""Script model — game logic scripts owned by users and associated with worlds."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, func
|
||||
from sqlalchemy.dialects.postgresql import ENUM, JSONB
|
||||
from sqlalchemy.orm import relationship
|
||||
import enum
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class ScriptType(str, enum.Enum):
|
||||
"""Type of script storage."""
|
||||
GDSCRIPT = "gdscript"
|
||||
DSL = "dsl"
|
||||
|
||||
|
||||
class Script(Base):
|
||||
"""A game script — either raw GDScript source or a DSL payload."""
|
||||
__tablename__ = "scripts"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
world_id = Column(Integer, ForeignKey("worlds.id", ondelete="CASCADE"), nullable=True)
|
||||
owner_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
source_code = Column(Text, nullable=True)
|
||||
version = Column(Integer, nullable=False, server_default="1")
|
||||
script_type = Column(
|
||||
ENUM(ScriptType, name="script_type", create_type=False),
|
||||
nullable=False,
|
||||
default=ScriptType.GDSCRIPT,
|
||||
)
|
||||
dsl_payload = Column(JSONB, nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
owner = relationship("User", back_populates="scripts")
|
||||
world = relationship("World", back_populates="scripts")
|
||||
Reference in New Issue
Block a user