Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
![](https://i.imgur.com/L3xfAs4.png)

[![CircleCI](https://circleci.com/gh/wurstscript/WurstStdlib2.svg?style=svg)](https://circleci.com/gh/wurstscript/WurstStdlib2)
[![Build](https://github.com/wurstscript/WurstStdlib2/actions/workflows/build.yml/badge.svg)](https://github.com/wurstscript/WurstStdlib2/actions/workflows/build.yml)
# Wurst Standard Library

This is the repository of the WurstScript standard library which provides a vast amount of useful packages to users starting out with Wurst.
Many commonly used data structures, wc3 specific utility packages, Object Editing as well as extension wrappers for the blizzard natives have been implemented, are unit tested and therefore ready to use in production immediately.
This is the repository of the WurstScript standard library. It provides commonly used data structures, math and string utilities, Warcraft III native wrappers, and reusable WC3 systems for maps.

The repository also contains opt-in object-editing APIs and generated Warcraft III asset catalogs. These map game data into Wurst so map authors can use typed constants instead of raw IDs and paths.

Packages are unit tested and intended to be usable in production. Tests live in dedicated `*Tests` packages so production packages contain only their runtime and compiletime APIs.
Comment thread
Frotty marked this conversation as resolved.

# Motivation

Expand Down
4 changes: 0 additions & 4 deletions wurst/_handles/Destructable.wurst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Destructable
import NoWurst
import Vectors
import Wurstunit

public function createDestructable(int id, vec3 pos, angle direction, real scale, int variation) returns destructable
return createDestructable(id, pos.toVec2(), direction, scale, variation)
Expand Down Expand Up @@ -150,6 +149,3 @@ public function elevator.setHeight(int height)
if newHeight != oldHeight
this.elevatable.queueAnimation(animationQueue)

@Test function testDestructables()
let destr = createDestructable(0, ZERO2, 0 .fromDeg(), 1, -1)
destr.getX().assertEquals(0.)
7 changes: 7 additions & 0 deletions wurst/_handles/DestructableTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package DestructableTests
import Destructable
import Wurstunit

@Test function testDestructables()
let destr = createDestructable(0, ZERO2, 0 .fromDeg(), 1, -1)
destr.getX().assertEquals(0.)
9 changes: 0 additions & 9 deletions wurst/_handles/Dialog.wurst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Dialog
import NoWurst
import Wurstunit

/**
Dialogs are big dialog boxes at the center of the screen. The player can choose one button to click.
Expand Down Expand Up @@ -42,11 +41,3 @@ public function dialog.display(player whichPlayer, boolean flag)
public function dialog.setMessage(string messageText)
DialogSetMessage(this, messageText)

@Test
function testDialog()
let dia = createDialog()
dia..addButton("text")
..addQuitButton(true, "test")
..display(Player(0), true)
..clear()
..destr()
11 changes: 11 additions & 0 deletions wurst/_handles/DialogTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package DialogTests
import Dialog
import Wurstunit

@Test function testDialog()
let dia = createDialog()
dia..addButton("text")
..addQuitButton(true, "test")
..display(Player(0), true)
..clear()
..destr()
9 changes: 0 additions & 9 deletions wurst/_handles/Effect.wurst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package Effect
import NoWurst
import Quaternion
import Colors
import Wurstunit

public function effect.destr()
DestroyEffect(this)
Expand Down Expand Up @@ -214,11 +213,3 @@ public function effect.setScale(vec3 scaleVector)
public function effect.resetScale()
BlzResetSpecialEffectMatrix(this)

@Test
function testEffect()
let eff = addEffect("testPath", vec2(12,32))

eff.getLocalX().assertEquals(12.)
eff.getLocalY().assertEquals(32.)

eff.destr()
11 changes: 11 additions & 0 deletions wurst/_handles/EffectTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package EffectTests
import Effect
import Wurstunit

@Test function testEffect()
let eff = addEffect("testPath", vec2(12,32))

eff.getLocalX().assertEquals(12.)
eff.getLocalY().assertEquals(32.)

eff.destr()
5 changes: 0 additions & 5 deletions wurst/_handles/Player.wurst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Player
import NoWurst
import Wurstunit
import Unit
import Annotations
import String
Expand Down Expand Up @@ -229,7 +228,3 @@ public function player.hasVisibility(vec2 pos) returns bool
return IsVisibleToPlayer(pos.x, pos.y, this)


@Test
function testPlayer()
let p = Player(0)
assertTrue(p == Player(0))
7 changes: 7 additions & 0 deletions wurst/_handles/PlayerTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package PlayerTests
import Player
import Wurstunit

@Test function testPlayer()
let p = Player(0)
assertTrue(p == Player(0))
32 changes: 0 additions & 32 deletions wurst/_handles/Playercolor.wurst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package Playercolor
import NoWurst
import Force
import Player
import Wurstunit

public constant PLAYER_COLOR_BLACK_AGGRESSIVE = ConvertPlayerColor(24)
public constant PLAYER_COLOR_UNKNOWN1 = ConvertPlayerColor(25)
Expand Down Expand Up @@ -72,34 +71,3 @@ public function playercolor.getPlayers() returns force
return matchingPlayers


@Test public function testToInt()
PLAYER_COLOR_RED.toInt().assertEquals(0)
PLAYER_COLOR_PEANUT.toInt().assertEquals(23)

@Test public function testToPlayerColor()
assertTrue((0).toPlayerColor() == PLAYER_COLOR_RED)
assertTrue((23).toPlayerColor() == PLAYER_COLOR_PEANUT)

@Test public function testGetPlayer()
assertTrue(PLAYER_COLOR_RED.getPlayer() == Player(0))
assertTrue(PLAYER_COLOR_PEANUT.getPlayer() == Player(23))

@Test public function testGetPlayers()
// Test some Player package methods that this file depends on
(players[0] != null).assertTrue()
players[0].setColor(PLAYER_COLOR_RED)
(players[0].getColor() == PLAYER_COLOR_RED).assertTrue()
// Test getting forces of players.
let force1 = PLAYER_COLOR_RED.getPlayers()
force1.containsPlayer(Player(0)).assertTrue()
players[1].setColor(PLAYER_COLOR_BLUE)
players[2].setColor(PLAYER_COLOR_BLUE)
let force2 = PLAYER_COLOR_BLUE.getPlayers()
force2.containsPlayer(Player(1)).assertTrue()
force2.containsPlayer(Player(2)).assertTrue()
force2.containsPlayer(Player(3)).assertFalse()

let p = players[5]
assertTrue(p.getColor() == null)
p.setColor(PLAYER_COLOR_AQUA)
assertTrue(p.getColor() == PLAYER_COLOR_AQUA)
35 changes: 35 additions & 0 deletions wurst/_handles/PlayercolorTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package PlayercolorTests
import Playercolor
import Wurstunit

@Test public function testToInt()
PLAYER_COLOR_RED.toInt().assertEquals(0)
PLAYER_COLOR_PEANUT.toInt().assertEquals(23)

@Test public function testToPlayerColor()
assertTrue((0).toPlayerColor() == PLAYER_COLOR_RED)
assertTrue((23).toPlayerColor() == PLAYER_COLOR_PEANUT)

@Test public function testGetPlayer()
assertTrue(PLAYER_COLOR_RED.getPlayer() == Player(0))
assertTrue(PLAYER_COLOR_PEANUT.getPlayer() == Player(23))

@Test public function testGetPlayers()
// Test some Player package methods that this file depends on
(players[0] != null).assertTrue()
players[0].setColor(PLAYER_COLOR_RED)
(players[0].getColor() == PLAYER_COLOR_RED).assertTrue()
// Test getting forces of players.
let force1 = PLAYER_COLOR_RED.getPlayers()
force1.containsPlayer(Player(0)).assertTrue()
players[1].setColor(PLAYER_COLOR_BLUE)
players[2].setColor(PLAYER_COLOR_BLUE)
let force2 = PLAYER_COLOR_BLUE.getPlayers()
force2.containsPlayer(Player(1)).assertTrue()
force2.containsPlayer(Player(2)).assertTrue()
force2.containsPlayer(Player(3)).assertFalse()

let p = players[5]
assertTrue(p.getColor() == null)
p.setColor(PLAYER_COLOR_AQUA)
assertTrue(p.getColor() == PLAYER_COLOR_AQUA)
26 changes: 1 addition & 25 deletions wurst/_handles/Rect.wurst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Rect
import NoWurst
import Vectors
import Wurstunit

public function rect.randomPoint() returns vec2
return vec2(GetRandomReal(this.getMinX(), this.getMaxX()), GetRandomReal(this.getMinY(), this.getMaxY()))
Expand Down Expand Up @@ -84,30 +83,6 @@ public function rect.fromCenter(real sizeX, real sizeY) returns rect
public function rect.fromCenterWithOffset(real sizeX, real sizeY, vec2 offset) returns rect
let c = this.getCenter() + offset
return Rect(c.x - sizeX / 2, c.y - sizeY / 2, c.x + sizeX / 2, c.y + sizeY / 2)

@Test
function rectTest()
let rekt = Rect(2, 2, 4, 4)

rekt.width().assertEquals(2)
rekt.height().assertEquals(2)

rekt.getCenterX().assertEquals(3)
rekt.getCenterY().assertEquals(3)

rekt.moveTo(1, 1)

rekt.width().assertEquals(2)
rekt.height().assertEquals(2)

rekt.getCenterX().assertEquals(1)
rekt.getCenterY().assertEquals(1)

rekt.resize(ZERO2, vec2(4, 4))

rekt.getCenterX().assertEquals(2)
rekt.getCenterY().assertEquals(2)

public function rect.setRectFromLoc(location min, location max)
SetRectFromLoc(this, min, max)

Expand All @@ -126,3 +101,4 @@ public function rect.addWeatherEffect(integer effectID) returns weathereffect
public function rect.setDoodadAnimationRect(integer doodadID, string animName, boolean animRandom)
SetDoodadAnimationRect(this, doodadID, animName, animRandom)


28 changes: 28 additions & 0 deletions wurst/_handles/RectTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package RectTests
import Rect
import Wurstunit


@Test
function rectTest()
let rekt = Rect(2, 2, 4, 4)

rekt.width().assertEquals(2)
rekt.height().assertEquals(2)

rekt.getCenterX().assertEquals(3)
rekt.getCenterY().assertEquals(3)

rekt.moveTo(1, 1)

rekt.width().assertEquals(2)
rekt.height().assertEquals(2)

rekt.getCenterX().assertEquals(1)
rekt.getCenterY().assertEquals(1)

rekt.resize(ZERO2, vec2(4, 4))

rekt.getCenterX().assertEquals(2)
rekt.getCenterY().assertEquals(2)

31 changes: 0 additions & 31 deletions wurst/closures/ClosureTimers.wurst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import NoWurst
import TimerDialog
import TimerUtils
import Real
import Wurstunit

/** Execute an action after a certain time.
The callback object is automatically destroyed.
Expand Down Expand Up @@ -225,33 +224,3 @@ public abstract class CallbackCounted
t.release()


var x = 200
@Test function testDoAfter()

doAfter(0.1) ->
x += 50

doAfter(0.2) ->
x *= 2

doAfter(0.3) ->
x = x div 2
x.assertEquals(250)

var _count = 3

let cb = doPeriodicallyCounted(3, 3) (CallbackCounted cb) ->
cb.getCount().assertEquals(_count)
if cb.isLast()
cb.progress().assertEquals(1, 0.0001)
cb.getCount().assertEquals(1)
else if _count == 3
cb.progress().assertEquals(0.33333, 0.00001)
cb.getCount().assertEquals(3)
else if _count == 2
cb.progress().assertEquals(0.66666, 0.00001)
cb.getCount().assertEquals(2)
_count--

cb.progress().assertEquals(0, 0.00001)
cb.getCount().assertEquals(_count)
30 changes: 30 additions & 0 deletions wurst/closures/ClosureTimersTests.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ClosureTimersTests
import ClosureTimers
import Wurstunit

var x = 200

@Test function testDoAfter()
doAfter(0.1) ->
x += 50
doAfter(0.2) ->
x *= 2
doAfter(0.3) ->
x = x div 2
x.assertEquals(250)

var _count = 3
let cb = doPeriodicallyCounted(3, 3) (CallbackCounted cb) ->
cb.getCount().assertEquals(_count)
if cb.isLast()
cb.progress().assertEquals(1, 0.0001)
cb.getCount().assertEquals(1)
else if _count == 3
cb.progress().assertEquals(0.33333, 0.00001)
cb.getCount().assertEquals(3)
else if _count == 2
cb.progress().assertEquals(0.66666, 0.00001)
cb.getCount().assertEquals(2)
_count--
cb.progress().assertEquals(0, 0.00001)
cb.getCount().assertEquals(_count)
Loading