Instantiate.gd 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. extends Node
  2. class_name Instantiate
  3. # Entity
  4. static func CreateEntity(entityType : ActorCommons.Type, data : EntityData, nick : String = "", isManaged : bool = false) -> Entity:
  5. if not data:
  6. return null
  7. var actor : Entity = FileSystem.LoadEntityVariant()
  8. if actor:
  9. actor._init(entityType, data, nick, isManaged)
  10. return actor
  11. static func CreateAgent(spawn : SpawnObject, data : EntityData, nick : String = "") -> BaseAgent:
  12. if spawn == null or data == null:
  13. return null
  14. if nick.is_empty():
  15. nick = data._name
  16. var actor : BaseAgent = null
  17. match spawn.type:
  18. "Npc":
  19. actor = NpcAgent.new(ActorCommons.Type.NPC, data, nick, true)
  20. actor.spawnInfo = spawn
  21. actor.playerScriptPath = spawn.player_script
  22. actor.ownScriptPath = spawn.own_script
  23. "Monster":
  24. actor = MonsterAgent.new(ActorCommons.Type.MONSTER, data, nick, true)
  25. actor.currentOrientation = Vector2(randf_range(-1.0, 1.0), randf_range(-0.3, 1.0))
  26. actor.spawnInfo = spawn
  27. "Player":
  28. actor = PlayerAgent.new(ActorCommons.Type.PLAYER, data, nick, true)
  29. _: assert(false, "Trying to create an agent with a wrong type: " + spawn.type)
  30. return actor
  31. # Drop
  32. static func CreateDrop(cell : BaseCell, pos : Vector2) -> Sprite2D:
  33. var node : Sprite2D = Sprite2D.new()
  34. node.texture = cell.icon
  35. node.position = pos
  36. return node
  37. # Map
  38. static func LoadMapData(mapID : int, ext : String) -> Object:
  39. var mapData : FileData = DB.MapsDB.get(mapID, null)
  40. return FileSystem.LoadMap(mapData._path, ext) if mapData else null