Ejemplo n.º 1
0
        /// <summary>
        /// Generates source code for inializiting the content of the current scene (paths, actors).
        /// </summary>
        private void GenerateContent()
        {
            // paths
            foreach (PlatformGameCreator.Editor.GameObjects.Paths.Path path in scene.Paths)
            {
                writer.WriteLine("{");
                GeneratePath(path);
                writer.WriteLine("}");
            }

            // global script
            writer.WriteLine("AddNode(new GlobalSceneActor() { ActorId = 0, Layer = 0});");

            // actors
            foreach (Actor actor in scene.AllActors())
            {
                writer.Write("AddNode(new {0}()", ActorGenerator.GetActorClassName(actor));
                writer.Write(" { ");
                writer.Write("ActorId = {0}, ", actor.Id);
                writer.Write("Layer = {0}f", ActorGenerator.GetLayerIndex(actor));
                writer.WriteLine(" });");
            }

            writer.WriteLine("InitializeActors();");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates the source code in C# for the specified scene.
        /// </summary>
        /// <param name="scene">The scene to generate the source code for.</param>
        /// <param name="textWriter">The <see cref="TextWriter"/> for writing the source code of the scene.</param>
        /// <param name="buildType">Type of the build.</param>
        public void Generate(Scene scene, TextWriter textWriter, BuildType buildType)
        {
            this.scene = scene;
            writer     = textWriter;

            if (actorGenerator == null)
            {
                actorGenerator = new ActorGenerator();
            }

            // scene namespace start
            writer.WriteLine("namespace {0}", GetSceneNamespace(scene));
            writer.WriteLine("{");

            // scene class
            writer.WriteLine("class SceneLevel : GlobalContentForScene");
            writer.WriteLine("{");

            writer.WriteLine("public override void LoadContent()");
            writer.WriteLine("{");
            writer.WriteLine("base.LoadContent();");

            writer.WriteLine("FarseerPhysics.Settings.ContinuousPhysics = {0};", ActorGenerator.GetBool(Project.Singleton.Settings.ContinuousCollisionDetection));
            writer.WriteLine("ConvertUnits.SetDisplayUnitToSimUnitRatio({0}f);", Project.Singleton.Settings.SimulationUnits);
            writer.WriteLine("World.Gravity = new Vector2({0}f, {1}f);", Project.Singleton.Settings.DefaultGravity.X, Project.Singleton.Settings.DefaultGravity.Y);
            writer.WriteLine("BackgroundColor = new Color({0}, {1}, {2});", Project.Singleton.Settings.BackgroundColor.R, Project.Singleton.Settings.BackgroundColor.G, Project.Singleton.Settings.BackgroundColor.B);

            GenerateContent();

            writer.WriteLine("}");

            writer.WriteLine("}");

            // generete actor global script class
            actorGenerator.GenerateGlobalSceneActor(scene.GlobalScript, writer);

            // generate actors classes
            GenerateActors();

            // scene namespace end
            writer.WriteLine("}");
        }