This file is indexed.

/usr/share/gcompris/python/followline.py is in gcompris-data 12.01-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#  gcompris - administration.py
#
# Copyright (C) 2005, 2008 Bruno Coudoin
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Follow Line Board module
import gobject
import goocanvas
import cairo
import gcompris
import gcompris.skin
import gcompris.bonus
import gcompris.utils
import gcompris.sound
import gtk
import gtk.gdk
import random
import math
from gcompris import gcompris_gettext as _

# ----------------------------------------
#

class Gcompris_followline:
  """follow the line"""


  def __init__(self, gcomprisBoard):
    self.gcomprisBoard = gcomprisBoard

    # These are used to let us restart only after the bonus is displayed.
    # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
    self.board_paused  = 0
    self.gamewon       = 0

    self.loosing_count = 0

    self.color_empty   = 0xcee871FFL
    self.color_full    = 0x1a24cbffL
    self.color_target  = 0xFF0000FFL
    self.color_border  = 0x101010FFL

    self.timeout       = 0


  def start(self):
    self.saved_policy = gcompris.sound.policy_get()
    gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)

    self.gcomprisBoard.level=1
    self.gcomprisBoard.maxlevel=9
    self.gcomprisBoard.sublevel=1
    self.gcomprisBoard.number_of_sublevel=1
    gcompris.bar_set(gcompris.BAR_LEVEL)
    gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                            "followline/followline.svgz")
    self.gcomprisBoard.canvas.get_root_item().connect("motion_notify_event",
                                                      self.loosing_item_motion)
    self.gcomprisBoard.canvas.get_root_item().connect("button_press_event",
                                                      self.loosing_item_click)

    gcompris.bar_set_level(self.gcomprisBoard)

    self.init_board()


  def end(self):

    # Remove the root item removes all the others inside it
    self.cleanup()

    # Disconnect from the background item
    self.gcomprisBoard.canvas.get_root_item().disconnect_by_func(
      self.loosing_item_motion)
    self.gcomprisBoard.canvas.get_root_item().disconnect_by_func(
      self.loosing_item_click)

    gcompris.sound.policy_set(self.saved_policy)

    if self.timeout:
      gobject.source_remove(self.timeout)
    self.timeout = 0

  def ok(self):
    pass


  def repeat(self):
    pass


  def config(self):
    pass


  def key_press(self, keyval, commit_str, preedit_str):
    return False


  # Called by gcompris core
  def pause(self, pause):

    self.board_paused = pause

    # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
    # the game is won
    if(pause == 0):
      self.next_level()
      self.gamewon = 0

    return


  # Called by gcompris when the user click on the level icon
  def set_level(self, level):
    self.gcomprisBoard.level=level
    self.gcomprisBoard.sublevel=1
    self.next_level()

  # End of Initialisation
  # ---------------------

  def cleanup(self):
    # Remove the root item removes all the others inside it
    self.state = "Done"

    self.rootitem.remove()
    self.lines_group.remove()
    self.water_spot_group.remove()

  def next_level(self):

    self.cleanup()

    # Set the level in the control bar
    gcompris.bar_set_level(self.gcomprisBoard);

    self.init_board()



  def init_board(self):

    self.state = "Ready"

    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains automaticaly.
    self.rootitem = goocanvas.Group(
      parent = self.gcomprisBoard.canvas.get_root_item())

    # Another group where we put each canvas line item in it
    self.lines_group = goocanvas.Group(
      parent = self.gcomprisBoard.canvas.get_root_item())

    start_x  = 40
    start_y  = gcompris.BOARD_HEIGHT/2
    stop_x   = gcompris.BOARD_WIDTH - 100

    # Line path (create several little line)
    min_boundary = 40
    y            = start_y
    line_width   = 45 - self.gcomprisBoard.level*2
    step         = (stop_x-start_x)/(30)

    frequency = 1 + int(self.gcomprisBoard.level/4)

    xpi = math.pi/2*frequency
    y   = start_y + math.cos(xpi)*(self.gcomprisBoard.level*10)
    for x in range(start_x, stop_x, step):

      xpi += (math.pi/2*frequency)/step
      y2 = start_y + math.cos(xpi)*(self.gcomprisBoard.level*10)

      # Check we stay within boundaries
      if(y2 >= gcompris.BOARD_HEIGHT - min_boundary):
        y2 = gcompris.BOARD_HEIGHT - min_boundary
      elif(y2 <= min_boundary):
        y2 = min_boundary

      item = goocanvas.Polyline(
        parent = self.lines_group,
        points = goocanvas.Points([(x, y), (x + step, y2)]),
        stroke_color_rgba = self.color_empty,
        line_width = line_width,
        line_cap = cairo.LINE_CAP_ROUND
        )
      item.connect("enter_notify_event", self.line_item_event)
      item.connect("button_press_event", self.line_item_event)

      # Draw the black tube
      if x > start_x and x < stop_x-step:
          goocanvas.Polyline(
          parent = self.rootitem,
          points = goocanvas.Points([( x, y),
                                     (x + step, y2)]),
          fill_color_rgba = self.color_border,
          line_width = line_width + 20,
          line_cap = cairo.LINE_CAP_ROUND
          )
      y = y2

    self.highlight_next_line()

    # Another group where we put each canvas line item in it
    self.water_spot_group = goocanvas.Group(
      parent = self.gcomprisBoard.canvas.get_root_item())

    # A water spot will be displayed when the user win
    self.water_spot = goocanvas.Image(
      parent = self.water_spot_group,
      pixbuf = gcompris.utils.load_pixmap("followline/water_spot.svg"),
      x = 580,
      y = 260,
      )
    self.water_spot.props.visibility = goocanvas.ITEM_INVISIBLE


  # Code that increments the sublevel and level
  # And bail out if no more levels are available
  # return 1 if continue, 0 if bail out
  def increment_level(self):
    self.gcomprisBoard.sublevel += 1

    if(self.gcomprisBoard.sublevel > self.gcomprisBoard.number_of_sublevel):
      # Try the next level
      self.gcomprisBoard.sublevel=1
      self.gcomprisBoard.level += 1
      if(self.gcomprisBoard.level > self.gcomprisBoard.maxlevel):
        self.gcomprisBoard.level = self.gcomprisBoard.maxlevel

    return 1

  #
  # Highlight the next spot on the line
  #
  def highlight_next_line(self):
    for i in range(0, self.lines_group.get_n_children()):
      item = self.lines_group.get_child(i)
      if(item.get_data("gotit") != True):
        item.props.stroke_color_rgba = self.color_target
        item.set_data("iamnext", True);
        return

  #
  # Highlight the previous spot on the line
  # Called on loose situation
  #
  def highlight_previous_line(self):
    previous_item = []

    for i in range(0, self.lines_group.get_n_children()):
      item = self.lines_group.get_child(i)

      if(item.get_data("iamnext") == True):

        if(previous_item):
          # Remove the target info for this item
          item.set_data("iamnext", False)
          item.props.stroke_color_rgba = self.color_empty

          # Set the target info on the previous item
          previous_item.props.stroke_color_rgba = self.color_target
          item.set_data("gotit", False)
          previous_item.set_data("iamnext", True);

        else:
          self.state = "Ready"

        return

      previous_item = item

  def lauch_bonus(self):
    gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)

  def is_done(self):
    done = True
    for i in range(0, self.lines_group.get_n_children()):
      item = self.lines_group.get_child(i)
      if(item.get_data("gotit") != True):
        done = False

    if(done):
      gcompris.sound.play_ogg("sounds/bubble.wav")
      # This is a win
      if (self.increment_level() == 1):
        self.state = "Done"
        self.gamewon = 1
        self.water_spot.raise_(None)
        self.water_spot.props.visibility = goocanvas.ITEM_VISIBLE
        self.timeout = gobject.timeout_add(1500, self.lauch_bonus)

    return done

  def loosing_item_click(self, widget, target, event=None):
    if target.__class__ != goocanvas.Svg:
      return False
    self.lost()

  def loosing_item_motion(self, widget, target, event=None):
    if target.__class__ != goocanvas.Svg:
      return False

    self.loosing_count += 1
    if(self.loosing_count % 10 == 0):
      self.lost()

  def lost(self):
    if(self.state == "Started"):
        gcompris.sound.play_ogg("sounds/smudge.wav")
        self.highlight_previous_line()
    return False


  def line_item_event(self, widget, target, event=None):
    if not self.board_paused and widget.get_data("iamnext") == True:
      # The first line touch means the game is started
      gcompris.sound.play_ogg("sounds/drip.wav")
      self.state = "Started"
      widget.props.stroke_color_rgba = self.color_full

      widget.set_data("gotit", True);
      widget.set_data("iamnext", False);
      self.highlight_next_line()
      self.is_done()

    return False