- Joined
- Sep 6, 2013
- Messages
- 6,743
Code
Readme
In the default settings integer and string vectors are supported.
So it requires your VectorT library support vectors of type string to let it run!
Add this line in your VectorT config:
Examples:
JASS:
library Sequence /* v1.2 -- 12.11.2017 -- By IcemanBo -- https://www.hiveworkshop.com/threads/sequencet.274244/#post2772894
*/ requires /*
*/ VectorT /* hiveworkshop.com/forums/submissions-414/containers-vector-t-248942/
*/ Alloc /* any alloc.
*/
// Read the readme before config.
// ================ Config =================== //
//! novjass
// To define sequence types we have to run following textmacro
textmacro SEQUENCE takes SEQUENCE, SEQUENCE_TYPE, VECTOR_TYPE, TYPE
SEQUENCE
// The struct name of the sequence
SEQUENCE_TYPE
// The struct name of the sequence type
VECTOR_TYPE
// The vector struct type name that defines the sequence type
TYPE
// The type that a sequence stores
//! endnovjass
//! runtextmacro SEQUENCE("IntegerSequence", "IntegerSequenceType", "IntegerVector", "integer")
// For integer sequences
//! runtextmacro SEQUENCE("StringSequence", "StringSequenceType", "StringVector", "string")
// For string sequences
// Read the readme for the system's API
// ================ End Config =================== //
//! textmacro SEQUENCE takes SEQUENCE SEQUENCE_TYPE VECTOR_TYPE, TYPE
struct $SEQUENCE_TYPE$ extends array
implement Alloc
readonly $VECTOR_TYPE$ vector
readonly integer size
static method create takes $VECTOR_TYPE$ vec returns thistype
local thistype this = allocate()
set this.vector = $VECTOR_TYPE$[vec]
set this.size = vec.size()
return this
endmethod
method destroy takes nothing returns nothing
call this.vector.destroy()
call this.deallocate()
endmethod
endstruct
struct $SEQUENCE$ extends array
implement Alloc
readonly $SEQUENCE_TYPE$ sequence
readonly boolean isSolved
readonly boolean isInputCorrect
readonly integer currentPosition
method onSequenceEvent takes $TYPE$ input returns nothing
set this.isInputCorrect = (input == this.sequence.vector[this.currentPosition])
if (this.isInputCorrect) then
set this.currentPosition = this.currentPosition + 1
set this.isSolved = this.currentPosition >= this.sequence.size
else
set this.isSolved = false
endif
endmethod
method setPos takes integer pos returns boolean
if pos > 0 and pos <= this.sequence.size then
set this.currentPosition = pos
return true
endif
return false
endmethod
method destroy takes nothing returns nothing
call deallocate()
endmethod
static method create takes $SEQUENCE_TYPE$ sequ, integer startPos returns thistype
local thistype this = allocate()
set this.currentPosition = startPos
set this.sequence = sequ
return this
endmethod
endstruct
//! endtextmacro
endlibrary
Readme
JASS:
/*
Sequence Readme v1.2 -- 12.11.2017
===== Introduction =====
A sequence is a defined order of data of one type. If all data is correctly
given through the input for a sequence, the sequence can be seen as solved.
Note:
Sequences work with vectors from VectorT library. If you want create
a sequence of a new type, you also have to create the VECTOR_TYPE respectivly.
===== Technical info =====
Sequences of type string and integer are supported by default.
To add more types you need to run the textmacro in Sequence config.
===== API ===== */
/* You now need to create a sequence type that can be used: */
struct $SEQUENCE_TYPE$
static method create takes $VECTOR_TYPE$ vec returns thistype
// constructor
method destroy takes nothing returns nothing
// destructor
readonly $VECTOR_TYPE$ vector
readonly integer size
// readonly members
/* Now you can create new instances of the sequence type */
struct SEQUENCE
static method create takes SEQUENCE_TYPE sequ, integer startPos returns thistype
// constructor
// startPos is the position where you want to start. Usually it should be 0.
method destroy takes nothing returns nothing
// destructor
/* To give input to the sequence interact with using this method */
method onSequenceEvent takes $TYPE$ input returns nothing
readonly boolean isSolved
readonly boolean isInputCorrect
readonly integer currentPosition
// readonly members
// it makes sense to read this members after onSequenceEvent was called
In the default settings integer and string vectors are supported.
So it requires your VectorT library support vectors of type string to let it run!
Add this line in your VectorT config:
//! runtextmacro DEFINE_VECTOR("", "StringVector", "string")
Examples:
- http://www.hiveworkshop.com/forums/spells-569/arrowkeysequence-v3-0-a-273573/?prev=status=p&of=dateline&o=ASC&imporder=1
^Here above I use integer sequences, but you can create sequences of anything you want. - It is possible for example to create a unit sequence.
So when a user selects certain 3 units correctly in a row a sequence can be solved. - UnitTypes that are trained by a specific unit in correct order.
- Levers that are destroyed in correct order.
- User types correct strings in order
Last edited: