Exemplo n.º 1
0
        private void OnEnable()
        {
            Log.Verbose("Starting maintenance mode...");

            room  = Ets.Room;
            pipes = room.GetGame <PipesGame>();

            lighting.SwitchAllLights(LightSetting.On);
            success          = false;
            readInitialState = true;
            record           = new MaintenanceRecord();

            // pipes
            List <int> valvesPerPipeSystem = new List <int>();
            List <int> fansPerPipeSystem   = new List <int>();

            foreach (PipeSystem ps in pipes.PipeSystems())
            {
                valvesPerPipeSystem.Add(ps.ValveCount);
                fansPerPipeSystem.Add(ps.FanCount);
            }

            initialValveStates = new bool[valvesPerPipeSystem.Count][];

            record.valvesPerPipeSystem_Rotating     = new bool[valvesPerPipeSystem.Count][];
            record.valvesPerPipeSystem_StateChanges = new bool[valvesPerPipeSystem.Count][];

            for (int i = 0; i < valvesPerPipeSystem.Count; i++)
            {
                initialValveStates[i] = new bool[valvesPerPipeSystem[i]];
                record.valvesPerPipeSystem_Rotating[i]     = new bool[valvesPerPipeSystem[i]];
                record.valvesPerPipeSystem_StateChanges[i] = new bool[valvesPerPipeSystem[i]];
            }

            record.fansPerPipeSystem = new bool[fansPerPipeSystem.Count][];
            for (int i = 0; i < fansPerPipeSystem.Count; i++)
            {
                record.fansPerPipeSystem[i] = new bool[fansPerPipeSystem[i]];
            }

            foreach (Fan f in pipes.Fans())
            {
                room.Physical.SetFanState(f.Row, f.PositionInRow, true);
            }

            // crane
            record.craneButtons = new bool[CratesGame.ButtonCount];

            // dynamite
            initialHoleStates = new int[DynamiteGame.HoleCount];

            record.holes = new bool[DynamiteGame.HoleCount];

            // trigger
            record.triggerButtons = new bool[TriggersGame.ButtonCount];

            Color[] colors = new Color[TriggersGame.LedCount];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = Color.blue;
            }
            room.Physical.SetLEDColors(colors);

            Log.Verbose("Maintenance mode started. Waiting for input...");
        }
Exemplo n.º 2
0
        public void OnGameStateChanged(Game <IEtsInterface> sender, GameStateChangedEventArgs e)
        {
            if (e.NewState == GameState.Initialized)
            {
                foreach (Image img in gridElementImages.Values)
                {
                    Destroy(img.gameObject);
                }
                gridElementImages.Clear();

                foreach (Fan fan in game.Fans())
                {
                    GameObject go = Instantiate(gridElementPrefab, pnlGrid);
                    go.name  = string.Format("Fan (row={0}, pos={1}, px={2})", fan.Row, fan.PositionInRow, fan.PxCoords);
                    go.layer = LayerMask.NameToLayer("UI");

                    GridElement gridElement = go.GetComponent <GridElement>();
                    gridElement.vertexRow = fan.Row;
                    gridElement.vertexPos = fan.PositionInRow;
                    gridElement.isValve   = false;

                    Image img = go.GetComponent <Image>();
                    img.sprite = fanSprite;
                    img.color  = fan.IsRunning ? activeFan : inactiveFan;

                    RectTransform rect = go.GetComponent <RectTransform>();
                    rect.sizeDelta = img.sprite.rect.size;
                    rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(0, 1);
                    Vector2 offset = new Vector2(-img.sprite.rect.size.x / 2, img.sprite.rect.size.y / 2);
                    rect.anchoredPosition = fan.PxCoords + offset;

                    gridElementImages[fan.PxCoords] = img;
                }

                foreach (Valve valve in game.Valves())
                {
                    GameObject go = Instantiate(gridElementPrefab, pnlGrid);
                    go.name  = string.Format("Valve (row={0}, pos={1}, px={2})", valve.Row, valve.PositionInRow, valve.PxCoords);
                    go.layer = LayerMask.NameToLayer("UI");

                    GridElement gridElement = go.GetComponent <GridElement>();
                    gridElement.vertexRow = valve.Row;
                    gridElement.vertexPos = valve.PositionInRow;
                    gridElement.isValve   = true;

                    Image img = go.GetComponent <Image>();
                    img.sprite = valveSprite;
                    img.color  = valve.IsOpen ? openValve : closedValve;

                    RectTransform rect = go.GetComponent <RectTransform>();
                    rect.sizeDelta = img.sprite.rect.size;
                    rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(0, 1);
                    Vector2 offset = new Vector2(-img.sprite.rect.size.x / 2, img.sprite.rect.size.y / 2);
                    rect.anchoredPosition = valve.PxCoords + offset;

                    gridElementImages[valve.PxCoords] = img;
                }

                lblFanCount.text = string.Format(fanCountStrF, game.RunningFansCount, game.FanCount);
            }
        }