mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +00:00
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
|
#!/usr/bin/env python3
|
||
|
#
|
||
|
# OperatorTile.py
|
||
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||
|
#
|
||
|
|
||
|
from Operator import Operator
|
||
|
import copy
|
||
|
|
||
|
class OperatorTile(Operator):
|
||
|
name = "Tile"
|
||
|
|
||
|
#
|
||
|
# apply2(self, mapPoint, mousePoint, regionOld, region)
|
||
|
def apply2(self, mapPoint, mousePoint, regionOld, region):
|
||
|
if self.lastPoint == None:
|
||
|
self.lastPoint = list(mapPoint)
|
||
|
if self.tileObject == None:
|
||
|
self.tileObject = copy.deepcopy(region)
|
||
|
delta = [b - a for a, b in zip(self.lastPoint, mapPoint)]
|
||
|
if delta[1] > 0:
|
||
|
for numNewRow in range(delta[1]):
|
||
|
newRow = copy.deepcopy(self.tileObject[len(region) % len(self.tileObject)])
|
||
|
if len(newRow) < len(region[0]):
|
||
|
for numNewCol in range(len(newRow), len(region[0])):
|
||
|
newRow += [list(self.tileObject[len(region) % len(self.tileObject)][numNewCol % len(self.tileObject[len(region) % len(self.tileObject)])])]
|
||
|
region += [newRow]
|
||
|
if delta[0] > 0:
|
||
|
for numRow in range(len(region)):
|
||
|
for numNewCol in range(len(region[numRow]), len(region[numRow]) + delta[0]):
|
||
|
region[numRow] += [list(self.tileObject[numRow % len(self.tileObject)][numNewCol % len(self.tileObject[numRow % len(self.tileObject)])])]
|
||
|
self.lastPoint = list(mapPoint)
|
||
|
return region
|
||
|
|
||
|
# __init__(self, *args): initialisation method
|
||
|
def __init__(self, *args):
|
||
|
self.lastPoint, self.tileObject = None, None
|
||
|
|
||
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|