| Line 32: |
Line 32: |
| | end | | end |
| | | | |
| − | function Iterator.equipmentBy(context, n, pred) | + | function Iterator.equipmentBy(context, n, pred, pre) |
| | local predKey = stringKey('pred', context, n) | | local predKey = stringKey('pred', context, n) |
| | if predKey then | | if predKey then |
| Line 53: |
Line 53: |
| | local i = 1 | | local i = 1 |
| | local current = nil | | local current = nil |
| | + | local preFlag = true |
| | return { | | return { |
| | next = function() | | next = function() |
| Line 58: |
Line 59: |
| | local e = collection[i] | | local e = collection[i] |
| | if pred(e, i) then | | if pred(e, i) then |
| | + | if pre and preFlag then |
| | + | local value = pre(e, i) |
| | + | if value then |
| | + | current = value |
| | + | preFlag = false |
| | + | return true |
| | + | end |
| | + | end |
| | current = e._name | | current = e._name |
| | i = i + 1 | | i = i + 1 |
| | + | preFlag = true |
| | return true | | return true |
| | end | | end |
| Line 79: |
Line 89: |
| | return e._id >= from and e._id <= to | | return e._id >= from and e._id <= to |
| | end) | | end) |
| | + | end |
| | + | |
| | + | function Iterator.equipmentByIdWithHeaders(context, n) |
| | + | local from = numberKey('from', context, n, 1) |
| | + | local to = numberKey('to', context, n, 500) |
| | + | local prevMod = 0 |
| | + | return Iterator.equipmentBy( |
| | + | context, n, |
| | + | function(e) |
| | + | return e._id >= from and e._id <= to |
| | + | end, |
| | + | function(e) |
| | + | local currentMod = (e._id - 1) % 10 |
| | + | if currentMod <= prevMod then |
| | + | prevMod = currentMod |
| | + | return "!#No " .. U.pad(e._id - currentMod, 3, "0") .. " - " .. U.pad(e._id - currentMod + 9, 3, "0") |
| | + | else |
| | + | prevMod = currentMod |
| | + | return false |
| | + | end |
| | + | end |
| | + | ) |
| | end | | end |
| | | | |
| Line 106: |
Line 138: |
| | end | | end |
| | testIterator('equipmentById', { from = '11', to = '20' }) | | testIterator('equipmentById', { from = '11', to = '20' }) |
| | + | testIterator('equipmentByIdWithHeaders', { from = '1', to = '30' }) |
| | testIterator('equipmentByType', { type = '2' }) | | testIterator('equipmentByType', { type = '2' }) |
| | testIterator('equipmentByType', { type = '1', sort = '_icon' }) | | testIterator('equipmentByType', { type = '1', sort = '_icon' }) |