Ignore:
Timestamp:
07/03/10 22:24:43 (19 months ago)
Author:
tolteque
Message:

o LOMEFC2:

  • New Rules management

TODO: indentation and consistency check

tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lomefc2/me_predicates.lua

    r2078 r2103  
    983983    }, 
    984984     
     985    -- ============================================================= 
     986    -- WARNING: keep these four decorations at the end of the list. 
     987    -- ============================================================= 
     988    { 
     989        name       = "op_startGroup", 
     990        fields     = {}, 
     991        decoration = "(" 
     992    }, 
     993    { 
     994        name       = "op_stopGroup", 
     995        fields     = {}, 
     996        decoration = ")" 
     997    }, 
     998    { 
     999        name       = "op_and", 
     1000        fields     = {}, 
     1001        decoration = " and " 
     1002    }, 
     1003    { 
     1004        name       = "op_or", 
     1005        fields     = {}, 
     1006        decoration = " or " 
     1007    }, 
     1008}; 
     1009 
     1010 
     1011cdata = { 
     1012 
     1013    predicates =  { 
     1014        op_startGroup             = _("("), 
     1015        op_stopGroup              = _(")"), 
     1016        op_and                    = _("and"), 
     1017        op_or                     = _("or"), 
    9851018     
    986     -- for tests 
    987     { 
    988         name = "getLoInterface", 
    989         fields = { 
    990         } 
    991     }, 
    992 }; 
    993  
    994  
    995 cdata = { 
    996  
    997     predicates =  { 
    9981019        c_unit_alive              = _("UNIT ALIVE"), 
    9991020        c_unit_damaged            = _("UNIT DAMAGED"), 
     
    10351056         
    10361057        c_file_exits              = _("FILE EXISTS"), 
    1037          
    1038          
    1039          
    1040          
    1041 --        getLoInterface            = _("GET LO INTERFACE"),       
    10421058    }, 
    10431059 
     
    10851101      for _tmp, v in ipairs(rules) do 
    10861102          local item = U.addListBoxItem(list, getRuleAsText(v, cdata), nil, v) 
    1087  
    1088           if v.operator == "or" then 
     1103          local color 
     1104          if v.decoration then 
     1105              if v.decoration == "(" or v.decoration == ")" then 
     1106                  color = Color.red 
     1107              else 
     1108                  color = Color.blue 
     1109              end 
    10891110              local theme = item:getTheme() 
    1090               theme.normalTheme.text.color = Color.red 
    1091               theme.selectedTheme.text.color = Color.red 
     1111              theme.normalTheme.text.color = color 
     1112              theme.selectedTheme.text.color = color 
    10921113              item:setTheme(theme)   
    10931114          end 
     
    11021123function getRuleAsText(rule, cdata) 
    11031124    local ruleDescr = rule.predicate 
    1104     local str = getPredicateName(ruleDescr, cdata) .. ' (' 
    1105  
    1106     local first = true 
    1107     local needComma = false 
    1108     for _tmp, field in ipairs(ruleDescr.fields) do 
    1109         if needComma then 
    1110             str = str .. ', ' 
    1111         else 
    1112             needComma = true 
     1125    local str = getPredicateName(ruleDescr, cdata) 
     1126    if not ruleDescr.decoration then 
     1127        str = str .. ' (' 
     1128        local first = true 
     1129        local needComma = false 
     1130        for _tmp, field in ipairs(ruleDescr.fields) do 
     1131            if needComma then 
     1132                str = str .. ', ' 
     1133            else 
     1134                needComma = true 
     1135            end 
     1136 
     1137            local text 
     1138            if field.displayFunc then 
     1139                text = field.displayFunc(cdata, rule[field.id]) 
     1140            else 
     1141                text = tostring(rule[field.id]) 
     1142            end 
     1143 
     1144            if first and ruleDescr.firstValueAsName then 
     1145                str = text .. ' (' 
     1146                needComma = false 
     1147            else 
     1148                str = str .. text 
     1149            end 
     1150 
     1151            first = false 
    11131152        end 
    11141153 
    1115         local text 
    1116         if field.displayFunc then 
    1117             text = field.displayFunc(cdata, rule[field.id]) 
    1118         else 
    1119             text = tostring(rule[field.id]) 
    1120         end 
    1121  
    1122         if first and ruleDescr.firstValueAsName then 
    1123             str = text .. ' (' 
    1124             needComma = false 
    1125         else 
    1126             str = str .. text 
    1127         end 
    1128  
    1129         first = false 
    1130     end 
    1131  
    1132     str = str .. ')' 
    1133     return str 
     1154        str = str .. ')' 
     1155      end 
     1156   return str 
    11341157end 
    11351158 
     
    13781401-- copy default values from rule descriptions 
    13791402function setRuleDefaults(rule, descr) 
     1403    -- Remove decoration field if it exists 
     1404    if rule.decoration then 
     1405        rule.decoration = nil 
     1406    end 
     1407     
     1408    -- Insert/Remove decoration according to the rule type 
     1409    if descr.decoration then 
     1410       rule.decoration = descr.decoration 
     1411    elseif rule.decoration then 
     1412       rule.decoration = nil 
     1413    end 
     1414     
    13801415    for _tmp, v in ipairs(descr.fields) do 
    13811416        if not rule[v.id] then 
     
    14961531 
    14971532    for i = 1, #toRemove do 
     1533        base.print("invalid rule" ) 
    14981534        table.remove(rulesList, toRemove[i] - (i - 1)) 
    14991535    end 
Note: See TracChangeset for help on using the changeset viewer.