KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

modifier.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env python3
  2. '''
  3. KLL Modifier Containers
  4. '''
  5. # Copyright (C) 2016 by Jacob Alexander
  6. #
  7. # This file is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This file is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  19. ### Imports ###
  20. ### Decorators ###
  21. ## Print Decorator Variables
  22. ERROR = '\033[5;1;31mERROR\033[0m:'
  23. WARNING = '\033[5;1;33mWARNING\033[0m:'
  24. ### Classes ###
  25. class AnimationModifier:
  26. '''
  27. Animation modification container class
  28. '''
  29. def __init__( self, name, value=None ):
  30. self.name = name
  31. self.value = value
  32. def __repr__( self ):
  33. if self.value is None:
  34. return "{0}".format( self.name )
  35. return "{0}:{1}".format( self.name, self.value )
  36. class AnimationModifierList:
  37. '''
  38. Animation modification container list class
  39. Contains a list of modifiers, the order does not matter
  40. '''
  41. def __init__( self ):
  42. self.modifiers = []
  43. def setModifiers( self, modifier_list ):
  44. '''
  45. Apply modifiers to Animation
  46. '''
  47. for modifier in modifier_list:
  48. self.modifiers.append( AnimationModifier( modifier[0], modifier[1] ) )
  49. def strModifiers( self ):
  50. '''
  51. __repr__ of Position when multiple inheritance is used
  52. '''
  53. output = ""
  54. for index, modifier in enumerate( self.modifiers ):
  55. if index > 0:
  56. output += ","
  57. output += "{0}".format( modifier )
  58. return output
  59. def __repr__( self ):
  60. return self.strModifiers()
  61. class PixelModifier:
  62. '''
  63. Pixel modification container class
  64. '''
  65. def __init__( self, operator, value ):
  66. self.operator = operator
  67. self.value = value
  68. def __repr__( self ):
  69. if self.operator is None:
  70. return "{0}".format( self.value )
  71. return "{0}{1}".format( self.operator, self.value )
  72. class PixelModifierList:
  73. '''
  74. Pixel modification container list class
  75. Contains a list of modifiers
  76. Index 0, corresponds to pixel 0
  77. '''
  78. def __init__( self ):
  79. self.modifiers = []
  80. def setModifiers( self, modifier_list ):
  81. '''
  82. Apply modifier to each pixel channel
  83. '''
  84. for modifier in modifier_list:
  85. self.modifiers.append( PixelModifier( modifier[0], modifier[1] ) )
  86. def strModifiers( self ):
  87. '''
  88. __repr__ of Position when multiple inheritance is used
  89. '''
  90. output = ""
  91. for index, modifier in enumerate( self.modifiers ):
  92. if index > 0:
  93. output += ","
  94. output += "{0}".format( modifier )
  95. return output
  96. def __repr__( self ):
  97. return self.strModifiers()