~sjdv1982/hivesystem/trunk

« back to all changes in this revision

Viewing changes to sparta/assessors/compare.py

  • Committer: Sjoerd de Vries
  • Date: 2014-06-09 10:19:38 UTC
  • mfrom: (182.1.43 hive-view)
  • Revision ID: sjdv1982@gmail.com-20140609101938-7ji5g0buo09r0se6
merged with hive-view branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import libcontext, bee
 
2
from bee.segments import *
 
3
from bee.types import stringtupleparser
 
4
 
 
5
class compare(object):
 
6
    """
 
7
    The compare assessor compares two input values
 
8
    """
 
9
    metaguiparams = {
 
10
      "type_" : "str",
 
11
      "autocreate" : {"type_" : "bool"},
 
12
    }
 
13
    @classmethod
 
14
    def form(cls, f):
 
15
        f.type_.name = "Type"
 
16
        f.type_.type = "option"        
 
17
        f.type_.options = "bool", "int", "float", "(str,identifier)", "(str,action)", "(str,keycode)", "(str,message)", "(str,property)", "(str,process)", "str", "(object,matrix)", "(object,bge)", "object", "custom"
 
18
        f.type_.optiontitles = "Bool", "Integer", "Float", "ID String", "Action String", "Key String", "Message String", "Property String", "Process ID String",  "Generic String", "Matrix Object", "BGE Object", "Generic Object", "Custom"
 
19
        f.type_.default = "bool"
 
20
    
 
21
    def __new__(cls, type_):
 
22
        type_ = stringtupleparser(type_)
 
23
        class compare(bee.worker):    
 
24
            __doc__ = cls.__doc__
 
25
            
 
26
            # Comparison mode
 
27
            mode = variable("str")
 
28
            parameter(mode, "equal")
 
29
            
 
30
            # Two input values 
 
31
            inp1 = antenna("pull", type_)            
 
32
            inp2 = antenna("pull", type_)            
 
33
            # One output value returning the result of the comparision
 
34
            outp = output("pull", "bool")
 
35
            result = variable("bool")
 
36
            connect(result, outp)
 
37
            
 
38
            # Whenever the result of the comparison is requested..
 
39
            # ...pull in the input values...
 
40
            b_inp1 = buffer("pull", type_)
 
41
            connect(inp1, b_inp1)
 
42
            pretrigger(result, b_inp1)
 
43
            b_inp2 = buffer("pull", type_)
 
44
            connect(inp1, b_inp2)            
 
45
            pretrigger(result, b_inp2)
 
46
            
 
47
            # ...and then compare the values
 
48
            @modifier
 
49
            def do_compare(self):              
 
50
              if self.mode == "equal":
 
51
                result = (self.b_inp1 == self.b_inp2)
 
52
              elif self.mode == "greater":  
 
53
                result = (self.b_inp1 > self.b_inp2)
 
54
              elif self.mode == "lesser":  
 
55
                result = (self.b_inp1 < self.b_inp2)
 
56
              self.result = result
 
57
            pretrigger(result, do_compare)
 
58
            
 
59
            # Specify names for the comparison mode
 
60
            @staticmethod
 
61
            def form(f):
 
62
                f.mode.name = "Mode"
 
63
                f.mode.type = "option"
 
64
                f.mode.options = "equal", "greater", "lesser"
 
65
                f.mode.optiontitles = "EqualTo", "GreaterThan", "LesserThan"
 
66
                
 
67
            guiparams = {
 
68
              "inp1" : {"name": "Input 1"},
 
69
              "inp2" : {"name": "Input 2"},
 
70
              "outp" : {"name": "Output"},
 
71
            }
 
72
                              
 
73
        return compare
 
74
    
 
 
b'\\ No newline at end of file'