Beispiel #1
0
        static void Main(string[] args)
        {
            var prototypeManager = new PrototypeManager();

            var order1 = new OrderDetails()
            {
                OrderId    = 101,
                OrderItems = new List <string>()
                {
                    "Pizza", "Cake", "Soda"
                },
                TotalValue = 23.50m
            };

            var order2 = new OrderDetails()
            {
                OrderId    = 102,
                OrderItems = new List <string>()
                {
                    "Cheeseburger", "Hamburger", "Soda", "Chicken strips"
                },
                TotalValue = 32.80m
            };

            prototypeManager[$"Order::{order1.OrderId}"] = order1;
            prototypeManager[$"Order::{order2.OrderId}"] = order2;

            var copiedOrder1 = prototypeManager["Order::101"].Clone() as OrderDetails;
            var copiedOrder2 = prototypeManager["Order::102"].Clone() as OrderDetails;

            copiedOrder1.Print();
            copiedOrder2.Print();
        }
        public void AddTestThrowsNullReferenceException454()
        {
            PrototypeManager <IPrototypable> prototypeManager;

            prototypeManager = new PrototypeManager <IPrototypable>();
            this.AddTest <IPrototypable>(prototypeManager, (IPrototypable)null);
        }
    private void PlaceTaskCard(GameObject taskCard)
    {
        if (numberOfTasksCompleted == totalTasksForLevel)
        {
            levelComplete = true;
            if (PrototypeManager.GetInstance().GetCurrentWave().PauseAfterCompletedWave)
            {
                PrototypeManager.GetInstance().AdvanceWave();
            }
        }

        Vector3 newOffset = new Vector3(baseOffset.x, baseOffset.y + (numberOfTasksCompleted * 0.01f), baseOffset.z);

        taskCard.gameObject.tag = "Untagged";
        Destroy(taskCard.GetComponent <PlaceablePickup>());
        Destroy(taskCard.GetComponent <Rigidbody>());
        Destroy(taskCard.GetComponent <Task>());
        Destroy(taskCard.GetComponentInChildren <ParticleSystem>()?.gameObject);
        taskCard.transform.localScale = new Vector3(0.15f, 0.15f, 0.1f);
        taskCard.transform.SetParent(newCardParent.transform);
        objectsInBox.Add(taskCard);

        taskCard.transform.localRotation = Quaternion.Euler(baseRotation);
        taskCard.transform.position      = newCardParent.transform.position + (transform.rotation * newOffset);
        numberOfTasksCompleted++;
    }
Beispiel #4
0
        protected override void ReactWithEntity(IEntity entity, double solutionFraction)
        {
            if (SolutionContainerComponent == null)
            {
                return;
            }

            if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
            {
                return;
            }

            if (entity.TryGetComponent(out InternalsComponent? internals) &&
                internals.AreInternalsWorking())
            {
                return;
            }

            var cloneSolution    = SolutionContainerComponent.Solution.Clone();
            var transferAmount   = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
            var transferSolution = cloneSolution.SplitSolution(transferAmount);

            foreach (var reagentQuantity in transferSolution.Contents.ToArray())
            {
                if (reagentQuantity.Quantity == ReagentUnit.Zero)
                {
                    continue;
                }
                var reagent = PrototypeManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);
                transferSolution.RemoveReagent(reagentQuantity.ReagentId, reagent.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.Quantity));
            }

            bloodstream.TryTransferSolution(transferSolution);
        }
        private protected override Entity CreateEntity(string?prototypeName, EntityUid?uid = null)
        {
            var entity = base.CreateEntity(prototypeName, uid);

            if (prototypeName != null)
            {
                var prototype = PrototypeManager.Index <EntityPrototype>(prototypeName);

                // At this point in time, all data configure on the entity *should* be purely from the prototype.
                // As such, we can reset the modified ticks to Zero,
                // which indicates "not different from client's own deserialization".
                // So the initial data for the component or even the creation doesn't have to be sent over the wire.
                foreach (var(netId, component) in ComponentManager.GetNetComponents(entity.Uid))
                {
                    // Make sure to ONLY get components that are defined in the prototype.
                    // Others could be instantiated directly by AddComponent (e.g. ContainerManager).
                    // And those aren't guaranteed to exist on the client, so don't clear them.
                    if (prototype.Components.ContainsKey(component.Name))
                    {
                        ((Component)component).ClearTicks();
                    }
                }
            }

            return(entity);
        }
Beispiel #6
0
    private void SetColor()
    {
        bool availableTasks       = TaskManager.GetInstance().tasks != null && TaskManager.GetInstance().tasks.Count > 0;
        int  randomChanceForMatch = RandomManager.GetRandomNumber(0, 101);

        if (availableTasks && randomChanceForMatch < PrototypeManager.GetInstance().GetCurrentWave().chanceOfCorrectBodyCombination)
        {
            BodyType taskBodyType = TaskManager.GetInstance().tasks[RandomManager.GetRandomNumber(0, TaskManager.GetInstance().tasks.Count)].Body;
            bodyType = taskBodyType;
        }
        else
        {
            bodyType = (BodyType)Random.Range(0, 3);
        }

        if (bodyType == BodyType.Blue)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.blue;
        }
        else if (bodyType == BodyType.Green)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.green;
        }
        else if (bodyType == BodyType.Red)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.red;
        }
    }
    static void MainRun()
    {
        PrototypeManager manager = new PrototypeManager();
        Prototype        c2, c3;

        // Make a copy of Australia's data
        c2 = manager.prototypes["Australia"].Clone();
        Report("Shallow cloning Australia\n===============",
               manager.prototypes["Australia"], c2);

        // Change the capital of Australia to Sydney
        c2.Capital = "Sydney";
        Report("Altered Clone's shallow state, prototype unaffected",
               manager.prototypes["Australia"], c2);

        // Change the language of Australia (deep data)
        c2.Language.Data = "Chinese";
        Report("Altering Clone deep state: prototype affected *****",
               manager.prototypes["Australia"], c2);

        // Make a copy of Germany's data
        c3 = manager.prototypes["Germany"].DeepCopy();
        Report("Deep cloning Germany\n============",
               manager.prototypes["Germany"], c3);

        // Change the capital of Germany
        c3.Capital = "Munich";
        Report("Altering Clone shallow state, prototype unaffected",
               manager.prototypes["Germany"], c3);

        // Change the language of Germany (deep data)
        c3.Language.Data = "Turkish";
        Report("Altering Clone deep state, prototype unaffected",
               manager.prototypes["Germany"], c3);
    }
Beispiel #8
0
    private void SetColor()
    {
        MeshRenderer[] meshRenderer = GetComponentsInChildren <MeshRenderer>();

        bool availableTasks       = TaskManager.GetInstance().tasks != null && TaskManager.GetInstance().tasks.Count > 0;
        int  randomChanceForMatch = RandomManager.GetRandomNumber(0, 101);

        if (availableTasks && randomChanceForMatch < PrototypeManager.GetInstance().GetCurrentWave().chanceOfCorrectBodyCombination)
        {
            HeadType taskHeadType = TaskManager.GetInstance().tasks[RandomManager.GetRandomNumber(0, TaskManager.GetInstance().tasks.Count)].Head;
            headType = taskHeadType;
        }
        else
        {
            headType = (HeadType)Random.Range(0, 3);
        }

        for (int i = 0; i < meshRenderer.Length; i++)
        {
            if (headType == HeadType.Blue)
            {
                meshRenderer[i].material.color = Color.blue;
            }
            else if (headType == HeadType.Green)
            {
                meshRenderer[i].material.color = Color.green;
            }
            else if (headType == HeadType.Red)
            {
                meshRenderer[i].material.color = Color.red;
            }
        }
    }
        /// <summary>
        /// 原型管理器
        /// </summary>
        static void PrototypeManager()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //创建原型管理器
            PrototypeManager prototypeManager = new PrototypeManager();

            stopwatch.Stop();
            Console.WriteLine($"原型管理器{Environment.NewLine}-------------------------------------------");
            Console.WriteLine($"Load用时:{stopwatch.Elapsed.TotalMilliseconds}ms");
            stopwatch.Restart();

            //创建实例
            Kit kit = prototypeManager.CreateInstance("LogitechKit") as Kit;

            stopwatch.Stop();
            Console.WriteLine($"CreateInstance用时:{stopwatch.Elapsed.TotalMilliseconds}ms");
            Console.WriteLine($"当前套装内的鼠标是:{kit.Mouse.GetBrand()}");
            Console.WriteLine($"当前套装内的键盘是:{kit.Keyboard.GetBrand()}");

            //创建原型并添加至原型管理器
            Kit razeKit = new Kit();

            razeKit.Mouse    = new RazeMouse();
            razeKit.Keyboard = new RazeKeyboard();
            prototypeManager.AddPrototype("RazeKit", razeKit);
            Console.ReadKey();
        }
Beispiel #10
0
        //LD_PROTOTYPE_000
        public static void RunPrototypeCreationalPattern()
        {
            Configuration c         = new Configuration();
            DateTime      startTime = DateTime.Now;

            c.GetFileInformation();  //takes long time to create the first time
            DateTime endTime = DateTime.Now;

            Console.WriteLine("First Configuration object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            UserProfile p = new UserProfile();

            startTime = DateTime.Now;
            p.GetDatabaseInformation();  //takes long time to create the first time
            endTime = DateTime.Now;
            Console.WriteLine("First UserProfile object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            //add prototypes to the manager
            PrototypeManager manager = new PrototypeManager();

            manager.AddPrototype(c, 0);
            manager.AddPrototype(p, 1);

            startTime = DateTime.Now;
            (manager.GetPrototype(0).Clone() as Configuration).ShowInformation();  //new prototype copy
            endTime = DateTime.Now;
            Console.WriteLine("Second Configuration object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            startTime = DateTime.Now;
            (manager.GetPrototype(1).Clone() as UserProfile).ShowInformation();  //new prototype copy
            endTime = DateTime.Now;
            Console.WriteLine("Second UserProfile object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");
        }
Beispiel #11
0
    public override void Started()
    {
        base.Started();

        // TODO: "safe random" for chems. Right now this includes admin chemicals.
        var allReagents = PrototypeManager.EnumeratePrototypes <ReagentPrototype>()
                          .Where(x => !x.Abstract)
                          .Select(x => x.ID).ToList();

        // This is gross, but not much can be done until event refactor, which needs Dynamic.
        var sound = new SoundPathSpecifier("/Audio/Effects/extinguish.ogg");

        foreach (var(_, transform) in EntityManager.EntityQuery <GasVentPumpComponent, TransformComponent>())
        {
            var solution = new Solution();

            if (!RobustRandom.Prob(0.33f))
            {
                continue;
            }

            if (RobustRandom.Prob(0.05f))
            {
                solution.AddReagent(RobustRandom.Pick(allReagents), 100);
            }
            else
            {
                solution.AddReagent(RobustRandom.Pick(SafeishVentChemicals), 100);
            }

            FoamAreaReactionEffect.SpawnFoam("Foam", transform.Coordinates, solution, RobustRandom.Next(2, 6), 20, 1,
                                             1, sound, EntityManager);
        }
    }
Beispiel #12
0
        static void Main(string[] args)
        {
            PrototypeManager manager = new PrototypeManager();
            Prototype        c2, c3;

            c2 = manager.prototypes["Australia"].Clone();
            Report("Shallow cloning Australia\n=========", manager.prototypes["Australia"], c2);

            c2.Capital = "Sydney";
            Report("Altered Clone's shallow state, prototype unaffected", manager.prototypes["Australia"], c2);

            c2.Language.Data = "Chinese";
            Report("Altering Clone deep state: prototype affected", manager.prototypes["Australia"], c2);


            c3 = manager.prototypes["Germany"].DeepCopy();
            Report("Deep cloning Germany\n=========", manager.prototypes["Germany"], c3);

            c3.Capital = "Munich";
            Report("Altering Clone shallow state, prototype unaffected", manager.prototypes["Germany"], c3);

            c3.Language.Data = "Turkish";
            Report("Altering Clone deep state: prototype unaffected", manager.prototypes["Germany"], c3);

            Console.ReadLine();
        }
        public PrototypeManager <T> ConstructorTest <T>()
            where T : IPrototypable
        {
            PrototypeManager <T> target = new PrototypeManager <T>();

            return(target);
            // TODO: add assertions to method PrototypeManagerTTest.ConstructorTest()
        }
        public void GetTestThrowsKeyNotFoundException394()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            IPrototypable iPrototypable;

            prototypeManager = new PrototypeManager <IPrototypable>();
            iPrototypable    = this.GetTest <IPrototypable>(prototypeManager, "");
        }
        public void GetTestThrowsArgumentNullException708()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            IPrototypable iPrototypable;

            prototypeManager = new PrototypeManager <IPrototypable>();
            iPrototypable    = this.GetTest <IPrototypable>(prototypeManager, (string)null);
        }
Beispiel #16
0
 private static void CreateManager()
 {
     _manager = new PrototypeManager();
     _manager.AddPrototype("ProductA1", new ProductA1());
     _manager.AddPrototype("ProductA2", new ProductA2());
     _manager.AddPrototype("ProductB1", new ProductB1());
     _manager.AddPrototype("ProductB2", new ProductB2());
 }
Beispiel #17
0
 protected AbstractFactory()
 {
     _manager = new PrototypeManager();
     _manager.AddPrototype("ProductA1", new ProductA1());
     _manager.AddPrototype("ProductA2", new ProductA2());
     _manager.AddPrototype("ProductB1", new ProductB1());
     _manager.AddPrototype("ProductB2", new ProductA2());
 }
        public T GetTest <T>([PexAssumeUnderTest] PrototypeManager <T> target, string type)
            where T : IPrototypable
        {
            T result = target.Get(type);

            return(result);
            // TODO: add assertions to method PrototypeManagerTTest.GetTest(PrototypeManager`1<!!0>, String)
        }
    public void Reset()
    {
        levelComplete = false;

        totalTasksForLevel     = PrototypeManager.GetInstance().NrOfTasks;
        numberOfTasksCompleted = 0;
        ClearObjectsInBox();
        //ToggleText(true);
    }
        public void AddTestThrowsArgumentNullException357()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            Building building;

            prototypeManager = new PrototypeManager <IPrototypable>();
            building         = new Building((Building)null);
            building.Tile    = (Tile)null;
            this.AddTest <IPrototypable>(prototypeManager, (IPrototypable)building);
        }
        public void AddTestThrowsArgumentNullException176()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            Projectile projectile;

            prototypeManager    = new PrototypeManager <IPrototypable>();
            projectile          = new Projectile((Projectile)null);
            projectile.Position = default(Vector2);
            projectile.Target   = (Enemy)null;
            this.AddTest <IPrototypable>(prototypeManager, (IPrototypable)projectile);
        }
Beispiel #22
0
        /// <summary>
        /// The method gets notified from the server control and performs any necessary
        /// pre-rendering steps prior to saving view state and rendering content
        /// </summary>
        /// <param name="e">Contains the event data</param>
        protected override void OnPreRender(EventArgs e)
        {
            // Order is important.
            // The control's JavaScript component relies on Prototype being present first.
            PrototypeManager.Load(this.Page);
            JSManager.AddResource(this.Page, typeof(AutoComplete), "NCI.Web.UI.WebControls.FormControls.Resources.AutoComplete.js");
            CssManager.AddResource(this.Page, typeof(AutoComplete), "NCI.Web.UI.WebControls.FormControls.Resources.AutoComplete.css");

            // Register this control to require postback handling when the page
            // is posted back to the server
            Page.RegisterRequiresPostBack(this);
        }
    public void SetUp()
    {
        PrototypeManager.Initialize();

        JToken reader = JToken.Parse(testHeadlineJson);

        PrototypeManager.Headline.LoadJsonPrototypes((JProperty)reader.First);

        gen = new HeadlineGenerator();
        gen.UpdatedHeadline += StringPrinted;
        stringPrinted        = false;
    }
Beispiel #24
0
        public void registerModule()
        {
            String[] classes =
            {
                "org.javarosa.model.xform.XPathReference",
                "org.javarosa.xpath.XPathConditional"
            };

            PrototypeManager.registerPrototypes(classes);
            PrototypeManager.registerPrototypes(XPathParseTool.xpathClasses);
            RestoreUtils.xfFact = new AnonymouseIXFormFactory();
        }
        public void AddTestThrowsArgumentNullException31()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            Job job;

            prototypeManager = new PrototypeManager <IPrototypable>();
            job = new Job((string)null, (Action <Job>)null, (float)0,
                          (string)null, (Func <Tile, bool>)null, 0);
            job.Robot = (Robot)null;
            job.Tile  = (Tile)null;
            this.AddTest <IPrototypable>(prototypeManager, (IPrototypable)job);
        }
Beispiel #26
0
        /// <summary>
        /// Register the control to be notified of postback events.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            ClientScriptManager cs = Page.ClientScript;
            Type myType            = typeof(TwoListSelect);

            // Order is important.
            // The control's JavaScript component relies on Prototype being present first.
            PrototypeManager.Load(this.Page);
            JSManager.AddResource(this.Page, typeof(TwoListSelect), "NCI.Web.UI.WebControls.FormControls.Resources.TwoListSelect.js");

            Page.RegisterRequiresPostBack(this);
            base.OnPreRender(e);
        }
        public void AddTest327()
        {
            PrototypeManager <IPrototypable> prototypeManager;
            Job job;

            prototypeManager = new PrototypeManager <IPrototypable>();
            job = new Job
                      ("", (Action <Job>)null, (float)0, (string)null, (Func <Tile, bool>)null, 0);
            job.Robot = (Robot)null;
            job.Tile  = (Tile)null;
            this.AddTest <IPrototypable>(prototypeManager, (IPrototypable)job);
            Assert.IsNotNull((object)prototypeManager);
        }
 private void UpdateCompletedTasksText()
 {
     if (taskText != null)
     {
         DateTime startTime = PrototypeManager.GetInstance().waveStartTime;
         DateTime endTime   = PrototypeManager.GetInstance().waveStartTime.AddSeconds(PrototypeManager.GetInstance().GetCurrentWave().timelimitForWave);
         TimeSpan timeSpan  = endTime - DateTime.Now;
         string   s         = $"{timeSpan.Minutes:00} : {timeSpan.Seconds:00}";
         taskText.text = $"Tasks Completed\n {numberOfTasksCompleted} / {totalTasksForLevel} " +
                         (PrototypeManager.GetInstance().GetCurrentWave().timeLimit ?
                          $"\n<color=red>Time to complete wave\n{s}</color>" :
                          $"\n<color=red>No time limit.</color>");
     }
 }
        public void Setup()
        {
            _components = IoCManager.Resolve <IComponentFactory>();
            _components.RegisterClass <HotReloadTestComponentOne>();
            _components.RegisterClass <HotReloadTestComponentTwo>();

            IoCManager.Resolve <ISerializationManager>().Initialize();
            _prototypes = (PrototypeManager)IoCManager.Resolve <IPrototypeManager>();
            _prototypes.LoadString(InitialPrototypes);
            _prototypes.Resync();

            _maps     = IoCManager.Resolve <IMapManager>();
            _entities = IoCManager.Resolve <IEntityManager>();
        }
Beispiel #30
0
        public void Setup()
        {
            _components = IoCManager.Resolve <IComponentFactory>();
            _components.RegisterClass <HotReloadTestOneComponent>();
            _components.RegisterClass <HotReloadTestTwoComponent>();
            _components.GenerateNetIds();

            IoCManager.Resolve <ISerializationManager>().Initialize();
            _prototypes = (PrototypeManager)IoCManager.Resolve <IPrototypeManager>();
            _prototypes.RegisterType(typeof(EntityPrototype));
            _prototypes.LoadString(InitialPrototypes);
            _prototypes.Resync();

            _maps     = IoCManager.Resolve <IMapManager>();
            _entities = IoCManager.Resolve <IEntityManager>();
        }
Beispiel #31
0
    public static void Main(string[] args)
    {
        // need a prototype manager
        PrototypeManager manager = new PrototypeManager();
        // prototype manager registers a few prototype
        manager.loadCache();
        // prototype manager can now be used as factory object
        Shape clonedShape1 = manager.GetShape("1");
        clonedShape1.Draw();

        Shape clonedShape2 = manager.GetShape("2");
        clonedShape2.Draw();

        Shape clonedShape3 = manager.GetShape("3");
        clonedShape3.Draw();
    }