File: libpento_1.xml

package info (click to toggle)
enigma 1.30%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76,132 kB
  • sloc: xml: 162,251; cpp: 67,393; ansic: 28,606; makefile: 1,986; sh: 1,298; yacc: 288; perl: 84; sed: 16
file content (128 lines) | stat: -rw-r--r-- 5,059 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<el:level xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://enigma-game.org/schema/level/1 level.xsd" xmlns:el="http://enigma-game.org/schema/level/1">
  <el:protected>
    <el:info el:type="library">
      <el:identity el:title="" el:id="lib/libpento"/>
      <el:version el:score="1" el:release="1" el:revision="4" el:status="released"/>
      <el:author  el:name="Ronald Lamprecht" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2009 Ronald Lamprecht</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.10">
        <el:dependency el:path="lib/libmap" el:id="lib/libmap" el:release="1" el:preload="true"/>
      </el:compatibility>
      <el:modes el:easy="false" el:single="false" el:network="false"/>
      <el:comments>
      </el:comments>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[

lib.pento = {}
lib.pento.MAX_WIDTH  = 100000  -- If you have to change this, change it before any call to res.pento.
lib.pento.MAX_HEIGHT = 100000  -- If you have to change this, change it before any call to res.pento.

ti["pentopuzzle"] = {"st_puzzle", "shape%%#", cluster="%%", intensity=0}

function res.pento_finalization(context)
    context.src_area = no[context.source.."#*"]
    context.src_anchor = po(0,0)
    do
        assert_bool(#context.src_area == 25, "Pentomino source area not a 5x5 square.", 2)
        local x = lib.pento.MAX_WIDTH
        local y = lib.pento.MAX_HEIGHT
        for s in context.src_area do
            if s.x < x then x = s.x end
            if s.y < y then y = s.y end
        end
        context.src_anchor = po(x, y)
        for s in context.src_area do
            assert_bool((s.x <= x + 5) and (s.y <= y + 5), "Pentomino source area not a 5x5 square.", 2)
        end
    end
    context.target_area = no["target#*"]
    local dummy = (assert_bool)(#context.target_area == 60, "Pentomino target area not 60 grids.", 2)

    context.last_shape = 12
    
    context.next = function ()
        local trash = st(context.src_area)
        for t in trash do
            if -t then
                t:get_cluster():kill()
            end
        end
        local count = 0
        repeat
            count = count + 1
            if count == 13 then return end
            context.last_shape = context.last_shape + 1
            if context.last_shape == 13 then context.last_shape = 1 end
        until #no["shape%"..context.last_shape.."#*"] == 0
        
        local shape_map = wo:newMap(" ", context.shapes[context.last_shape])
        local offset = po(3 - shape_map.width/2, 3 - shape_map.height/2)
        wo:drawMap(context[3], context.src_anchor + offset, " ", shape_map)
    end

    context.transform = function (transformation)
        local target = st(context.src_area)
        local cluster = nil
        if #target ~= 5 then return end
        for t in target do
            if cluster == nil then 
                cluster = t["cluster"]
            elseif cluster ~= t["cluster"] then
                return
            end
        end
        local oldtransform = MAP_ALL[target[1]["_transform"]] or MAP_IDENT
        local newtransform = oldtransform * transformation
        target[1]:get_cluster():kill()
        local shape = 0 + cluster:sub(2)
        local shape_map = wo:newMap(" ", context.shapes[shape]) ^ newtransform
        local offset = po(3 - shape_map.width/2, 3 - shape_map.height/2)
        wo:drawMap(context[3], context.src_anchor + offset, " ", shape_map)
        st(context.src_area)["_transform"] = newtransform.index
    end

    context.rotate = function()
        context.transform(MAP_ROT_CW)
    end
    
    context.mirror = function()
        context.transform(MAP_FLIP_HORIZONTAL)
    end
    
    context.check = function()
        return #st(context.target_area) == 60
    end

end

function res.pento_implementation(context, evaluator, key, x, y)
    return evaluator(context[3], key, x, y)
end

function res.pento(subresolver, ...)
    -- syntax: ... = <sourcebasename>, <targetbasename>
    -- context: 
    local args = {...}
    assert_bool(is_resolver(subresolver), "res.pento first argument (subresolver)", 2)
    assert_type(args[1], "res.pento second argument (source basename)", 2, "string")
    assert_type(args[2], "res.pento third argument (target basename)", 2, "string")
    local autotile = res.autotile(subresolver, {"O","Z", "pentopuzzle"})
    local context = {res.pento_implementation, res.pento_finalization, autotile}
    context.source = args[1]
    context.target = args[2]
    context.shapes = {{"OOOOO"}, {"PP","PPP"}, {"QQQQ","Q"},{"R","RRR"," R"},
        {"  SS","SSS"},{"T","TTT","T"},{"U U","UUU"},{"VVV","V","V"},
        {"W","WW"," WW"},{" X","XXX"," X"},{"YYYY"," Y"},{"ZZ"," Z"," ZZ"}}
    setmetatable(context, res.metatable)
    return context
end

    ]]></el:luamain>
    <el:i18n>
    </el:i18n>
  </el:protected>
</el:level>