Beispiel #1
0
    public void SaveAllKeybinds()
    {
        foreach (var b in bufferKeybind)
        {
            KeyScheme.SaveKeycodeToPlayerPrefs(b.Key, b.Value);
            //Lookup.GetBtnText(b.Key).text = Lookup.GetKeycode(b.Key).ToString();
        }

        KeyScheme.LoadKeycodesFromPlayerPrefs();
    }
Beispiel #2
0
    public void Initialize()
    {
        //Reference
        Lookup     = GetComponent <KeyRemappingUILookup>();
        sfxManager = SfxManager.instance;

        //Load keyscheme and update display
        KeyScheme.LoadKeycodesFromPlayerPrefs();
        UpdateAllUiButtonText();
    }
Beispiel #3
0
        /// <summary>
        /// Generates a random hexadecimal string.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="scheme">Scheme to use.</param>
        /// <param name="parity">Parity to use.</param>
        /// <returns>Generated random key.</returns>
        public static string RandomKey(this string text, KeyScheme scheme, Parity parity)
        {
            switch (scheme.GetKeyLength())
            {
            case 16:
                return(RandomKey(text, parity));

            case 32:
                return((RandomKey(text, parity) + RandomKey(text, parity)).MakeParity(parity));

            default:
                return((RandomKey(text, parity) + RandomKey(text, parity) + RandomKey(text, parity)).MakeParity(parity));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Determines the length of a key corresponding to
        /// a key scheme.
        /// </summary>
        /// <param name="scheme">Key scheme.</param>
        /// <returns>Key length.</returns>
        public static int GetKeyLength(this KeyScheme scheme)
        {
            switch (scheme)
            {
            case KeyScheme.SingleLengthKey:
                return(16);

            case KeyScheme.DoubleLengthKeyAnsi:
            case KeyScheme.DoubleLengthKeyVariant:
                return(32);

            default:
                return(48);
            }
        }
        public DynamicEntityInfo(string entityName, IEnumerable<FieldAttribute> fields, IEnumerable<ReferenceAttribute> references, KeyScheme keyScheme, EntityInfo.SerializerDelegate serializer, EntityInfo.DeserializerDelegate deserializer)
        {
            this.Registered = false;
            this.AllowRuntimeChanges = DynamicEntityInfo.CanChangeDefinitionsAtRuntime;

            if (entityName == null || entityName.Length <= 0)
                throw new ArgumentException("EntityName", "A DynamicEntityInfo does not accept a null or empty EntityName");

            var entityAttribute = new EntityAttribute(keyScheme);
            entityAttribute.NameInStore = entityName;
            this.EntityType = typeof(DynamicEntityInfo);
            this.Initialize(entityAttribute, this.EntityType);
            this.Serializer = serializer;
            this.Deserializer = deserializer;
            if (fields != null) this.Fields.AddRange(fields);
            if (references != null) this.References.AddRange(references);
        }
        public static string GetKeySchemeValue(KeyScheme key)
        {
            switch (key)
            {
            case KeyScheme.DoubleLengthKeyAnsi:
                return("X");

            case KeyScheme.DoubleLengthKeyVariant:
                return("U");

            case KeyScheme.SingleDESKey:
                return("Z");

            case KeyScheme.TripleLengthKeyAnsi:
                return("Y");

            case KeyScheme.TripleLengthKeyVariant:
                return("T");

            default:
                throw new Exception("Invalid key scheme");
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the character corresponding to a key scheme.
        /// </summary>
        /// <param name="scheme">Key scheme to get char for.</param>
        /// <returns>Corresponding key scheme character.</returns>
        public static string GetKeySchemeChar(this KeyScheme scheme)
        {
            switch (scheme)
            {
            case KeyScheme.DoubleLengthKeyAnsi:
                return("X");

            case KeyScheme.SingleLengthKey:
                return("Z");

            case KeyScheme.DoubleLengthKeyVariant:
                return("U");

            case KeyScheme.TripleLengthKeyAnsi:
                return("Y");

            case KeyScheme.TripleLengthKeyVariant:
                return("T");

            default:
                throw new InvalidCastException("Invalid key scheme");
            }
        }
Beispiel #8
0
 public PrimaryKeyAttribute(KeyScheme keyScheme)
 {
     KeyScheme    = keyScheme;
     IsPrimaryKey = true;
     AllowsNulls  = false;
 }
Beispiel #9
0
 public void VerifyKeySchemeChar(KeyScheme scheme, string expected)
 {
     Assert.AreEqual(expected, scheme.GetKeySchemeChar());
 }
Beispiel #10
0
 public void TestSchemeLength(KeyScheme scheme, int expected)
 {
     Assert.AreEqual(expected, scheme.GetKeyLength());
 }
Beispiel #11
0
 public void TestToKeyScheme(string text, KeyScheme expected)
 {
     Assert.AreEqual(expected, text.GetKeyScheme());
 }
Beispiel #12
0
 /// <summary>
 /// Parses and validates a key scheme code.
 /// </summary>
 /// <param name="keySchemeCode">Key scheme code.</param>
 /// <param name="mr">Message response to add error code to, if parsing fails.</param>
 /// <param name="scheme">Parsed key scheme.</param>
 /// <returns>True if parsing is successful.</returns>
 protected bool ValidateKeySchemeCode(string keySchemeCode, StreamResponse mr, ref KeyScheme scheme)
 {
     try
     {
         scheme = keySchemeCode.GetKeyScheme();
         return(true);
     }
     catch (Exception)
     {
         mr.Append(ErrorCodes.ER_26_INVALID_KEY_SCHEME);
         return(false);
     }
 }
Beispiel #13
0
 public DynamicEntityInfo(string entityName, IEnumerable <FieldAttribute> fields, IEnumerable <ReferenceAttribute> references, KeyScheme keyScheme)
     : this(entityName, fields, references, keyScheme, null, null)
 {
 }
Beispiel #14
0
 void Awake()
 {
     KeyScheme.LoadKeycodesFromPlayerPrefs();
 }
Beispiel #15
0
        public void VerifyHexKeyCreation(string hexKey, string expectedKey, KeyLength expectedLength, KeyScheme expectedScheme)
        {
            var key = new HexKey(hexKey);

            Assert.AreEqual(expectedKey, key.Key);
            Assert.AreEqual(expectedLength, key.Length);
            Assert.AreEqual(expectedScheme, key.Scheme);
            Assert.AreEqual(key.ToString().StripKeyScheme(), hexKey.ToUpper().StripKeyScheme());
        }
 public DynamicEntityInfo(string entityName, IEnumerable<FieldAttribute> fields, IEnumerable<ReferenceAttribute> references, KeyScheme keyScheme)
     : this(entityName, fields, references, keyScheme, null, null)
 {
 }
Beispiel #17
0
        public static Field GetFieldForAttribute(FieldAttribute attrib, KeyScheme keyScheme)
        {
            Field field = null;

            switch (attrib.DataType)
            {
            case System.Data.DbType.Int32:
                field = new Field <int>(attrib.FieldName);
                if (attrib.IsPrimaryKey)
                {
                    if (keyScheme == KeyScheme.Identity)
                    {
                        // As of 10/28/2013, if a field is a PK, DreamFactory forces it to be an auto-incrementing number
                        field.IsPrimaryKey  = true;
                        field.AutoIncrement = true;
                    }
                }
                break;

            case System.Data.DbType.Int64:
                field = new Field <long>(attrib.FieldName);
                break;

            case System.Data.DbType.Byte:
                field = new Field <byte>(attrib.FieldName);
                break;

            case System.Data.DbType.Int16:
                field = new Field <short>(attrib.FieldName);
                break;

            case System.Data.DbType.String:
            case System.Data.DbType.StringFixedLength:
                field = new Field <string>(attrib.FieldName);
                if (attrib.Length <= 0)
                {
                    field.Length = DefaultStringLength;
                }
                else if (attrib.Length > MaxStringLength)
                {
                    field.Length = MaxStringLength;
                }
                else
                {
                    field.Length = attrib.Length;
                }

                break;

            case System.Data.DbType.Boolean:
                field = new Field <bool>(attrib.FieldName);
                break;

            case System.Data.DbType.Single:
                field           = new Field <float>(attrib.FieldName);
                field.Scale     = attrib.Scale <= 0 ? DefaultDoubleScale : attrib.Scale;
                field.Precision = attrib.Precision <= 0 ? DefaultDoublePrecision : attrib.Precision;
                break;

            case System.Data.DbType.Double:
                field           = new Field <double>(attrib.FieldName);
                field.Scale     = attrib.Scale <= 0 ? DefaultDoubleScale : attrib.Scale;
                field.Precision = attrib.Precision <= 0 ? DefaultDoublePrecision : attrib.Precision;
                break;

            case System.Data.DbType.Decimal:
                field = new Field <decimal>(attrib.FieldName);
//                    field.Scale = attrib.Scale;
//                    field.Precision = attrib.Precision;
                break;

            case System.Data.DbType.DateTime:
                field = new Field <DateTime>(attrib.FieldName);
                break;

            case System.Data.DbType.Time:
                field = new Field <TimeSpan>(attrib.FieldName);
                break;

            case System.Data.DbType.Guid:
            case System.Data.DbType.Binary:
                field = new Field <byte[]>(attrib.FieldName);
                break;

            default:
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                throw new NotSupportedException(string.Format("Field type '{0}' is not supported.", attrib.DataType.ToString()));
            }

            field.AllowsNull = attrib.AllowsNulls;

            return(field);
        }
        public DynamicEntityDefinition(string entityName, IEnumerable <FieldAttribute> fields, KeyScheme keyScheme)
        {
            var entityAttribute = new EntityAttribute(keyScheme);

            entityAttribute.NameInStore = entityName;

            this.EntityType = typeof(DynamicEntityDefinition);
            this.Initialize(entityAttribute, this.EntityType);
            this.Fields.AddRange(fields);

            var k = this.Fields.FirstOrDefault(c => c.IsPrimaryKey);

            if (k != null)
            {
                this.PrimaryKeyColumnName = k.FieldName;
            }
        }
Beispiel #19
0
 /// <summary>
 /// Generates a random key with odd parity.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="scheme">Scheme to use.</param>
 /// <returns>Generated key.</returns>
 public static string RandomKey(this string text, KeyScheme scheme)
 {
     return(RandomKey(text, scheme, Parity.Odd));
 }
Beispiel #20
0
 public EntityAttribute(KeyScheme keyScheme)
 {
     KeyScheme = keyScheme;
 }
Beispiel #21
0
        public DynamicEntityInfo(string entityName, IEnumerable <FieldAttribute> fields, IEnumerable <ReferenceAttribute> references, KeyScheme keyScheme, EntityInfo.SerializerDelegate serializer, EntityInfo.DeserializerDelegate deserializer)
        {
            this.Registered          = false;
            this.AllowRuntimeChanges = DynamicEntityInfo.CanChangeDefinitionsAtRuntime;

            if (entityName == null || entityName.Length <= 0)
            {
                throw new ArgumentException("EntityName", "A DynamicEntityInfo does not accept a null or empty EntityName");
            }

            var entityAttribute = new EntityAttribute(keyScheme);

            entityAttribute.NameInStore = entityName;
            this.EntityType             = typeof(DynamicEntityInfo);
            this.Initialize(entityAttribute, this.EntityType);
            this.Serializer   = serializer;
            this.Deserializer = deserializer;
            if (fields != null)
            {
                this.Fields.AddRange(fields);
            }
            if (references != null)
            {
                this.References.AddRange(references);
            }
        }
 public EntityAttribute(KeyScheme keyScheme)
 {
     KeyScheme = keyScheme;
 }
Beispiel #23
0
    public virtual void changeTarget(BotController bc)
    {
        target = bc;
        if (bc == null)
        {
            gameObject.SetActive(false);
        }
        else
        {
            gameObject.SetActive(true);
            Size = target.instructions.Count;
            GetComponent <SpriteRenderer>().size = Vector2.one * dimension;
            while (target.instructions.Count < Size)
            {
                target.instructions.Add(defaultInstruction);
            }
            //Initialize offset
            float scalar = Mathf.Floor(dimension / 2);
            if (dimension % 2 == 0)
            {
                scalar -= 0.5f;
            }
            offset = Vector2.one * -scalar;
            //Initialize instSprites
            while (instSprites.Count >= Size)
            {
                SpriteRenderer removeSR = instSprites[instSprites.Count - 1];
                instSprites.Remove(removeSR);
                Destroy(removeSR.gameObject);
            }
            int i = 0;
            while (instSprites.Count < Size)
            {
                GameObject instSprite = Instantiate(instructionPrefab);
                instSprite.transform.parent = transform;
                instSprites.Add(instSprite.GetComponent <SpriteRenderer>());
                instSprite.transform.position = indexToPos(i);
                i++;
            }
            prevCursor = -1;
            if (Cursor >= Size)
            {
                Cursor = 0;
            }
            updateDisplay();

            //
            //Show keys
            //
            //Remove previous key buttons
            foreach (KeyButton kb in keyButtons)
            {
                Destroy(kb.gameObject);
            }
            keyButtons.Clear();
            //Hide locked key
            keyButtonLockedObject.SetActive(false);
            //Start process of showing new keys
            Vector2 basePosition = indexToPos(target.instructions.Count);
            if (!Locked)
            {
                //Select key scheme
                KeyScheme keyScheme = keySchemes[keySchemes.Count - 1];
                foreach (KeyScheme ks in keySchemes)
                {
                    if (ks.amountOfKeys == target.alphabet.Count)
                    {
                        keyScheme = ks;
                        break;
                    }
                }
                //Generate new key buttons
                for (i = 0; i < target.alphabet.Count; i++)
                {
                    GameObject keyButton = Instantiate(keyButtonPrefab);
                    keyButton.transform.parent   = transform;
                    keyButton.transform.position =
                        basePosition
                        + new Vector2(
                            i % dimension,
                            -(int)(i / dimension) * 0.5f
                            )
                    ;
                    KeyButton kb = keyButton.GetComponent <KeyButton>();
                    kb.keySR.sprite    = keyScheme.keys[i].keySprite;
                    kb.symbolSR.sprite = target.alphabet[i].symbol;
                    kb.key             = keyScheme.keys[i];
                    keyButtons.Add(kb);
                }
            }
            else
            {
                //Show locked key
                i = 0;
                keyButtonLockedObject.SetActive(true);
                keyButtonLockedObject.transform.position =
                    basePosition
                    + new Vector2(
                        i % dimension,
                        -(int)(i / dimension) * 0.5f
                        )
                ;
            }
        }
    }