예제 #1
0
    private void recordDynamicState()
    {
        DynamicState ds = new DynamicState();

        foreach (MoveableScript m in moveables)
        {
            switch (m.type)
            {
            case BoardCodes.PLAYER:
                ds.playerPosition = m.GetCoords();
                break;

            case BoardCodes.MIMIC:
                ds.mimicPositions.Add(m.GetCoords());
                break;

            case BoardCodes.MIRROR:
                ds.mirrorPositions.Add(m.GetCoords());
                break;
            }
        }

        foreach (coord b in buttonCoords.Keys)
        {
            if (buttonCoords[b].laser.data.isActive)
            {
                ds.activeButtons.Add(b);
            }
        }

        dynamicStateStack.Push(ds);
        //Debug.Log (ds.toJson ());
        LoggingManager.instance.RecordEvent(LoggingManager.EventCodes.DYNAMIC_STATE, ds.toJson());
    }
예제 #2
0
 private void undo()
 {
     // TODO: Record an undo with logging as an event
     if (dynamicStateStack.Count <= 1)
     {
         return;
     }
     try {
         dynamicStateStack.Pop();
         DynamicState ds = dynamicStateStack.Peek();
         LoggingManager.instance.RecordEvent(LoggingManager.EventCodes.UNDO, ds.toJson());
         //int mimicIdx = 0;
         //int mirrorIdx = 0;
         List <coord> mimicCoords  = ds.mimicPositions.ToList();
         List <coord> mirrorCoords = ds.mirrorPositions.ToList();
         while (moveables.Count > 0)
         {
             MoveableScript ms = moveables[0];
             moveables.RemoveAt(0);
             if (ms is PlayerScript)
             {
                 continue;
             }
             Destroy(ms.gameObject);
         }
         player.SetCoords(ds.playerPosition.col, ds.playerPosition.row);
         player.transform.position = new Vector3(player.GetCoords().col + mapOrigin.x, player.GetCoords().row + mapOrigin.y + player.yOffset);
         moveables.Add(player);
         foreach (coord c in mimicCoords)
         {
             MimicScript m = GameObject.Instantiate(mimic);
             m.SetCoords(c.col, c.row);
             m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f);
             moveables.Add(m);
         }
         foreach (coord c in mirrorCoords)
         {
             MirrorScript m = GameObject.Instantiate(mirror);
             m.SetCoords(c.col, c.row);
             m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f);
             moveables.Add(m);
         }
         foreach (coord c in buttonCoords.Keys)
         {
             if (buttonCoords[c].laser.data.isActive != ds.activeButtons.Contains(c))
             {
                 buttonCoords[c].TogglePressed();
             }
         }
     } catch (InvalidOperationException) {
         //TODO: Actually display this to the user
         Debug.Log("Empty stack, no previous move to undo.");
     }
 }