Ejemplo n.º 1
0
        // Pit Functions


        


   

























        private IEnumerator<bool> Init()
        {

            Skins.Clear();
            ShipData.Clear();
            InitProblemBlockNames.Clear();

            blocks = new List<IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType(blocks, x => x.IsSameConstructAs(Me));


            var sprites = new List<string>();

            foreach (var block in blocks)
            {
                if (block is IMyShipController)
                {
                    var contr = block as IMyShipController;
                    if (contr.CanControlShip)
                    {
                        if (Controller == null)
                        {
                            //Take any controller just to have one.
                            Controller = contr;
                        }
                        if (contr.IsMainCockpit)
                        {
                            //If a main one is defined, use that.
                            Controller = contr;
                        }
                    }
                }

                var surfaceProvider = block as IMyTextSurfaceProvider;
                if (surfaceProvider != null && surfaceProvider.SurfaceCount > 0)
                {
                    //Get all textures, might be needed in the ini parser
                    if (sprites.Count == 0)
                    {
                        surfaceProvider.GetSurface(0).GetSprites(sprites);
                    }

                    //Has Surface, check custom data

                    Ini ini = new Ini(block.CustomData, surfaceProvider.SurfaceCount, sprites, Preloads);
                    //Skins will be added to the Skins list in ParseIni

                    while (true)
                    {
                        if (ini.ParserDone() == true)
                        {
                            break;
                        }
                        else
                        {
                            if (OverInstructionLimit()) yield return true;
                        }
                    }

                    if (!ini.NoErrors)
                    {
                        //TODO
                        InitProblemBlockNames.Add(block.CustomName);
                    }
                    block.CustomData = ini.Processed;

                    foreach (var skinDef in ini.SkinDataList)
                    {
                        if (skinDef.screenId < surfaceProvider.SurfaceCount)
                        {
                            var surface = surfaceProvider.GetSurface(skinDef.screenId);
                            var sm = new SurfaceMath(surface);
                            var meters = new List<IMeter>();
                            foreach (var meter in skinDef.meters)
                            {
                                if (meter.type == Meter.Text)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterText(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Value)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterValue(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Bar)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterBar(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.LineGraph)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterLineGraph(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Meter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.HalfMeter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterHalfMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.ThreeQuaterMeter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterThreeQuaterMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.Sprite)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterSprite(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Action)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterAction(sm, meter, ShipData, blocks, GridTerminalSystem, Me));
                                }

                            }
                            Skins.Add(new Skin(this, surface, sm, block, skinDef, meters));
                        }
                    }

                    /* Adding all isn't what we want.
					for (int i = 0; i < surfaceProvider.SurfaceCount; i++)
					{
						Skins.Add(new Skin(this, surfaceProvider.GetSurface(i), i, block));
					}
					*/
                }
            }

            DrawStateMachine = Draw();
            Initialized++;
            yield return false;
        }