Пример #1
0
 void OnEnable()
 {
     RuleDatabase.LoadDatabase();
     for (int i = 0; i < RuleDatabase.GetNumOfAssets(); i++)
     {
         foldedOut.Add(false);
     }
 }
Пример #2
0
        public IndexingTests()
        {
            _model = TestHelpers.GetDefaultTestModel();
            _db    = new RuleDatabase();

            foreach (var step in _model.Steps)
            {
                _db.Steps.Insert(step.Adapt <StepEntity>());
                if (step.Choices == null)
                {
                    continue;
                }
                foreach (var choice in step.Choices)
                {
                    var entity = choice.Adapt <ChoiceEntity>();
                    entity.PkStep = _db.Steps.Last().Pk;
                    _db.Choices.Insert(entity);
                }
            }
        }
Пример #3
0
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 1200, 500), EditorStyles.helpBox);
        _scrollPositionBottom = EditorGUILayout.BeginScrollView(_scrollPositionBottom, true, true);

        EditorGUILayout.LabelField("Rules:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField(" -S: second input item doesn't need to be selected. -I: main output goes straight to inventory. #Rules: " + RuleDatabase.GetNumOfAssets()); // +
        //"-A: rule is executed automatically. ");
        if (GUILayout.Button("Add New Rule", GUILayout.ExpandWidth(false)))
        {
            foldedOut.Add(false);
            RuleDatabase.CreateAsset();
        }



        for (int ruleIndx = 0; ruleIndx < RuleDatabase.GetNumOfAssets(); ruleIndx++)
        {
            Rule rule = RuleDatabase.GetAsset(ruleIndx);
            EditorUtility.SetDirty(rule);
            string additionalProperties = "";       //Addition - indicating Rule properties:
            if (rule.selectedInput)
            {
                additionalProperties += " -S ";     //Second input item does not need to be selected
            }
            if (rule.inventory)
            {
                additionalProperties += " -I ";     //First output item is spawned directly in the inventory
            }

            /*if (rule.automatic)
             *  additionalProperties += " -A ";  *///Such rules are excuted automatically
            if (rule.ruleNumber != GetFileNameShort(rule))
            {
                rule.ruleNumber = GetFileNameShort(rule);
            }
            string ruleNumber = "#" + rule.ruleNumber + ": ";
            foldedOut[ruleIndx] = EditorGUILayout.Foldout(foldedOut[ruleIndx], ruleNumber + rule.GetRuleAsString() + additionalProperties);

            if (foldedOut[ruleIndx])
            {
                // === OUTPUT ===
                EditorGUILayout.LabelField("Output:", EditorStyles.boldLabel);

                for (int outputIndx = 0; outputIndx < rule.outputs.Count; outputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term output = rule.outputs[outputIndx];
                    output.name = EditorGUILayout.TextArea(output.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteOutputAtIndex(outputIndx);
                    }
                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < output.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(output.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            output.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        output.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddOutput();
                }

                // === ACTION ===
                EditorGUILayout.LabelField("Action:", EditorStyles.boldLabel);
                rule.action = EditorGUILayout.TextArea(rule.action);

                // === INPUT ===
                EditorGUILayout.LabelField("Input:", EditorStyles.boldLabel);

                for (int inputIndx = 0; inputIndx < rule.inputs.Count; inputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term input = rule.inputs[inputIndx];
                    input.name = EditorGUILayout.TextArea(input.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteInputAtIndex(inputIndx);
                    }

                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < input.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(input.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            input.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        input.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }


                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddInput();
                }


                // === InIventory ===                   (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Input doesn't need to be selected:", EditorStyles.boldLabel);
                rule.selectedInput = EditorGUILayout.Toggle(rule.selectedInput);
                EditorGUILayout.EndHorizontal();

                // === Straight to Inventory ===        (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("First output goes straight to inventory:", EditorStyles.boldLabel);
                rule.inventory = EditorGUILayout.Toggle(rule.inventory);
                EditorGUILayout.EndHorizontal();

                /*// === Automatic Rule ===        (addition)       This is a starting point for including rules which can be executed without player interaction
                 * EditorGUILayout.BeginHorizontal();
                 * EditorGUILayout.LabelField("Automatically executed rule:", EditorStyles.boldLabel);
                 * rule.automatic = EditorGUILayout.Toggle(rule.automatic);
                 * EditorGUILayout.EndHorizontal();
                 */
                if (GUILayout.Button("Delete Rule", GUILayout.ExpandWidth(false)))
                {
                    RuleDatabase.DeleteAsset(ruleIndx);
                }
            }
        }

        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();
    }
Пример #4
0
 public string GetFileName(Rule rule)
 {
     return(RuleDatabase.GetPath(rule));
 }
Пример #5
0
    // Use this for initialization

    // Rule Key
    void Awake()
    {
        if (RDBcontrol == null)
        {
            DontDestroyOnLoad(gameObject);
            RDBcontrol = this;
        }
        else if (RDBcontrol != this)
        {
            print("RDB Destroyed");
            Destroy(gameObject);
        }

        // ID Key:  Rule List Number / Wall Color Effected / Second Color Effected / Primary Color Effected
        rules.Add(new Rule(1000, "In general, match a key with the same colored lock.", 0, 0));
        rules.Add(new Rule(1021, "Color1 keys now go to Color2 locks and Color2 keys go into Color1 locks.", 1, 0));
        rules.Add(new Rule(1045, "Color4 keys now go to Color5 locks and Color5 keys go into Color4 locks.", 1, 0));
        rules.Add(new Rule(1111, "Color1 locks within 2 spaces of a Color1 wall use Color1 keys, despite other rules.", 1, 0));
        rules.Add(new Rule(5555, "Color5 locks within 2 spaces of a Color5 wall use Color5 keys, despite other rules.", 1, 0));

        //___________________________
        rules.Add(new Rule(1001, "Color1 locks in the center row or center column are bombs. ", 2, 0));
        rules.Add(new Rule(2001, "Color1 locks against the sides of the grid are all bombs if the exact center lock is Color1.", 2, 0));
        rules.Add(new Rule(3401, "Color1 locks are bombs if a Color4 wall is on the same half of the grid.", 3, 0));
        rules.Add(new Rule(4031, "Color1 locks on the same row as a Color3 lock are bombs.", 2, 0));
        rules.Add(new Rule(5011, "Color1 locks are all bombs if all corners are Color1 locks.", 2, 0));
        //___________________________


        rules.Add(new Rule(1502, "Color2 locks on the side of the grid opposite of a Color5 wall are bombs.", 2, 0));
        rules.Add(new Rule(2052, "Color2 locks next to Color5 locks are bombs.", 2, 0));
        rules.Add(new Rule(3002, "Color2 locks next to a blank space are bombs.", 2, 0));
        rules.Add(new Rule(4202, "Color2 locks next to a Color2 wall are bombs.", 2, 0));
        rules.Add(new Rule(5052, "Color2 locks between two Color5 locks are a solution, despite any other rule!", 2, 0));
        //___________________________

        rules.Add(new Rule(1003, "Color3 locks are all bombs.", 2, 0));
        rules.Add(new Rule(2003, "Color3 bomb exception: Color3 locks in the corner are solutions!", 2, 0));
        rules.Add(new Rule(3033, "Color3 bomb exception: Color3 locks where all four adjacent sides are Color3 locks are solutions!", 2, 0));
        rules.Add(new Rule(4003, "Color3 bomb Exception: A Color3 lock in the exact center of the grid is an answer!", 2, 0));
        rules.Add(new Rule(5203, "Color3 bomb exception: Color3 locks next to a Color2 wall are solutions!", 2, 0));
        //___________________________

        rules.Add(new Rule(1004, "Color4 locks in a corner are bombs.", 2, 0));
        rules.Add(new Rule(2404, "Color4 locks on the opposite half of the grid from a Color4 wall are bombs.", 2, 0));
        rules.Add(new Rule(3014, "Color4 locks next to a Color1 lock are bombs.", 2, 0));
        rules.Add(new Rule(4034, "Color4 locks on the same row or column as a Color3 lock are bombs.", 2, 0));
        rules.Add(new Rule(5004, "Color4 locks on the same half of the grid as a Color1 wall are bombs.", 2, 0));

        //___________________________
        rules.Add(new Rule(1025, "Color5 locks next to a Color2 lock is a bomb.", 2, 0));
        rules.Add(new Rule(2405, "Color5 locks on the same half of the grid as a Color4 wall are bombs.", 2, 0));
        rules.Add(new Rule(3005, "Color5 locks away from the sides of the grid are bombs if the exact center lock of the grid is Color5.", 2, 0));
        rules.Add(new Rule(4205, "Color5 locks against the side of the grid opposite from a Color2 wall are bombs.", 2, 0));
        rules.Add(new Rule(5035, "Color5 locks in the same column as a Color3 lock are bombs.", 2, 0));

        //___________________________


        MaxRules = rules.Count;
    }