Subversion Repositories public iLand

Rev

Rev 1008 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
961 werner 2
#include "barkbeetlescript.h"
3
 
4
#include "barkbeetlemodule.h"
5
 
6
 
7
 
8
BarkBeetleScript::BarkBeetleScript(QObject *)
9
{
10
    mBeetle = 0;
11
}
12
 
13
void BarkBeetleScript::test(QString value)
14
{
15
    qDebug() << value;
16
}
17
 
18
void BarkBeetleScript::init(QJSValue fun)
19
{
20
    QJSValueList args = QJSValueList() << 0 << 0;
21
 
22
    if (!fun.isCallable()) {
23
        qDebug() << "no valid function in init!!";
24
        return;
25
    }
26
    for (int y=0;y < mBeetle->mGrid.sizeY(); ++y)
27
        for (int x=0;x < mBeetle->mGrid.sizeX(); ++x) {
28
            args[0] = x; args[1] = y;
29
            double result = fun.call(args).toNumber();
30
            mBeetle->mGrid.valueAtIndex(x,y).n = result;
31
        }
32
}
33
 
34
void BarkBeetleScript::run(QJSValue fun)
35
{
36
    QJSValueList args = QJSValueList() << 0 << 0;
37
 
38
    if (!fun.isCallable()) {
39
        qDebug() << "no valid function in run!!";
40
        return;
41
    }
42
    for (int y=0;y < mBeetle->mGrid.sizeY(); ++y)
43
        for (int x=0;x < mBeetle->mGrid.sizeX(); ++x) {
44
            args[0] = x; args[1] = y;
45
            fun.call(args);
46
        }
47
}
48
 
49
double BarkBeetleScript::pixelValue(int ix, int iy)
50
{
51
    if (mBeetle->mGrid.isIndexValid(ix,iy)) {
52
        return mBeetle->mGrid.valueAtIndex(ix, iy).n;
53
    } else {
54
        return -9999;
55
    }
56
}
57
 
58
void BarkBeetleScript::setPixelValue(int ix, int iy, double val)
59
{
60
    if (mBeetle->mGrid.isIndexValid(ix,iy)) {
61
        mBeetle->mGrid.valueAtIndex(ix, iy).n = val;
62
    }
63
}