Esempio n. 1
0
        public static void moveToStar(this Fleet fleet, StarNode to)
        {
            var starAt = fleet.appearer.state.starAt;

            starAt.value.enterable.removeFleet(fleet);
            to.enterable.addFleet(fleet);
        }
Esempio n. 2
0
        public IEnumerator hydrateState(StarNode starter, StarNodeState state, Transform representationTransform, Transform ChildrenTransform, Dictionary <long, object> stateTable)
        {
            starter.state = state;
            GameManager.idMaker.insertObject(starter, state.id);
            state.positionState.appearTransform      = representationTransform;
            state.asContainerState.childrenTransform = ChildrenTransform;
            state.icon = starIconSprites[0];
            foreach (var connectionRef in state.asContainerState.connections)
            {
                var connection = starConnectionFactory.makeConnection(starter, connectionRef, stateTable);
                state.asContainerState.appearables.Add(connection);
            }
            foreach (var planetRef in state.asContainerState.planets)
            {
                var planet = planetfactory.makePlanet(planetRef, starter, stateTable);
                state.asContainerState.appearables.Add(planet);
                yield return(null);
            }
            var length = state.asContainerState.fleets.Count;

            for (var i = 0; i < length; i++)
            {
                var fleetRef      = state.asContainerState.fleets[i];
                var fleetStateObj = stateTable[fleetRef.id];
                var fleetState    = (FleetState)fleetStateObj;
                var faction       = fleetState.factionOwnedState.belongsTo;
                var factory       = faction.value.fleetFactory;
                var fleet         = factory.hydrateFleet(fleetState, stateTable);
                state.asContainerState.appearables.Add(fleet);
                Debug.Log("created fleet " + fleet.state.id);
            }
        }
Esempio n. 3
0
        private StarConnection _makeConnection(StarNode nodeInstance, Reference <StarNode> referencedStarNode)
        {
            var state = new StarConnectionState()
            {
                appearableState = new State.AppearablePositionState(
                    appearTransform: nodeInstance.appearer.state.appearTransform,
                    position: new Vector3(-99999, -99999, -99999),
                    star: null
                    ),
                strength = Random.Range(.01f, .99f),
                nodes    = new Reference <StarNode>[] { (Reference <StarNode>)nodeInstance, referencedStarNode },
            };
            var infos = new sceneAppearInfo[_sceneToPrefab.Length];

            for (var i = 0; i < _sceneToPrefab.Length; i++)
            {
                infos[i] = new sceneAppearInfo(_sceneToPrefab[i]);
            }
            var conn = nodeInstance.gameObject.AddComponent <StarConnection>();

            state.id = GameManager.idMaker.newId(conn);

            var renderer = new StarConnectionAppearer(conn, infos, state);

            conn.Init(state, renderer);
            return(conn);
        }
Esempio n. 4
0
        private StarConnection _makeConnection(StarNode nodeInstance, StarConnectionState state)
        {
            StarConnection conn;
            var            obj = GameManager.instance.objectTable.get(state.id);

            if (obj == null)
            {
                conn       = nodeInstance.gameObject.AddComponent <StarConnection>();
                conn.state = state;
                state.appearableState.appearTransform = nodeInstance.state.positionState.appearTransform;
                var infos = new sceneAppearInfo[_sceneToPrefab.Length];
                for (var i = 0; i < _sceneToPrefab.Length; i++)
                {
                    infos[i] = new sceneAppearInfo(_sceneToPrefab[i]);
                }
                GameManager.idMaker.insertObject(conn, state.id);

                var renderer = new StarConnectionAppearer(conn, infos, state);
                conn.Init(state, renderer);
            }
            else
            {
                conn = (StarConnection)obj;
            }

            return(conn);
        }
Esempio n. 5
0
        public StarConnection makeConnection(StarNode a, StarNode b)
        {
            var conn = _makeConnection(a, (Reference <StarNode>)b);

            a.enterable.addConnection(conn);
            b.enterable.addConnection(conn);
            return(conn);
        }
Esempio n. 6
0
 private void hydrateState(Planet planet, StarNode star, PlanetState state, Transform parent, Dictionary <long, object> stateTable)
 {
     planet.state = state;
     planet.state.positionState.appearTransform = parent;
     planet.state.positionState.starAt          = star;
     planet.state.icon = planetSprites[Random.Range(0, planetSprites.Length - 1)];
     GameManager.instance.factions.registerPlanetToFaction(planet, state.factionOwnedState.belongsTo.value);
     GameManager.idMaker.insertObject(planet, state.id);
     foreach (var tileRef in state.tileableState.tiles)
     {
         tileFactory.makeTile(tileRef, stateTable);
     }
 }
Esempio n. 7
0
 private StarNodeState makeBaseState(StarNode node, Vector3 position, Transform representationTransform, Transform childrenTransform, string name)
 {
     return(new StarNodeState(
                positionState: new AppearablePositionState(appearTransform: representationTransform, position: position, star: null, isActive: false),
                asContainerState: new StarAsContainerState(childrenTransform),
                actionState: new SelfStateActionState(node),
                namedState: new NamedState(Names.starNames.getName()),
                stamp: new FactoryStamp(),
                id: GameManager.idMaker.newId(node),
                icon: starIconSprites[0],
                factionOwned: new FactionOwnedState()
                ));
 }
Esempio n. 8
0
        private Planet makeTransforms(StarNode starAt, string name, out Transform parent)
        {
            var planetHolder = starAt.state.asContainerState.childrenTransform;
            var parentGo     = new GameObject("planet");

            parentGo.name = name;
            parent        = parentGo.transform;
            parent.SetParent(planetHolder, false);
            var planet = parentGo.AddComponent <Planet>();

            //var collider = planet.gameObject.AddComponent<BoxCollider>();
            //collider.size = new Vector3(3, 3, 3);
            return(planet);
        }
Esempio n. 9
0
        public StarConnection makeConnection(StarNode nodeInstance, Reference <StarNode> referencedStarNode)
        {
            StarConnection conn = null;

            if (referencedStarNode.checkExists())
            {
                conn = referencedStarNode.value.enterable.getConnection(nodeInstance.state.id);
            }
            if (conn == null)
            {
                conn = _makeConnection(nodeInstance, referencedStarNode);
            }
            nodeInstance.enterable.addConnection(conn);
            return(conn);
        }
Esempio n. 10
0
        public Planet makePlanet(StarNode star, Vector3 position, Faction faction)
        {
            var name = Names.planetNames.getName();

            Transform parent;
            var       planet   = makeTransforms(star, name, out parent);
            var       tileable = tileFactory.makeTileManager();

            var state      = makeState(parent, planet, position, star, name, faction, tileable.state);
            var appearable = new SingleSceneAppearer(new sceneAppearInfo(baseStarFab), 3, state.positionState);

            planet.Init(appearable, tileable, state);
            GameManager.instance.factions.registerPlanetToFaction(planet, faction);
            return(planet);
        }
Esempio n. 11
0
        public Planet makePlanet(Reference <Planet> Planetref, StarNode star, Dictionary <long, object> stateTable)
        {
            var       name    = Names.planetNames.getName();
            var       faction = GameManager.instance.user.faction;
            Transform parent;
            var       planet = makeTransforms(star, name, out parent);
            var       state  = (PlanetState)stateTable[Planetref.id];

            hydrateState(planet, star, state, parent, stateTable);
            var tileable = tileFactory.makeTileManager();

            var appearable = new SingleSceneAppearer(new sceneAppearInfo(baseStarFab), 3, state.positionState);

            planet.Init(appearable, tileable, state);
            return(planet);
        }
Esempio n. 12
0
 public StarConnection makeConnection(StarNode starHolder, Reference <StarConnection> connectionRef, Dictionary <long, object> stateTable)
 {
     return(_makeConnection(starHolder, (StarConnectionState)stateTable[connectionRef.id]));
 }
Esempio n. 13
0
        private PlanetState makeState(Transform parent, Planet planet, Vector3 position, StarNode starAt, string name, Faction faction, TileableState tileState)
        {
            var state = new PlanetState(
                positionState: new State.AppearablePositionState(
                    appearTransform: parent,
                    position: position,
                    star: starAt
                    ),
                stamp:  new FactoryStamp(),
                actionState: new SelfStateActionState(planet),
                tileableState: tileState,
                id: GameManager.idMaker.newId(planet),
                namedState: new State.NamedState()
            {
                name = name
            },
                icon: planetSprites[Random.Range(0, planetSprites.Length - 1)],
                factionState: new State.FactionOwnedState()
            {
                belongsTo = faction
            }
                );

            return(state);
        }
Esempio n. 14
0
 public virtual StarConnection makeConnection(StarNode a, StarNode b)
 {
     return(starConnectionFactory.makeConnection(a, b));
 }