Ejemplo n.º 1
0
 public ViewModelJsonConverter(bool isPostback, JObject encryptedValues = null)
 {
     IsPostback      = isPostback;
     EncryptedValues = encryptedValues ?? new JObject();
     evReader        = EncryptedValuesReader.FromObject(EncryptedValues);
     evWriter        = new EncryptedValuesWriter(EncryptedValues.CreateWriter());
 }
Ejemplo n.º 2
0
 public ViewModelJsonConverter(bool isPostback, IViewModelSerializationMapper viewModelSerializationMapper, JObject encryptedValues = null)
 {
     IsPostback      = isPostback;
     EncryptedValues = encryptedValues ?? new JObject();
     evReader        = EncryptedValuesReader.FromObject(EncryptedValues);
     evWriter        = new EncryptedValuesWriter(EncryptedValues.CreateWriter());
     this.viewModelSerializationMapper = viewModelSerializationMapper;
 }
Ejemplo n.º 3
0
 public ViewModelJsonConverter(bool isPostback, IViewModelSerializationMapper viewModelSerializationMapper, JObject encryptedValues = null)
 {
     IsPostback      = isPostback;
     EncryptedValues = encryptedValues ?? new JObject();
     evReader        = new Lazy <EncryptedValuesReader>(() => {
         evWriter = new Lazy <EncryptedValuesWriter>(() => { throw new Exception("Can't use EncryptedValuesWriter at the same time as EncryptedValuesReader."); });
         return(new EncryptedValuesReader(EncryptedValues));
     });
     evWriter = new Lazy <EncryptedValuesWriter>(() => {
         evReader = new Lazy <EncryptedValuesReader>(() => { throw new Exception("Can't use EncryptedValuesReader at the same time as EncryptedValuesWriter."); });
         return(new EncryptedValuesWriter(EncryptedValues.CreateWriter()));
     });
     this.viewModelSerializationMapper = viewModelSerializationMapper;
 }
Ejemplo n.º 4
0
    public void Start()
    {
        Instance    = this;
        NeedyModule = GetComponent <KMNeedyModule>();
        Audio       = GetComponent <KMAudio>();

        OperandGameObject = OperandScreen.Traverse("Operand");
        Submission        = SubmissionScreen.Traverse <TextMesh>("Submission");
        moduleID          = idCounter++;

        // Setup the buttons
        for (int i = 0; i < 12; i++)
        {
            KMSelectable selectable = Numberpad[i];
            selectable.AddInteract(() =>
            {
                if (NotInteractable)
                {
                    return(false);
                }

                Audio.PlaySoundAtTransform("ButtonPress", transform);
                UserInput += selectable.gameObject.Traverse <TextMesh>("ButtonText").text;

                return(true);
            });
        }

        ClearButton.AddInteract(() =>
        {
            if (NotInteractable)
            {
                return(false);
            }

            Audio.PlaySoundAtTransform("ButtonPress", transform);
            UserInput = null;
            return(true);
        });

        SubmitButton.AddInteract(() =>
        {
            if (NotInteractable)
            {
                return(false);
            }

            decimal result;
            if (decimal.TryParse(UserInput, out result) && result == CurrentOperand.Value)
            {
                Audio.PlaySoundAtTransform("Solve", transform);
            }
            else
            {
                Audio.PlaySoundAtTransform("Strike", transform);
                NeedyModule.HandleStrike();
            }
            isSolved = true;
            NeedyModule.HandlePass();
            SetDisplayVisiblity(false);

            return(true);
        });

        NeedyModule.OnNeedyActivation = () =>
        {
            isSolved  = false;
            UserInput = null;

            // Generate up to 1000 operands until we get one that doesn't throw an exception.
            for (int i = 0; i < 1000; i++)
            {
                try
                {
                    CurrentOperand = Operand.Generate();
                    decimal OperandValue = CurrentOperand.Value;
                }
                catch (OverflowException)
                {
                    // An overflow probably can't happen with a single operand, but it doesn't hurt.
                    CurrentOperand = null;
                }
                catch (Exception exception)
                {
                    Log("Unexpected exception occured, solving module: ");
                    Debug.LogException(exception);
                    NeedyModule.HandlePass();
                    return;
                }

                if (CurrentOperand != null)
                {
                    break;
                }
            }

            // If we weren't able to generate a valid operand, force solve.
            if (CurrentOperand == null)
            {
                Log("Unable to generate a valid operand, solving module.");
                NeedyModule.HandlePass();
                return;
            }

            Log("Operand:\n" + CurrentOperand.LogMessage.PrefixLines(" - "));

            CurrentOperand.Display(OperandGameObject);
            SetDisplayVisiblity(true);
        };

        NeedyModule.OnNeedyDeactivation = () => SetDisplayVisiblity(false);
        NeedyModule.OnTimerExpired      = () =>
        {
            NeedyModule.HandleStrike();
            SetDisplayVisiblity(false);
        };
    }