<commit_before># -*- coding: utf-8 -*-
# This file is part of LiSE, a framework for life simulation games.
# Copyright (C) 2013-2014 <NAME>, <EMAIL>
from kivy.logger import Logger
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import (
    NumericProperty,
    BooleanProperty,
    BoundedNumericProperty,
    ObjectProperty,
    StringProperty,
    DictProperty,
    ListProperty,
    ReferenceListProperty
)
from kivy.resources import resource_add_path
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.uix.scrollview import ScrollView

from kivy.factory import Factory

from .board import Board

import LiSE
import ELiDE
from ELiDE.kivygarden.texturestack import ImageStack

resource_add_path(ELiDE.__path__[0] + "/assets")


Factory.register('Board', cls=Board)


class MouseFollower(Widget):
    boardview = ObjectProperty()

    def on_touch_move(self, touch):
        self.center = self.boardview.to_local(*touch.pos)
        return True


class Dummy(ImageStack):
    _touch = ObjectProperty(None, allownone=True)
    name = StringProperty()
    prefix = StringProperty()
    num = NumericProperty()
    x_start = NumericProperty()
    y_start = NumericProperty()
    pos_start = ReferenceListProperty(x_start, y_start)
    x_down = NumericProperty()
    y_down = NumericProperty()
    pos_down = ReferenceListProperty(x_down, y_down)
    x_up = NumericProperty()
    y_up = NumericProperty()
    pos_up = ReferenceListProperty(x_up, y_up)
    x_center_up = NumericProperty()
    y_center_up = NumericProperty()
    center_up = ReferenceListProperty(x_center_up, y_center_up)
    right_up = NumericProperty()
    top_up = NumericProperty()

    def on_pos_up(self, *args):
        self.x_center_up = self.x_up + self.width / 2
        self.y_center_up = self.y_up + self.height / 2
        self.right_up = self.x_up + self.width
        self.top_up = self.y_up + self.height

    def on_touch_down(self, touch):
        if not self.collide_point(*touch.pos):
            return False
        self.pos_start = self.pos
        self.pos_down = (
            self.x - touch.x,
            self.y - touch.y
        )
        touch.grab(self)
        self._touch = touch
        return True

    def on_touch_move(self, touch):
        if touch is not self._touch:
            return False
        self.pos = (
            touch.x + self.x_down,
            touch.y + self.y_down
        )
        return True

    def on_touch_up(self, touch):
        if touch is not self._touch:
            return False
        self.pos_up = self.pos
        self.pos = self.pos_start
        self._touch = None
        return True


class BoardView(ScrollView):
    pass


class ELiDELayout(FloatLayout):
    """A master layout that contains one board and some menus
    and charsheets.

    This contains three elements: a scrollview (containing the board),
    a menu, and the time control panel. This class has some support methods
    for handling interactions with the menu and the character sheet,
    but if neither of those happen, the scrollview handles touches on its
    own.

    """
    app = ObjectProperty()
    board = ObjectProperty()
    dummies = ListProperty()
    _touch = ObjectProperty(None, allownone=True)
    popover = ObjectProperty()
    grabbing = BooleanProperty(True)
    reciprocal_portal = BooleanProperty()
    grabbed = ObjectProperty(None, allownone=True)
    selection = ObjectProperty(None, allownone=True)
    selection_candidates = ListProperty([])
    keep_selection = BooleanProperty(False)
    engine = ObjectProperty()
    tick_results = DictProperty({})
    branch = StringProperty()
    tick = NumericProperty()
    rules_per_frame = BoundedNumericProperty(10, min=1)

    def on_touch_down(self, touch):
        if (
                self.ids.boardview.collide_point(*touch.pos)
                and not self.selection_candidates
        ):
            # if the board itself handles the touch, let it be
            touch.push()
            touch.apply_transform_2d(self.ids.boardview.to_local)
            pawns = list(self.board.pawns_at(*touch.pos))
            if pawns:
                self.selection_candidates = pawns
                return True
            spots = list(self.board.spots_at(*touch.pos))
            if spots:
                self.selection_candidates = spots
                return True
            arrows = list(self.board.arrows_at(*touch.pos))
            if arrows:
                self.selection_candidates = arrows
                return True
            # the board did not handle the touch, so let the view scroll
            touch.pop()
            return self.ids.boardview.dispatch('on_touch_down', touch)
        for dummy in self.dummies:
            if dummy.collide_point(*touch.pos):
                self.selection = dummy
                return True
        # the menu widgets can handle things themselves
        if self.ids.timemenu.dispatch('on_touch_down', touch):
            return True
        if self.ids.charmenu.dispatch('on_touch_down', touch):
            return True

    def on_touch_move(self, touch):
        # For now, there's no way to select things by dragging.
        # However, if something's already selected, you can move it.
        if self.selection:
            touch.push()
            if hasattr(self.selection, 'use_boardspace'):
                touch.apply_transform_2d(self.ids.boardview.to_local)
            r = self.selection.dispatch('on_touch_move', touch)
            touch.pop()
            self.keep_selection = True
            return r<commit_msg>Touches weren't being dispatched to Dummy instances<commit_after># -*- coding: utf-8 -*-
# This file is part of LiSE, a framework for life simulation games.
# Copyright (C) 2013-2014 <NAME>, <EMAIL>
from kivy.logger import Logger
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import (
    NumericProperty,
    BooleanProperty,
    BoundedNumericProperty,
    ObjectProperty,
    StringProperty,
    DictProperty,
    ListProperty,
    ReferenceListProperty
)
from kivy.resources import resource_add_path
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.uix.scrollview import ScrollView

from kivy.factory import Factory

from .board import Board

import LiSE
import ELiDE
from ELiDE.kivygarden.texturestack import ImageStack

resource_add_path(ELiDE.__path__[0] + "/assets")


Factory.register('Board', cls=Board)


class MouseFollower(Widget):
    boardview = ObjectProperty()

    def on_touch_move(self, touch):
        self.center = self.boardview.to_local(*touch.pos)
        return True


class Dummy(ImageStack):
    _touch = ObjectProperty(None, allownone=True)
    name = StringProperty()
    prefix = StringProperty()
    num = NumericProperty()
    x_start = NumericProperty()
    y_start = NumericProperty()
    pos_start = ReferenceListProperty(x_start, y_start)
    x_down = NumericProperty()
    y_down = NumericProperty()
    pos_down = ReferenceListProperty(x_down, y_down)
    x_up = NumericProperty()
    y_up = NumericProperty()
    pos_up = ReferenceListProperty(x_up, y_up)
    x_center_up = NumericProperty()
    y_center_up = NumericProperty()
    center_up = ReferenceListProperty(x_center_up, y_center_up)
    right_up = NumericProperty()
    top_up = NumericProperty()

    def on_pos_up(self, *args):
        self.x_center_up = self.x_up + self.width / 2
        self.y_center_up = self.y_up + self.height / 2
        self.right_up = self.x_up + self.width
        self.top_up = self.y_up + self.height

    def on_touch_down(self, touch):
        if not self.collide_point(*touch.pos):
            return False
        self.pos_start = self.pos
        self.pos_down = (
            self.x - touch.x,
            self.y - touch.y
        )
        touch.grab(self)
        self._touch = touch
        return True

    def on_touch_move(self, touch):
        if touch is not self._touch:
            return False
        self.pos = (
            touch.x + self.x_down,
            touch.y + self.y_down
        )
        return True

    def on_touch_up(self, touch):
        if touch is not self._touch:
            return False
        self.pos_up = self.pos
        self.pos = self.pos_start
        self._touch = None
        return True


class BoardView(ScrollView):
    pass


class ELiDELayout(FloatLayout):
    """A master layout that contains one board and some menus
    and charsheets.

    This contains three elements: a scrollview (containing the board),
    a menu, and the time control panel. This class has some support methods
    for handling interactions with the menu and the character sheet,
    but if neither of those happen, the scrollview handles touches on its
    own.

    """
    app = ObjectProperty()
    board = ObjectProperty()
    dummies = ListProperty()
    _touch = ObjectProperty(None, allownone=True)
    popover = ObjectProperty()
    grabbing = BooleanProperty(True)
    reciprocal_portal = BooleanProperty()
    grabbed = ObjectProperty(None, allownone=True)
    selection = ObjectProperty(None, allownone=True)
    selection_candidates = ListProperty([])
    keep_selection = BooleanProperty(False)
    engine = ObjectProperty()
    tick_results = DictProperty({})
    branch = StringProperty()
    tick = NumericProperty()
    rules_per_frame = BoundedNumericProperty(10, min=1)

    def on_touch_down(self, touch):
        if (
                self.ids.boardview.collide_point(*touch.pos)
                and not self.selection_candidates
        ):
            # if the board itself handles the touch, let it be
            touch.push()
            touch.apply_transform_2d(self.ids.boardview.to_local)
            pawns = list(self.board.pawns_at(*touch.pos))
            if pawns:
                self.selection_candidates = pawns
                return True
            spots = list(self.board.spots_at(*touch.pos))
            if spots:
                self.selection_candidates = spots
                return True
            arrows = list(self.board.arrows_at(*touch.pos))
            if arrows:
                self.selection_candidates = arrows
                return True
            # the board did not handle the touch, so let the view scroll
            touch.pop()
            return self.ids.boardview.dispatch('on_touch_down', touch)
        for dummy in self.dummies:
            if dummy.dispatch('on_touch_down', touch):
                return True
        # the menu widgets can handle things themselves
        if self.ids.timemenu.dispatch('on_touch_down', touch):
            return True
        if self.ids.charmenu.dispatch('on_touch_down', touch):
            return True

    def on_touch_move(self, touch):
        # For now, there's no way to select things by dragging.
        # However, if something's already selected, you can move it.
        if self.selection:
            touch.push()
            if hasattr(self.selection, 'use_boardspace'):
                touch.apply_transform_2d(self.ids.boardview.to_local)
            r = self.selection.dispatch('on_touch_move', touch)
            touch.pop()
            self.keep_selection = True
            return r
{'fraction_non_alphanumeric': 0.08171891511095457, 'fraction_numerical': 0.0029940119760479044, 'mean_word_length': 2.4425583510154594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1940707', 'n_tokens_mistral': 3373, 'n_tokens_neox': 3262, 'n_words': 866}