예제 #1
0
 public ResourceType(ResourceTypeInfo info, World world)
 {
     Info     = info;
     Variants = new Dictionary <string, ISpriteSequence>();
     foreach (var v in info.Sequences)
     {
         var seq = world.Map.Rules.Sequences.GetSequence(Info.Image, v);
         Variants.Add(v, seq);
     }
 }
예제 #2
0
 public ResourceType(ResourceTypeInfo info, World world)
 {
     Info     = info;
     Variants = new Dictionary <string, Sprite[]>();
     foreach (var v in info.Sequences)
     {
         var seq     = world.Map.Rules.Sequences.GetSequence(Info.Image, v);
         var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
         Variants.Add(v, sprites);
     }
 }
예제 #3
0
        public int SetResource(WorldRenderer wr, ResourceTypeInfo resource)
        {
            terrainOrResourceCell = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(Viewport.LastMousePos));

            Type                   = EditorCursorType.Resource;
            Resource               = resource;
            Actor                  = null;
            TerrainTemplate        = null;
            terrainOrResourceDirty = true;

            return(++CurrentToken);
        }
예제 #4
0
        public void Clear(int token)
        {
            if (token != CurrentToken)
            {
                return;
            }

            Type            = EditorCursorType.None;
            Actor           = null;
            TerrainTemplate = null;
            Resource        = null;
        }
예제 #5
0
        public int SetActor(WorldRenderer wr, ActorInfo actor, PlayerReference owner)
        {
            var ios          = actor.TraitInfoOrDefault <IOccupySpaceInfo>();
            var buildingInfo = ios as BuildingInfo;

            actorCenterOffset = buildingInfo?.CenterOffset(world) ?? WVec.Zero;
            actorSharesCell   = ios != null && ios.SharesCell;
            actorSubCell      = SubCell.Invalid;

            // Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners
            var ownerName         = owner.Name;
            var specificOwnerInfo = actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();

            if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
            {
                ownerName = specificOwnerInfo.ValidOwnerNames.First();
            }

            var reference = new ActorReference(actor.Name);

            reference.Add(new OwnerInit(ownerName));
            reference.Add(new FactionInit(owner.Faction));

            var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
            var cell    = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));

            reference.Add(new LocationInit(cell));
            if (ios != null && ios.SharesCell)
            {
                actorSubCell = editorLayer.FreeSubCellAt(cell);
                if (actorSubCell != SubCell.Invalid)
                {
                    reference.Add(new SubCellInit(actorSubCell));
                }
            }

            if (actor.HasTraitInfo <IFacingInfo>())
            {
                reference.Add(new FacingInit(info.PreviewFacing));
            }

            Type            = EditorCursorType.Actor;
            Actor           = new EditorActorPreview(wr, null, reference, owner);
            TerrainTemplate = null;
            Resource        = null;

            return(++CurrentToken);
        }