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
129
130
131
132
133
|
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3
Item {
anchors.fill: parent
id : board;
Column {
id : column;
anchors.fill: parent;
spacing: 25
Row {
id: row
width: parent.width;
IconButton {
width: (parent.width - parent.height) / 2;
icon.source: "image://theme/icon-m-back"
onClicked: goban.undo();
}
Image {
width: parent.height;
source: "../content/gfx/" + (goban.currentPlayer ? "white":"black") + ".png"
height: parent.height;
scale: 0.5
}
IconButton {
width: (parent.width - parent.height) / 2;
icon.source: "image://theme/icon-m-refresh"
onClicked: goban.start()
}
}
Goban {
id:goban
width: parent.width;
height: column.height - (row.height + view.height);
onCompletedLevel: {
overlay.text = status ? "X" : "✓";
overlay.color = status ? "red" : "green" ;
}
}
SlideshowView {
id: view
width: parent.width
height: 200
itemWidth: width / 2
onCurrentIndexChanged: {
py.call('board.getGame', [view.currentIndex], goban.setGoban)
}
model: 1
delegate: Text {
horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter;
color: Theme.primaryColor;
font.family: Theme.fontFamily;
font.pixelSize: Theme.fontSizeMedium;
width: view.itemWidth;
height: view.height;
text: "Problem " + (index + 1);
}
}
}
Text {
id: overlay
opacity: goban.completed ? 1 : 0
anchors {
centerIn:parent
}
font.family: Theme.fontFamily;
font.pixelSize: goban.height;
Behavior on opacity { NumberAnimation { duration: 500 } }
}
function loadBoard(path) {
py.loadBoard(path);
}
Python {
id:py
Component.onCompleted: {
var pythonpath = Qt.resolvedUrl('../python').substr('file://'.length);
addImportPath(pythonpath);
console.log(pythonpath);
importModule('board', function() {
console.log('module loaded');
console.log('Python version: ' + pythonVersion());
});
setHandler('log', function (content) {
console.log(content);
});
call('board.setPath', [pythonpath]);
call('board.loadBoard', ["easy.sgf"], function (result) {
console.log(result + " problems found in the file");
view.model = result
call('board.getGame', [0], goban.setGoban);
});
}
function loadBoard(path) {
call('board.loadBoard', [path], function (result) {
console.log(result + " problems found in the file");
view.model = result
call('board.getGame', [0], goban.setGoban);
});
}
}
function showHint() {
goban.showHint();
}
}
|