Exemple #1
0
        protected override void link()
        {
            base.link();

            //We need a real template that does not involve sucking an object out of the scene, but whatever for now
            //Kind of safe to use the same object, destroy is safe, and the thread shouldn't execute till later, but otherwise sharing won't work
            //If you add real templates it won't be a problem since you can use those
            //For this using the same object as a template across multiple players seems ok
            var templateObject = Owner.getOtherSimObject(SimObjectTemplate);

            if (templateObject == null)
            {
                blacklist($"Cannot find template object {SimObjectTemplate}");
            }

            template = templateObject.saveToDefinition("");
            ThreadManager.invoke(templateObject.destroy);

            objectStartingRot = template.Rotation;

            var controlsType = this.PlayerId.GetPlayerKeyedType(typeof(FireControls <>));

            controls = Scope.ServiceProvider.GetService(controlsType) as FireControls;
            controls.Fire.FirstFrameDownEvent += Fire_FirstFrameDownEvent;
        }
Exemple #2
0
        private void createInstance(SimObjectDefinition simObject)
        {
            Instance instance = new Instance(simObject.Name, simObject);

            this.addInstance(instance);
            instanceFiles[instance.Name].Modified = true;
        }
        public SimObjectBase createProp(String propName, Vector3 translation, Quaternion rotation)
        {
            if (subScene != null)
            {
                PropDefinition propDef;
                if (prototypes.TryGetValue(propName, out propDef))
                {
                    SimObjectDefinition definition          = propDef.SimObject;
                    Vector3             originalTranslation = definition.Translation;
                    Quaternion          originalRotation    = definition.Rotation;

                    definition.Name        = UniqueKeyGenerator.generateStringKey();
                    definition.Translation = translation;
                    definition.Rotation    = rotation;
                    SimObjectBase instance = definition.register(subScene);
                    medicalController.addSimObject(instance);
                    scene.buildScene();

                    definition.Translation = originalTranslation;
                    definition.Rotation    = originalRotation;
                    return(instance);
                }
                else
                {
                    Log.Error("Could not create prop {0}. The definition cannot be found.", propName);
                }
            }
            else
            {
                Log.Error("Could not create prop {0}. The subscene is null.", propName);
            }
            return(null);
        }
Exemple #4
0
 /// <summary>
 /// Create another SimObject in the scene this object belongs to according to the given definition.
 /// </summary>
 /// <param name="definition">The definition to build.</param>
 /// <returns>The newly create SimObject from the definition.</returns>
 public SimObject createOtherSimObject(SimObjectDefinition definition)
 {
     if (simObjectManager != null)
     {
         return(simObjectManager.createLiveSimObject(definition));
     }
     else
     {
         throw new SimObjectException(String.Format("Could not create another SimObject using {0} because it is not registered.", Name));
     }
 }
Exemple #5
0
        /// <summary>
        /// Create a new SimObjectManagerDefinition that can recreate this
        /// SimObjectManager exactly how it is when this function is called.
        /// </summary>
        /// <returns>A new SimObjectManagerDefinition configured appropriatly.</returns>
        public SimObjectManagerDefinition saveToDefinition()
        {
            SimObjectManagerDefinition definition = new SimObjectManagerDefinition();

            foreach (SimObjectBase simObject in simObjects.Values)
            {
                SimObjectDefinition simObjDef = simObject.saveToDefinition(simObject.Name);
                definition.addSimObject(simObjDef);
            }
            return(definition);
        }
        public void getInitialPosition(String propName, ref Vector3 translation, ref Quaternion rotation)
        {
            PropDefinition propDef;

            if (prototypes.TryGetValue(propName, out propDef))
            {
                SimObjectDefinition definition = propDef.SimObject;
                translation = definition.Translation;
                rotation    = definition.Rotation;
            }
        }
 /// <summary>
 /// Create a new SimObject and add it.
 /// </summary>
 /// <param name="definition">The definition to create.</param>
 /// <returns>A SimObject if one was created. Not returning one does not indicate an error it just means the sim object hasnt been created yet.</returns>
 public SimObject createSimObject(SimObjectDefinition definition)
 {
     simObjectManagerDefiniton.addSimObject(definition);
     if (subScene != null)
     {
         SimObjectBase instance = definition.register(subScene);
         simObjectManager.addSimObject(instance);
         controller.SceneController.createSimObjects();
         return(instance);
     }
     return(null);
 }
Exemple #8
0
 protected PropDefinition(LoadInfo info)
 {
     Name        = info.GetString("Name");
     PrettyName  = info.GetString("PrettyName");
     BrowserPath = info.GetString("BrowserPath");
     simObject   = info.GetValue <SimObjectDefinition>("SimObject");
     trackInfo   = info.GetValue <ShowPropTrackInfo>("TrackInfo");
     if (info.hasValue("PropLicenseId"))
     {
         PropLicenseId = info.GetInt64("PropLicenseId");
     }
 }
Exemple #9
0
 /// <summary>
 /// Create and add a SimObject to this manager. This is used to create
 /// objects after the build process has run during scene execution.
 /// </summary>
 /// <param name="definition">The definition of the object to create.</param>
 public SimObjectBase createLiveSimObject(SimObjectDefinition definition, SceneBuildOptions options = SceneBuildOptions.None)
 {
     if (!simObjects.ContainsKey(definition.Name))
     {
         SimObjectBase simObj = definition.register(subScene);
         addSimObject(simObj);
         subScene.buildScene(options);
         return(simObj);
     }
     else
     {
         throw new SimObjectException(String.Format("Attempted to create a SimObject {0} that already exists in sub scene {1}.", definition.Name, subScene.Name));
     }
 }
Exemple #10
0
        public void pasteCallback(object pasted)
        {
            SimObjectDefinition simObject = (SimObjectDefinition)pasted;

            if (hasInstance(simObject.Name))
            {
                String namebase = simObject.Name + " - Copy";
                simObject.Name = namebase;
                int i = 1;
                while (hasInstance(simObject.Name))
                {
                    simObject.Name = namebase + i++;
                }
            }
            createInstance(simObject);
        }
 /// <summary>
 /// Load the SimObject instances from the given XML stream into the
 /// given SimObjectManagerDefinition.
 /// </summary>
 /// <param name="xmlReader">The XML stream to read instances from.</param>
 /// <param name="objectManager">The SimObjectManagerDefinition to fill with the new instances.</param>
 public void loadInstances(XmlReader xmlReader, SimObjectManagerDefinition objectManager)
 {
     while (xmlReader.Read())
     {
         if (xmlReader.NodeType == XmlNodeType.Element)
         {
             if (xmlReader.Name.Equals(SIMOBJECT_ELEMENT))
             {
                 String templatePath          = xmlReader.GetAttribute(TEMPLATE_ATTRIBUTE);
                 SimObjectDefinition template = null;//= templateController.getTemplateFromPath(templatePath);
                 if (template != null)
                 {
                     if (!objectManager.hasSimObject(template.Name))
                     {
                         SimObjectDefinition instance = copySaver.copyObject(template) as SimObjectDefinition;
                         while (!(xmlReader.Name == SIMOBJECT_ELEMENT && xmlReader.NodeType == XmlNodeType.EndElement) && xmlReader.Read())
                         {
                             if (xmlReader.NodeType == XmlNodeType.Element)
                             {
                                 if (xmlReader.Name == ROTATION_ELEMENT)
                                 {
                                     instance.Rotation = readRotation(xmlReader);
                                 }
                                 else if (xmlReader.Name == LOCATION_ELEMENT)
                                 {
                                     instance.Translation = readTranslation(xmlReader);
                                 }
                             }
                         }
                         objectManager.addSimObject(instance);
                     }
                     else
                     {
                         Log.Default.sendMessage("The SimObjectManager already has an instance named {0}. Skipping this instance.", LogLevel.Warning, "Editor", template.Name);
                     }
                 }
                 else
                 {
                     Log.Default.sendMessage("Could not find template {0}. Skipping this instance.", LogLevel.Warning, "Editor", templatePath);
                 }
             }
         }
     }
 }
Exemple #12
0
        protected override void link()
        {
            base.link();

            //We need a real template that does not involve sucking an object out of the scene, but whatever for now
            var templateObject = Owner.getOtherSimObject(SimObjectTemplate);

            if (templateObject == null)
            {
                blacklist($"Cannot find template object {SimObjectTemplate}");
            }

            template = templateObject.saveToDefinition("");
            ThreadManager.invoke(templateObject.destroy);

            trigger = Owner.getElement(TriggerName) as Triggerable;
            if (trigger == null)
            {
                blacklist($"Cannot find trigger {TriggerName}");
            }

            trigger.Triggered += Trigger_Triggered;
        }
Exemple #13
0
        private void renameSimObjectCallback(EditUICallback callback)
        {
            callback.getInputString("Enter a name.", delegate(String input, ref String errorPrompt)
            {
                if (input == null || input == "")
                {
                    errorPrompt = "Please enter a non empty name.";
                    return(false);
                }
                if (this.instanceFiles.ContainsKey(input))
                {
                    errorPrompt = "That name is already in use. Please provide another.";
                    return(false);
                }

                InstanceFileInterface instanceFile = callback.getSelectedEditInterface().getEditableProperties().First() as InstanceFileInterface;
                SimObjectDefinition sourceObject   = instanceFile.Instance.Definition;
                SimObjectDefinition simObject      = copySaver.copyObject(sourceObject) as SimObjectDefinition;
                simObject.Name = input;
                createInstance(simObject);
                removeInstanceFile(instanceFile.Name);
                return(true);
            });
        }
Exemple #14
0
 /// <summary>
 /// Remove a SimObjectDefinition to use as a template.
 /// </summary>
 /// <param name="definition">The definition to remove.</param>
 public void removeSimObject(SimObjectDefinition definition)
 {
     simObjects.Remove(definition.Name);
 }
Exemple #15
0
 /// <summary>
 /// Add a SimObjectDefinition to use as a template.
 /// </summary>
 /// <param name="definition">The definition to add.</param>
 public void addSimObject(SimObjectDefinition definition)
 {
     simObjects.Add(definition.Name, definition);
 }
Exemple #16
0
 public Instance(String name, SimObjectDefinition definition)
 {
     this.name        = name;
     this.positionKey = name;
     simObject        = definition;
 }
Exemple #17
0
 public PropDefinition(SimObjectDefinition simObject)
 {
     PrettyName     = Name = simObject.Name;
     this.simObject = simObject;
     trackInfo      = new ShowPropTrackInfo();
 }
Exemple #18
0
 protected Instance(LoadInfo info)
 {
     positionKey = info.GetString("PositionKey");
     name        = info.GetString("Name");
     simObject   = info.GetValue <SimObjectDefinition>("SimObject");
 }
 /// <summary>
 /// Set the SimObjectDefinition for this element.
 /// </summary>
 /// <param name="simObjectDef">The definition to set.</param>
 internal void setSimObjectDefinition(SimObjectDefinition simObjectDef)
 {
     this.simObjectDef = simObjectDef;
 }