public void LoadWorld(TileMapList tileMaps, ReadonlyEntityPackage entityPackage) { this._ready = false; this._tileMaps = tileMaps ?? throw new ArgumentNullException(nameof(tileMaps), "Attempted to load world with no tilemaps."); this._entityPackage = entityPackage; this._entityIDToDrawPackage = new Dictionary <int, EntityDrawPackage>(); foreach (Entity entity in this._entityPackage.entitiesByID.Values) { string spritePath = entity.fullSprite.Texture.ResourcePath; string spritePathPrefix = spritePath.Substr(0, spritePath.FindLast(".")); Texture spriteSheet = spritePathPrefix.OpenSplitSpriteImage(); GD.PrintS("new img sprite sheet rid: " + spriteSheet.GetRid().GetId()); List <SplitSpriteInfo> spriteSheetInfo = spritePathPrefix.OpenSplitSpriteJson(); int entityID = entity.GetRid().GetId(); GD.PrintS("id: " + entityID); var splitSpriteSheet = new SplitSpriteSheet(spriteSheet, spriteSheetInfo); GD.PrintS(splitSpriteSheet.GetAnyInfo().First().size); var idToSplitNodes = new Dictionary <int, Node2D>(); List <SplitSpriteSheetValue> splitInfo = splitSpriteSheet.GetAnyInfo(); foreach (SplitSpriteSheetValue info in splitInfo) { var splitNode2D = new Node2D(); idToSplitNodes[info.splitIndex] = splitNode2D; } this._entityIDToDrawPackage.Add(entityID, new EntityDrawPackage(entityID, splitSpriteSheet, idToSplitNodes, entity.fullSprite.Offset)); entity.fullSprite.Hide(); } this._ready = true; }
/// <summary> /// Load a world by setting this class to track its Entities. /// TODO figure out whether deferred-queue is enough to ensure this loads after every other world-reliant function is finished so nothing funny happens like we load a world before an Area2D exit callback finishes and crashes the game /// TODO if yes, PULL latch in this func to prevent async funcs and entities moving, AND have the async funcs use a stack of tokens or something that this func needs to wait for it to be empty before continuing /// </summary> /// <param name="tileMaps">A list of all TileMaps in the world.</param> public void LoadWorld(TileMapList tileMaps, ReadonlyEntityPackage entityPackage) { this._floorConstructedToken = this._toPhysicsHub.Subscribe <FloorsConstructedMessage>((msg) => this._HandleFloorsConstructed(msg)); this._areaMonitorsSetupToken = this._toPhysicsHub.Subscribe <AreaMonitorsSetupMessage>((msg) => this._waitPhysicsSteps = 1); this._area2DCallbackToken = this._toPhysicsHub.Subscribe <Area2DCallbackMessage>((msg) => this._HandleArea2DCallback(msg)); this._entityPackage = entityPackage; this._entityIDToZPigeonhole = new Dictionary <int, EntityZPigeonhole>(); this._tileMaps = tileMaps ?? throw new ArgumentNullException(nameof(tileMaps), "Attempted to load world with no tilemaps."); this._ready = false; this._waitPhysicsSteps = 0; }
private void _LoadWorld() { var worldNode = (Node2D)this.GetNode(Globals.WorldNodeName); var children = new List <Node>(worldNode.GetChildren().OfType <Node>()); (TileMapList tileMaps, PerimeterData perimData, LedgeData ledgeData) = TileProcessorModule.TileProcessor.BuildTileNodes(children); this._entityBirthDeathHandler.LoadWorld(tileMaps); ReadonlyEntityPackage entityPackage = this._entityBirthDeathHandler.GetEntityPackage(); this._entityTracker.LoadWorld(tileMaps, entityPackage); this._splitSpritePainter.LoadWorld(tileMaps, entityPackage); this._physicsControl.LoadWorld(tileMaps, perimData, ledgeData, worldNode.GetWorld2d().Space); }