-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshc-mapeditortools.lua
3311 lines (2032 loc) · 84.5 KB
/
shc-mapeditortools.lua
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Stronghold Map Editor Tools to improve Map Making in Stronghold Crusader
Copyright (C) 2021 Edward Gynt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--]]
--[[--
|-------------------|
| TABLE OF CONTENTS |
|-------------------|
This list is not intended to indicate the actual positions, but the structure of this file.
One could, for example, use it to better search the file with CTRL + F.
* UTILITY
* BASE CONFIGURATION
* Assert Functions
* Default Configuration Class
* _FieldUtil_ Helper
* Default _FieldUtil_
* COORDINATE MODIFICATION FEATURES
* SHAPE FEATURE
* Shape Fill Functions
* Shape Modification Function
* Shape Configuration
* Shape _FieldUtil_
* SPRAY FEATURE
* Spray Modification Function
* Spray Configuration
* Spray _FieldUtil_
* MIRROR FEATURE
* Mirror Modification Function
* Mirror Configuration
* Mirror _FieldUtil_
* MIRROR ROTATION FEATURE
* Mirror Rotation Modification Function
* Mirror Rotation Configuration
* Mirror Rotation _FieldUtil_
* OTHER FEATURES
* TRACING FEATURE
* Tracing Helper Functions
* Tracing Function
* Tracing Configuration
* Tracing _FieldUtil_
* API STUCTURES
* Basic Help Text
* Default Pipeline
* Status Function
* API Functions
--]]--
-- ################################################################################################ --
-- ##
-- ## UTILITY
-- ##
-- ################################################################################################ --
--[[
Returns "true" should the table be empty.
source: https://stackoverflow.com/a/1252776
@TheRedDaemon
]]--
local function isTableEmpty(t)
local next = next
return next(t) == nil
end
--[[
Gets the number of entries in a table.
Apparently there is #, but this only works on array-style tables.
O(N) is the most efficient this can get without meta structures (a "count" variable for example)
source: https://stackoverflow.com/a/2705804
@TheRedDaemon
]]--
local function getTableLength(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
--[[
A simple rounding to full numbers function.
@TheRedDaemon
]]--
local function round(x)
--[[
Round towards positive infinity: 0.5 -> 1, but -0.5 -> 0
source: https://scriptinghelpers.org/questions/4850/how-do-i-round-numbers-in-lua-answered
]]--
--local modNum = 1
--[[
Round towards positive and negative infinity: 0.5 -> 1 and -0.5 -> -1
source: https://love2d.org/forums/viewtopic.php?p=208676#p208676
]]--
local modNum = x >= 0.0 and 1 or -1
local n = x + 0.5 * modNum
return n - n % modNum
end
-- ################################################################################################ --
-- ##
-- ## BASE CONFIGURATION
-- ##
-- ################################################################################################ --
-- ### Assert Functions ######################################################################### --
-- @TheRedDaemon
local function checkType(value, intendedType, failMessage)
local res = type(value) == intendedType
if not res and failMessage ~= nil then
print(failMessage)
end
return res
end
-- @TheRedDaemon
local function isBoolean(value)
return checkType(value, "boolean", "The given parameter value is not true or false (Boolean).")
end
-- @TheRedDaemon
local function isNumber(value)
return checkType(value, "number", "The given parameter value is no number.")
end
-- @TheRedDaemon
local function isInteger(value)
local res = isNumber(value)
if res and math.floor(value) ~= value then
print("The given parameter value is no whole number (Integer).")
res = false
end
return res
end
-- @TheRedDaemon
local function isString(value)
return checkType(value, "string", "The given parameter value is no string.")
end
--[[
Checks if a number is in a specific range (inclusive).
Setting "minRange" or "maxRange" to "nil" will assume no border.
@TheRedDaemon
]]--
local function isInRange(number, minRange, maxRange, rangeMessage)
if minRange ~= nil and number < minRange then
print("The given number is too small. Allowed range: ", rangeMessage)
return false
end
if maxRange ~= nil and number > maxRange then
print("The given number is too big. Allowed range: ", rangeMessage)
return false
end
return true
end
-- ### Default Configuration Class ############################################################## --
--[[ Table ]]--
--[[
Create default configuration base table.
@TheRedDaemon
]]--
local DefaultBase = {
active = false , -- is the modification active
_FieldUtil_ = {} , -- includes check functions and help texts by parameter name
__name = "Base Configuration Object", -- debug info
}
--[[
Add dummy "func" to "DefaultBase".
Executed if func in config not set. Returns "coordinatelist" unchanged.
@TheRedDaemon
]]--
function DefaultBase.func(config, coordinatelist, size)
print("Noticed config without a valid function. No changes to coords.")
return coordinatelist
end
--[[ Functions ]]--
--[[
Helper function. Searches metatables for a _FieldUtil_ that contains the requested field.
Returns the found util for the field or "nil" if no fitting util in the _FieldUtil_s was found.
@TheRedDaemon
]]--
function DefaultBase:receiveUtilForField(field)
local util = self._FieldUtil_[field]
if util ~= nil then
return util
end
self = getmetatable(self) -- check parent for validation or help text
if self == nil then
return nil
end
return self:receiveUtilForField(field) -- recursive
end
--[[
General function to set a field in the configuration.
Also prints help texts.
Returns true if any field was set. Might not be the field requested through "field".
@TheRedDaemon
]]--
function DefaultBase:setField(field, value)
if field == nil then
local featureCon = self._FieldUtil_[self.__name]
local featureText = featureCon ~= nil and featureCon.help or nil
if featureText == nil then
featureText = "No feature description found."
end
print(featureText)
return false
end
local utilForField = self:receiveUtilForField(field)
if utilForField == nil then
print("No parameter handler for this name found: ", field)
return false
end
if value == nil then
local fieldText = utilForField.help
if fieldText == nil then
fieldText = "No parameter description found."
end
print(fieldText)
return false
end
return utilForField.set(self, field, value)
end
--[[
General function to guard a simple field assignment.
If this configuration does not have an index named "field", the assignment is prevented.
WARNING: Does not prevent wrong assignments to valid fields.
@gynt, @TheRedDaemon
]]--
function DefaultBase:guardedAssign(field, value)
if self[field] == nil then
print("'" .. tostring(field) .. "' is not a valid parameter for this feature.")
else
rawset(self, field, value)
end
end
--[[
Creates a status using the structure in _FieldUtil_.
Aliases will be filtered by using rawget(), so that they do not fall through on accident.
Will return a table of key value pairs. Keys are the parameter.
The configuration description will be in "__name"..
@TheRedDaemon
]]--
function DefaultBase:getPublicStatus()
local statusTable = {}
statusTable.__name = self._FieldUtil_[self.__name] ~= nil and self.__name or "Unknown"
local currentClass = self
repeat
local currentFieldUtil = nil
repeat
currentFieldUtil = rawget(currentClass, "_FieldUtil_")
if currentFieldUtil == nil then
currentClass = getmetatable(currentClass) -- check parent
end
if currentClass == nil then
return statusTable -- we are done
end
until (currentFieldUtil ~= nil)
for field, _ in pairs(currentFieldUtil) do
-- will notice default fields, filters aliases, does not override (keeps specialized)
if rawget(currentClass, field) ~= nil and statusTable[field] == nil then
statusTable[field] = self[field] -- add current value
end
end
currentClass = getmetatable(currentClass)
until (currentClass == nil)
return statusTable
end
--[[
Constructs new object (or class, there does not seem to be a difference) from the default base values.
"fields" is a table that can already provide values that extend the object or override functions.
Uses simple LUA OOP.
Source: https://www.lua.org/pil/16.2.html
@TheRedDaemon
]]--
function DefaultBase:new(fields)
fields = fields or {}
setmetatable(fields, self)
self.__index = self
self.__call = DefaultBase.setField -- sets __call always to default handler
self.__newindex = DefaultBase.guardedAssign -- sets __newindex always to default handler
return fields
end
--[[ Configuration Constructor ]]--
ConfigConstructor = {} -- GLOBAL object to contain default constructors
-- @TheRedDaemon
function ConfigConstructor.newBaseConfig(fields)
return DefaultBase:new(fields)
end
--[[ Configuration Proxy ]]--
--[[
The general configuration proxy metatable.
@TheRedDaemon
]]--
local proxyMeta = {
__call = function(self, field, value)
return self._config(field, value)
end,
__newindex = function(self, field, value)
self._config:setField(field, value) -- guard
end,
__index = function(self, field)
if field == "_proxy" then
return true -- indicates that proxy table
end
return self._config[field] -- reads should be no issue, right?
end,
__name = "Configuration Proxy MetaTable"
}
--[[ GLOBAL
Wraps a configuration in a proxy table. Direct assigns are guarded.
To access the configuration directly, use the "_config" variable.
@TheRedDaemon
]]--
function CreateConfigProxy(config)
if config == nil then
return nil -- no config provided
end
local proxy = {}
proxy._config = config -- only unprotected thing
setmetatable(proxy, proxyMeta)
return proxy
end
-- ### _FieldUtil_ Helper ####################################################################### --
-- @TheRedDaemon: Has anyone more ideas for helpers?
--[[
A helper function to set a boolean configuration value.
If "setTrueMsg" and/or "setFalseMsg" are unequal "nil" they are used in the
respective cases instead of a default message.
@TheRedDaemon
]]--
function DefaultBase.setConfigBoolean(config, field, value, setTrueMsg, setFalseMsg)
local res = isBoolean(value)
if res then
config[field] = value
if value then
print(setTrueMsg == nil and "The parameter is now 'true'." or setTrueMsg)
else
print(setFalseMsg == nil and "The parameter is now 'false'." or setFalseMsg)
end
end
return res
end
--[[
A helper function to create a new alias. Returns "true" if an alias was created.
Rejects requests that would overwrite an existing alias.
The alias is created in the first _FieldUtil_ of the calling object, not in the
_FieldUtil_ where the parameter was found!
One can hide aliases of lower levels, but no fields.
@TheRedDaemon
]]--
function DefaultBase:createAlias(field, newAlias)
if (self[newAlias] ~= nil) then
print("New alias would hide field and is rejected: ", newAlias)
return false
end
local utilOfField = self:receiveUtilForField(field)
if utilOfField == nil then
print("No valid parameter or existing alias: ", field)
return false
end
local ownFieldUtil = self._FieldUtil_ -- to prevent overwriting in lower levels ("active" for example)
if ownFieldUtil[newAlias] ~= nil then
if utilOfField == ownFieldUtil[newAlias] then
print("Alias already points to the same field.")
else
print("Alias already used: ", newAlias)
end
return false
else
ownFieldUtil[newAlias] = utilOfField
print("New alias set.")
return true
end
end
--[[
A helper function to remove an alias. Returns "true" if an alias was removed.
Removes first instance of an alias found with the name "alias".
Rejects requests that would remove the Util of the original parameter.
@TheRedDaemon
]]--
function DefaultBase:removeAlias(alias)
if (self[alias] ~= nil) then
print("Can not remove. Actual field: ", alias)
return false
end
-- alias can only be set on own level, so it can only be removed there
local ownFieldUtil = self._FieldUtil_
if ownFieldUtil[alias] == nil then
print("No existing alias: ", alias)
return false
end
ownFieldUtil[alias] = nil
print("Alias removed.")
return true
end
-- ### Default _FieldUtil_ ###################################################################### --
--[[ Base ]]--
-- @TheRedDaemon: Do the (...).set functions need the field value?
-- @TheRedDaemon: It might be beneficial to create some helper functions in the future.
-- tables
local baseFieldUtil = DefaultBase._FieldUtil_
baseFieldUtil[DefaultBase.__name] = {}
-- help
baseFieldUtil[DefaultBase.__name].help = [[
## Base Configuration ##
This is a raw configuration object.
If you can read this and you did not intend to experiment with the functions,
please report this as a bug on github.]]
--[[ func ]]--
-- table
baseFieldUtil.func = {}
-- set
function baseFieldUtil.func.set(config, field, value)
print("The function of this configuration can not be changed with this method.")
end
-- help
baseFieldUtil.func.help = [[
"func"
The parameter "func" contains the function which will be called with this configuration.
This is an internal value and should not be changed.]]
--[[ active ]]--
-- table
baseFieldUtil.active = {}
-- set
function baseFieldUtil.active.set(config, field, value)
-- config is self; manually set field to avoid problem with aliases
return config:setConfigBoolean("active", value,
"Feature activated.", "Feature deactivated.")
end
-- help
baseFieldUtil.active.help = [[
"active"
General activation parameter. Controls whether the feature is active or not.
This parameter might be set by other parameter changes.
false feature is deactivated
true feature is active
Default: ]] .. tostring(DefaultBase.active)
-- ################################################################################################ --
-- ##
-- ## COORDINATE MODIFICATION FEATURES
-- ##
-- ################################################################################################ --
-- ##============================================================================================## --
-- ##
-- ## SHAPE FEATURE
-- ##
-- ##============================================================================================## --
-- ### Shape Fill Functions ##################################################################### --
--[[
Fills coordTable with {x,y} int coordinates using Bresenham's line algorithm.
Returns the received table.
According to source, this version does not guarantee a coordinate order. Could be x0, y0 to x1, y1 or vise versa.
source: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
@TheRedDaemon
]]--
local function fillWithLineCoords(x0, y0, x1, y1, coordTable)
local index = #coordTable + 1
local dx = math.abs(x1 - x0)
local sx = x0 < x1 and 1 or -1
local dy = -math.abs(y1 - y0)
local sy = y0 < y1 and 1 or -1
local err = dx + dy -- error value e_xy
while true do -- loop
coordTable[index] = {x0, y0}
index = index + 1
if x0 == x1 and y0 == y1 then break end
local e2 = 2 * err
if e2 >= dy then -- e_xy+e_x > 0
err = err + dy
x0 = x0 + sx
end
if e2 <= dx then -- e_xy+e_y < 0
err = err + dx
y0 = y0 + sy
end
end
return coordTable
end
--[[
Create coords in such a way that the player sees a rectangle.
Returns the received table.
Used own function, maybe change to four "fillWithLineCoords" one day?
(But this would only save visual space in this file.)
@TheRedDaemon
]]--
local function fillWithRectCoords(x0, y0, x1, y1, coordTable)
local xDiff = x1 - x0
local yDiff = y1 - y0
local stepsSide = (xDiff - yDiff) / 2
local stepsDown = (xDiff + yDiff) / 2
-- prevent duplicates with line algorithm
if stepsSide == 0 or stepsDown == 0 then
return fillWithLineCoords(x0, y0, x1, y1, coordTable)
end
local index = #coordTable + 1
for i = 0, stepsSide, 0 < stepsSide and 1 or -1 do
coordTable[index] = {x0 + i, y0 - i}
coordTable[index + 1] = {x1 - i, y1 + i}
index = index + 2
end
local ySign = 0 < stepsDown and 1 or -1
for i = 0 + ySign, stepsDown - ySign + ySign * (stepsDown % 1 ~= 0 and 1 or 0), ySign do
coordTable[index] = {x0 + i, y0 + i}
coordTable[index + 1] = {x1 - i, y1 - i}
index = index + 2
end
return coordTable
end
--[[
Create coords in such a way that the player sees a rectangle rotated by 45 degree.
Returns the received table.
@TheRedDaemon
]]--
local function fillWithRect45Coords(x0, y0, x1, y1, coordTable)
-- prevent duplicates with line algorithm
if x0 == x1 or y0 == y1 then
return fillWithLineCoords(x0, y0, x1, y1, coordTable)
end
local index = #coordTable + 1
for i = x0, x1, x0 < x1 and 1 or -1 do
coordTable[index] = {i, y0}
coordTable[index + 1] = {i, y1}
index = index + 2
end
local ySign = y0 < y1 and 1 or -1
for i = y0 + ySign, y1 - ySign, ySign do -- skip edges set by run over x
coordTable[index] = {x0, i}
coordTable[index + 1] = {x1, i}
index = index + 2
end
return coordTable
end
--[[
-- @TheRedDaemon: as long as there is a limit on the input actions, this function does not make much sense
Create coords in such a way that the player sees a filled rectangle rotated by 45 degree.
Returns the received table.
@TheRedDaemon
local function fillWithFilledRect45Coords(x0, y0, x1, y1, coordTable)
local index = #coordTable + 1
for i = x0, x1, x0 < x1 and 1 or -1 do
for j = y0, y1, y0 < y1 and 1 or -1 do
coordTable[index] = {i, j}
index = index + 1
end
end
return coordTable
end
]]--
--[[
Function used to draw a circle using Mid-Point Circle Drawing Algorithm.
Returns the received table.
source: https://www.geeksforgeeks.org/mid-point-circle-drawing-algorithm/
Note:
- originally used Bresenham’s Algorithm (source: https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/)
- but it produced duplicates I was unable to remove
@TheRedDaemon
]]--
local function fillWithCircleCoords(x_centre, y_centre, xr, yr, coordTable)
local index = #coordTable + 1
local r = round(math.sqrt((x_centre - xr)^2 + (y_centre - yr)^2))
local x = r
local y = 0
-- Slightly changed for SHC, since it produced duplicates and wrong output:
-- Printing the initial points on the axes after translation
coordTable[index] = {r + x_centre, y_centre}
index = index + 1
if r > 0 then --When radius is zero only a single point will be printed
coordTable[index] = {-r + x_centre, y_centre}
coordTable[index + 1] = {x_centre, r + y_centre}
coordTable[index + 2] = {x_centre, -r + y_centre}
index = index + 3
end
-- Initializing the value of P
local P = 1 - r
while x > y do
y = y + 1
if P <= 0 then -- Mid-point is inside or on the perimeter
P = P + 2 * y + 1
else -- Mid-point is outside the perimeter
x = x - 1
P = P + 2 * y - 2 * x + 1
end
-- All the perimeter points have already been printed
if x < y then break end
-- Printing the generated point and its reflection in the other octants after translation
coordTable[index] = {x + x_centre, y + y_centre}
coordTable[index + 1] = {-x + x_centre, y + y_centre}
coordTable[index + 2] = {x + x_centre, -y + y_centre}
coordTable[index + 3] = {-x + x_centre, -y + y_centre}
index = index + 4
-- If the generated point is on the line x = y then the perimeter points have already been printed
if x ~= y then
coordTable[index] = {y + x_centre, x + y_centre}
coordTable[index + 1] = {-y + x_centre, x + y_centre}
coordTable[index + 2] = {y + x_centre, -x + y_centre}
coordTable[index + 3] = {-y + x_centre, -x + y_centre}
index = index + 4
end
end
return coordTable
end
-- ### Shape Modification Function ############################################################## --
--[[
Uses a previous click and the current click to generate NEW "coordlist" that forms a shape.
Or will try to create multiple shapes in a NEW "coordlist" if it receives multiple coords.
Returns an empty "coordlist" after it stored the first coordinate for the shape if
"config.removeRememberedCoords" is set to "true".
If multiple coords are received, then setting "config.connectShapes" to "true" will use non
start or end coords twice and will result in connected shapes.
A single shape should not produce duplicates. Multiple will.
WARNING: Currently maximal 200 coords can be applied. This easily results in incomplete big shapes.
WARNING: The first coordinate is only invalidated after use, after receiving multiple coords
or after disabling the shape brush.
@TheRedDaemon
]]--
local function applyShape(config, coordlist, size)
if not config.active or isTableEmpty(coordlist) then
config.lastCoords = {} -- remove last entry if brush inactive (sadly happens on every call)
return coordlist
end
local newCoordlist = {}
-- trusting on continuous index (should this make issues: get length)
-- currently no shape that takes three points, so this can be general
if coordlist[2] == nil and isTableEmpty(config.lastCoords) then
config.lastCoords = coordlist
return config.removeRememberedCoords and newCoordlist or coordlist
end
local shape = config.shape
local fillFunction = nil
if shape == "line" then
fillFunction = fillWithLineCoords
elseif shape == "rect" then
fillFunction = fillWithRectCoords
elseif shape == "rect45" then
fillFunction = fillWithRect45Coords
elseif shape == "circle" then
fillFunction = fillWithCircleCoords
end
if fillFunction == nil then
print("No valid shape: " ..shape)
config.lastCoords = {} -- remove due to invalid shape
return coordlist
end
if coordlist[2] == nil then
-- no shape with more than two coords, so:
fillFunction(config.lastCoords[1][1], config.lastCoords[1][2],
coordlist[1][1], coordlist[1][2], newCoordlist)
else
local connectShapes = config.connectShapes
-- no shape with anything other than two coords, so the loop can be simple
local lastCoord = nil
for _, coord in ipairs(coordlist) do
if lastCoord ~= nil then
fillFunction(lastCoord[1], lastCoord[2], coord[1], coord[2], newCoordlist)
lastCoord = connectShapes and coord or nil
else
lastCoord = coord
end
end
end
config.lastCoords = {} -- remove points after any kind of shape was applied
return newCoordlist
end
-- ### Shape Configuration ###################################################################### --
--[[ Default Configuration ]]--
local DefaultShape = DefaultBase:new{