Skip to content

Commit 07d210b

Browse files
committed
backport more fixes
1 parent 1b71313 commit 07d210b

6 files changed

Lines changed: 88 additions & 18 deletions

File tree

wurst/_handles/primitives/String.wurst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package String
22
import NoWurst
33
import Integer
4+
import Maths
45

56
constant charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
67
constant numberset = "0123456789"
@@ -205,6 +206,24 @@ public function string.replace(string oldSubstring, string newSubstring) returns
205206
i = s.indexOf(oldSubstring, i + newSubstring.length())
206207
return s
207208

209+
/** Returns an integer result based on a lexicographic string comparison of strings s1 and s2. */
210+
public function stringCompare(string s1, string s2) returns int
211+
let s1Len = s1.length()
212+
let s2Len = s2.length()
213+
for int i = 0 to min(s1Len, s2Len)
214+
let char1Int = s1.charAt(i).toCharsetInt()
215+
let char2Int = s2.charAt(i).toCharsetInt()
216+
if char1Int < char2Int
217+
return -1
218+
else if char1Int > char2Int
219+
return 1
220+
221+
if s1Len < s2Len
222+
return -1
223+
else if s1Len > s2Len
224+
return 1
225+
return 0
226+
208227
public function string.getHash() returns int
209228
return StringHash(this)
210229

@@ -271,4 +290,4 @@ public class StringLines
271290

272291
/** Returns a StringLines Object of the given string for iteration */
273292
public function string.toLines() returns StringLines
274-
return new StringLines(this, 0, this.countOccurences("\n") + 1)
293+
return new StringLines(this, 0, this.countOccurences("\n") + 1)

wurst/closures/ClosureTimers.wurst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ClosureTimers
22
import NoWurst
3+
import TimerDialog
34
import TimerUtils
45
import Real
56
import Wurstunit
@@ -26,6 +27,23 @@ public function timer.doAfter(real timeToWait, CallbackSingle cb) returns Callba
2627
public function doAfter(real timeToWait, CallbackSingle cb) returns CallbackSingle
2728
return getTimer().doAfter(timeToWait, cb)
2829

30+
/** Execute an action after a certain time.
31+
The timer is accompanied by a visible timerdialog with the title text provided.
32+
The callback object is automatically destroyed.
33+
34+
Example use:
35+
| doAfterWithDialogue(10.0, "Respawn in") ->
36+
| hero.revive()
37+
| print("10 seconds later")
38+
*/
39+
public function doAfterWithDialogue(real timeToWait, string titleText, Callback cb) returns CallbackSingle
40+
let tim = getTimer()
41+
let dia = tim.createTimerDialog()..setTitle(titleText)..display(true)
42+
return tim.doAfter(timeToWait) ->
43+
cb.call()
44+
destroy cb
45+
dia.destr()
46+
2947
/** Execute an action with a 0-second timer delay.
3048
The callback object is destroyed afterwards.
3149
*/
@@ -104,6 +122,9 @@ public function doPeriodicallyTimed(real interval, real timerDuration, CallbackC
104122
return getTimer().doPeriodicallyTimed(interval, timerDuration, cb)
105123

106124
//Timer Stuff
125+
public interface Callback
126+
function call()
127+
107128
public abstract class CallbackSingle
108129
private timer t
109130
abstract function call()

wurst/data/LinkedList.wurst

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public class LinkedList<T>
8888
function getFirst() returns T
8989
return dummy.next.elem
9090

91+
/** Returns the last element in the list */
92+
function getLast() returns T
93+
return dummy.prev.elem
94+
9195
/** Returns and removes the first added Element (FIFO) */
9296
function dequeue() returns T
9397
let top = dummy.next
@@ -108,7 +112,7 @@ public class LinkedList<T>
108112

109113
/** Returns the lastly added Element */
110114
function peek() returns T
111-
return dummy.prev.elem
115+
return getLast()
112116

113117
/** Returns whether the lists contains the specified element */
114118
@deprecated("Use .has instead") function contains(T elem) returns boolean
@@ -175,7 +179,7 @@ public class LinkedList<T>
175179
/** get the static back iterator for this list */
176180
function staticBackItr() returns LLBackIterator<T>
177181
if staticBackItr == null
178-
staticBackItr = new LLBackIterator<T>(dummy, false)
182+
staticBackItr = new LLBackIterator<T>(this, false)
179183
staticBackItr.reset()
180184
return staticBackItr
181185

@@ -185,11 +189,11 @@ public class LinkedList<T>
185189

186190
/** get a backiterator for this list */
187191
function backiterator() returns LLBackIterator<T>
188-
return new LLBackIterator(dummy)
192+
return new LLBackIterator(this)
189193

190194
/** adds an element to the beginning of the list */
191195
function enqueue(T elem)
192-
addtoStart(elem)
196+
add(elem)
193197

194198
/** adds an element to the beginning of the list */
195199
function addtoStart(T elem)
@@ -491,6 +495,9 @@ public class LLIterator<T>
491495
retVal = current.next.elem
492496
return retVal
493497

498+
function previous() returns T
499+
return current.prev.elem
500+
494501
/** Adds an element before the currently iterated element */
495502
function addBefore(T elem)
496503
let entry = new LLEntry<T>(elem, current.prev, current)
@@ -505,18 +512,20 @@ public class LLIterator<T>
505512
public class LLBackIterator<T>
506513
LLEntry<T> dummy
507514
LLEntry<T> current
515+
LinkedList<T> parent
508516
protected bool destroyOnClose = true
509517

510-
construct(LLEntry<T> dummy, bool destroyOnClose)
511-
this.dummy = dummy
518+
construct(LinkedList<T> parent, bool destroyOnClose)
519+
this.parent = parent
512520
reset()
513521
this.destroyOnClose = destroyOnClose
514522

515-
construct(LLEntry<T> dummy)
516-
this.dummy = dummy
523+
construct(LinkedList<T> parent)
524+
this.parent = parent
517525
reset()
518526

519527
function reset()
528+
this.dummy = parent.getDummy()
520529
this.current = dummy
521530

522531
/** Modifies the last element that was returned by next() (optional operation). */
@@ -537,6 +546,13 @@ public class LLBackIterator<T>
537546
retVal = current.prev.elem
538547
return retVal
539548

549+
/** Adds an element before the currently iterated element */
550+
function addBefore(T elem)
551+
let entry = new LLEntry<T>(elem, current.prev, current)
552+
current.prev.next = entry
553+
current.prev = entry
554+
parent.size++
555+
540556
function close()
541557
if destroyOnClose
542558
destroy this
@@ -567,6 +583,10 @@ constant Comparator<int> intComparator = (i1, i2) -> i1 - i2
567583
public function LinkedList<int>.sort()
568584
this.sortWith(intComparator)
569585

586+
constant Comparator<string> stringComparator = (s1, s2) -> stringCompare(s1, s2)
587+
public function LinkedList<string>.sort()
588+
this.sortWith(stringComparator)
589+
570590
public function group.asList() returns LinkedList<unit>
571591
let result = new LinkedList<unit>()
572592
this.forEachFrom() u ->
@@ -607,4 +627,4 @@ public function LinkedList<string>.join() returns string
607627
return this.joinBy("")
608628

609629
init
610-
realToIndex(0.)
630+
realToIndex(0.)

wurst/dummy/DummyCaster.wurst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import ClosureTimers
1616
* DummyCaster uses one dummy per cast, and only removes it after a set delay, to allow effects and damage to process
1717
* Example with long delay for blizzard:
1818
*
19-
* new DummyCaster(casterPos)
19+
* new DummyCaster()
20+
* ..origin(casterPos)
2021
* ..owner(caster)
2122
* ..delay(15)
2223
* ..castPoint('A000', 1, OrderIds.OrderIds.blizzard, target)
@@ -29,11 +30,16 @@ public class DummyCaster
2930
private var castCount = 0
3031
protected var delay = 5.0
3132
protected var owner = DUMMY_PLAYER
32-
protected var origin = ZERO2
33+
protected var origin = ZERO3
3334

3435
construct()
3536

37+
/** Sets the origin of the dummy with a z-value of 0 */
3638
function origin(vec2 pos)
39+
this.origin = pos.toVec3()
40+
41+
/** Sets the origin of the dummy */
42+
function origin(vec3 pos)
3743
this.origin = pos
3844

3945
/** Sets the owner of the dummy */
@@ -75,9 +81,9 @@ public class DummyCaster
7581
return dummy
7682

7783
protected function prepare(int id, int lvl) returns unit
78-
let dummy = DummyRecycler.get(origin, angle(0))
84+
let dummy = DummyRecycler.get(origin.toVec2(), angle(0))
7985
if origin.inBounds()
80-
dummy.setXY(origin)
86+
dummy.setXYZ(origin)
8187
dummy..addAbility(id)..setMana(1000000)
8288
if lvl > 1
8389
dummy.setAbilityLevel(id, lvl)

wurst/dummy/DummyDamage.wurst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import DummyRecycler
2020
*/
2121

2222
public class DummyDamage
23-
private unit dummy = DummyRecycler.get(origin, angle(0))
23+
private unit dummy = null
2424
private widget target = null
2525
private var amount = 0.
2626
private var attack = false
@@ -35,6 +35,9 @@ public class DummyDamage
3535
apply(false)
3636

3737
function apply(boolean terminate)
38+
if dummy == null
39+
dummy = DummyRecycler.get(origin, angle(0))
40+
dummy.setPos(origin)
3841
dummy
3942
..setOwner(attacker, false)
4043
..damageTarget(target, amount, attack, ranged, attackType, damageType, weaponType)
@@ -70,4 +73,5 @@ public class DummyDamage
7073
this.weaponType = weaponType
7174

7275
ondestroy
73-
DummyRecycler.recycle(dummy)
76+
if dummy != null
77+
DummyRecycler.recycle(dummy)

wurst/file/ChunkedString.wurst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class ChunkedString
9797
let lastChunk = endIndex div chunkSize
9898
for i = startChunk to lastChunk
9999
if i == startChunk
100-
out += getChunk(i).substring(startIndex - startChunk * chunkSize, min(endIndex, chunkSize))
100+
out += getChunk(i).substring(startIndex - startChunk * chunkSize, min(endIndex - startChunk * chunkSize, chunkSize))
101101
else if i == lastChunk
102102
out += getChunk(i).substring(0, endIndex - lastChunk * chunkSize)
103103
else
@@ -125,4 +125,4 @@ function chunkedStringTest()
125125
cstring.getUnsafeString().assertEquals("abcdefghijklmnopq")
126126
cstring.getUnsafeSubString(4, 12).assertEquals("efghijkl")
127127
cstring.getUnsafeSubString(0, 3).assertEquals("abc")
128-
cstring.getUnsafeSubString(15, 17).assertEquals("pq")
128+
cstring.getUnsafeSubString(15, 17).assertEquals("pq")

0 commit comments

Comments
 (0)