Inbuilt Packages¶
The inbuilt packages are used only internally but feel free to use them although please beware of modifying them as it will have global effects.
User interface¶
The user interface can be accesed in two ways:
Use this to create a new UI package, use this in exceptional circumstances.
-
ui_package:new()
Returns ui_package:
OR
This is the main method of accessing UI
Gamestate.current().ui
Parenting¶
The UI is based on a parent and child system, inother words if you create a button it is either the child of the UI itself or a frame or another item.
The use of this system should come intuitively.
All of the ui elements with the exception of a few follow this syntax:
ui:add<Item>(parent,x,y,width,height,...)
Example:
-- Creating a frame with a button on it.
local width,height = 200,200
local Frame = ui:addFrame(nil,400,300,width,height)
local doneButton = ui:addButton(frame,5,20,100,100)
doneButton:setText("Done")
-- this will create a button at 405 and 320; the 5,20 coords are relative.
doneButton.OnClick = function()
-- this will remove the Frame AND the button.
Frame:remove()
end
The parent system is cumulative meaning that you can have a parent who’s child is also a parent and so on, this is also used internally especially in lists.
Items¶
Here are all the currently implemented items and their functions.
Frame
-
ui:addFrame([parent or name],x,y,width,height,[parent])
Returns Frame: the frame item.
-
frame:addCloseButton(function)
Params function: the function executed when the X button is pressed.
-
frame:setShape(shape)
Params HardonCollider shape: the shape of the new frame.
-
frame:setImage(image)
Params love2DImage: the image to draw on the frame
-
frame:setTooltip(toolTip, delay)
Params toolTip: the pre-created tooltip Params number delay: time before the tooltip shows up.
-
frame:addTooltip(text,delay)
Params string text: the text the tooltip will display Params number delay: time before the tooltip shows up
-
frame:setSize(width,height)
-
frame:setTexture(image.wrap)
Params Love2DImage: the image for the texture. Params wrap: the wrap mode, see: Wrap Modes.
-
frame:setHeader(name,width,height.color)
Params table color: color = {r,g,b,a}
Important Variables:
dontDrawSelf ; boolean, prevents the frame from being drawn.
Events:
OnDrawTop(self)
-
Button
-
button:setTooltip(toolTip, delay)
Params toolTip: the pre made tooltip
-
button:addTooltip(text,delay)
Params string text: the text Params delay: the time required for the tooltip to appear.
-
button:setShape(shape)
Params HardonCollider shape: the shape of the new button
-
button:setSize(width,height)
-
button:setTexture(image.wrap)
Params Love2DImage: the image for the texture. Params wrap: the wrap mode, see: Wrap Modes.
Important Variables:
dontDrawB ; boolean, prevents drawing of image on button.
dontDrawC ; boolean, prevents drawing of collision.
dontDrawText ; boolean, prevents drawing text.
dontDrawActive ; boolean, prevents drawing active/inactive gestures.
-
Text
-
ui:addText([parent],x,y,text,[font],[color])
Params font: love2d font for the text.
-
text:setText(text,[font],[color])
Events:
DrawPrefix(x,y)
DrawSuffix(x,y)
-
Costum
Experimental, only use if you absolutely need to.
-
ui:addCostum(x,y,colision)
Only has draw , getColision and update
-
Tooltip
-
ui:addTooltip([parent],text,mode,[font],[color])
-
tooltip:setCenter(cx,cy,px,py)
Params numbers cx,cy: the center x and y Params numbers px,py: the parent x and y
-
tooltip:setPoints()
Resets the points.
-
Menu
-
ui:addMenu([parent],x,y,[table])
Params table: table filled in as such: { {"Run",function() salf:save() salf:run() end,10} } -- Syntax: { {Text,function,gap} }
-
menu:addChoice(text,function)
-
menu:addItem(item, function)
Params ui_item item: A UI item to be an item within the list.
-
menu:clear()
-
menu:refresh()
-
Slider
-
ui:addSlider([parent],x,y,width,height,[mode])
Params string mode: horizontal or vertical, horiz or vert for short.
-
slider:getFloat()
Returns: gets the float value in terms of percent of.
-
slider:setFloat(d)
Params float d: the float number of d, use to set the current percentage.
-
slider:setRange(min,max,isInteger)
Params bool isInteger: if you want integer only values.
-
slider:getStepSizePX()
Returns number: the number of pixels per step.
-
slider:getValue()
Returns number: the current value so if min = 100, max = 200 will return value inbetween.
-
slider:setValue(val)
Params number val: the value that lies within min and max set earlier.
-
slider:OnMove(x,y)
Event:
OnChange(value)
-
Textinput
-
ui:addTextinput([parent],x,y,width,height,text)
-
textinput:getLocalText()
-
textinput:getPosFromCords(x,y)
Params numbers x,y: the local coordinates Sets the position of the indicator at X and Y.
-
textinput:resetPos()
-
textinput:setMultiline()
Enables multi-line.
-
textinput:getText()
Returns text: the concatenated text.
-
textinput:setAllowed(a)
Params table a: the table full of strings you don’t want to see in your input.
-
textinput:moveLine(bool)
Params bool: false for down, true for up
-
textinput:setText(text)
Params string text: the text as a long string.
Events:
OnChange(text)
-
List
-
ui:addList([parent],x,y,width,height,[items],[mode])
Params bool [mode]: True if you want horizontal mode.
-
list:setHeader(text)
-
list:addChoice(text,function)
-
list:addItem(item,position)
Params ui_Item item:
-
list:refresh()
-
list:setMode(horizontal,vertical)
Params booleans horizontal,vertical:
-
list:getStencil()
Returns function:
-
list:goMax()
Sets the position to maximum.
-
list:clear()
-
list:getLeftOver()
Returns number: the leftover space at either the sides or top and bottom.
-
list:removeItem(item)
Params ui_item item:
-
Shared
-
<item>:getColision()
Returns HardonCollider shape:
-
<item>:addItem(item)
Params ui_item item:
-
<item>:setInactive(t)
Params bool t:
-
<item>:moveTo(x,y)
-
<item>:remove()
Events:
-
[*] This might be used internally so be careful when assigning.
Important Variables:
dontDraw = boolean; do not draw self.
inList = boolean; is it in the list?
Note
Some items have internal items:
Slider: sliderButton [button]
Menu, List, textInput: mainFrame [frame]
Base[UI]
-
ui:getItemCount()
-
ui:clear()
-
ui:getZorder()
-
ui:draw(debug)
-
ui:update(dt)
-
ui:mousepressedList(x,y,button)
-
ui:textinput(t)
-
ui:getmxb()
Returns HardonCollider_shape: the shape used for the mouse.
-
ui:init(Collider)
-
ui:getFont()
Returns love2Dfont:
-
ui:setMousePos(x,y)
-
ui:setTitleIncrement(degree)
-
ui:setLeftClick(main,alt)
Params booleans main,alt: the main and alt left clicks. Run at update.
-
ui:setRightClick(main,alt)
Params booleans main,alt: the main and alt right clicks. Run at update.
-
ui:setMiddleMouse(down,up)
Params booleans down,up: the down and up for middle mouse Run at update.
-
ui:setFont(font)
Params Love2dFont font:
-
Note
Some internal use functions are omitted.
Editor specific¶
Module admin¶
Module admin primarily designed for internal usage, please use with care!
to get module admin:
local ma = Gamestate.current().moduleAdmin
-
ma:newModule(directory,name)
Returns module:
-
ma:seekInstance(module,own)
Params numbers module,own: the registry numbers that the module and instance owns. Returns instance:
-
ma:getModules()
Returns: table of modules.
-
ma:getModulesFrom(dir,make)
Params string dir: the directory where the modules are. Params boolean make: if the module should be created. Returns table: in format {dir = string,name = string,derivatives = table}
-
ma:make(table)
Params table: in format {dir = string,name = string,derivatives = table}
-
ma:save(map,[source or filter].parents)
Params string map: Params string source: Params filter: the filter function(module), return module. Params table parents: Use: getParents()
-
ma:saveModule(module,map,source,parents)
Params Module module: Params string map: Params string source: source directory. Params table parents: Use: getParents()
Returns table: the table with the saved module.
-
ma:checkModule(src,name,instances,parents)
Params src: source directory Params name: name of the module Params table instances: the modules instances Params table parents: Use: getParents()
-
ma:load(map,table,parents)
Params string map: Params table: the table where all of the modules were saved into. Params table parents: Use: getParents()
-
ma:getInstances()
Returns table: of instances
-
ma:clear()
Module¶
-
module:seek(derivative)
Params string derivative: the name of the derivative.
-
module:getInstances()
Returns table instances:
-
module:addDeriv(dir,name)
Params string dir: the source directory of the derivative Patams string name: the name of the derivative.
-
module:addInstance(name,x,y,zmap)
Params string name: the name of the source derivative Params numbers x,y: the position in game world Params number zmap: the z position in game world Returns instance:
-
module:remove()
Trigger admin¶
To get the trigger admin handle:
local ta = Gamestate.current().triggerAdmin()
-
ta:setEnviroment(global)
Prams table global: the pairs table with globals. :returns table enviroment: use in coalition with setfenv.
-
ta:getEnviroment()
Returns table enviroment:
-
ta:load(t)
Params table t: the table with saved triggers.
-
ta:getModes()
Returns table: table of strings of trigger modes.
-
ta:exec(function,var)
Params function: a function to execute Params var: the self variable.
-
ta:addTrigger(item)
Params Editor_item item: the item that exists within the editor. Returns Trigger: the trigger module used below.
Trigger¶
-
Trigger:setActiv(mode,fns)
Params string mode: the mode of action Params function fns: the function to execute.
-
Trigger:save()
Returns table:
-
Trigger:load(t)
Params table t: the table previously made using Trigger:save()
Image admin¶
To get the image admin use:
local ia = Gamestate.current().imageAdmin
-
ia:addImage(sheet,quad,x,y,rotation,scale_x,scale_y)
Params Sheet sheet: the sheet from texture manager. Params Quad quad: from the sheet. Returns Image:
-
ia:clear()
-
ia:getItems()
-
ia:save()
-
ia:load(tables,tm,gamestate)
Params TextureManager tm: link to texture manager Params gamestate: the current gamestate
Image¶
-
Image:unpack()
-
Image:mirror()
-
Image:flip()
-
Image:setScale(sx,sy)
-
Image:setZmap(z)
-
Image:setRotation(r)
Params number r: In radians!
-
Image:setMod(modx,mody)
Params numbers modx,mody: the modifiers in x and y directions, used for parallax.
-
Image:makeColision()
-
Image:update(dt)
-
Image:getPos()
Returns numbers x,y: position
-
Image:rotate(r)
Params number r: in radians
-
Image:draw(DEBUG)
Params bool DEBUG: debug for drawing wireframe etc
-
Image:remove()
-
Image:OnMenu(menu,ui)
Params ui_item menu: Params ui_package ui:
Shape admin¶
To get the shape admin do:
local sa = Gamestate.current().shapeAdmin
-
sa:newRectangle(mode,x,y,width,height,color)
Params string mode: the mode, “fill” or “line” Returns Rectangle:
-
sa:newCircle(mode,x,y,r,color)
Params string mode: “fill” or “line” Returns Circle:
-
sa:newPolygon(mode,x,y,points,color)
Params string mode: “fill” or “line” Params table points: the table full of points eg {x,y,x2,y2} Returns Polygon:
-
sa:newLine(color,x,y)
Returns Line:
Rectangle¶
rectangle:setPointOfCreation(x,y)
params numbers x,y: the position of creation.
Circle¶
circle:setRadius(r)
params number r: Radius in radians.
Polygon¶
polygon:setPoints(points)
params table points:
Line¶
line:addPoint(x,y)
line:addTempPoint(x,y)
Params numbers x,y: the x and y position of the temporary point.
line:update(key,key2)
Params booleans key,key2: key is for left click and key2 is for middle click for edit mode.
line:makeSilent(x)
Params bool x: sets silent mode.
line:remove()
line:makeColision()
line:draw()
line:checkPoints()
line:returnPoints()
Returns table: of points, use in coalition with polygon:setPoints()
Textures¶
There are two modules for textures:
Texture manager¶
local tm = Gamestate.current().textureManager
Note
functions that start with pr are used for once only loads.
-
tm:newSheet(name,image)
Params string name: of the new sheet. Params love2dImage image: Returns Sheet:
-
tm:prNewSheet(name,image)
Returns Sheet: Does NOT add it to the active sheets.
-
tm:remove([sheet or sheet_name])
Params Sheet sheet: Params string sheet_name: the name of the sheet
-
tm:addSheet(sheet)
Parameters: sheet (Sheet) –
-
tm:seek(sheet)
Params string sheet: the name of the sheet Returns Sheet:
-
tm:save(map,parents)
Params string map: Params table parents: Use: getParents()
-
tm:load(map,parents)
Params string map: Params table parents: Use: getParents()
-
tm:unpack()
Returns table: to save using Tserial.
-
tm:clear()
-
tm:prLoad(map)
Parameters: map (string) –
Sheet¶
-
sheet:addQuad(name,x,y,w,h,delay,frame1,frame2)
Params numbers x,y,w,h: position and dimensions Params delay,frame1,frame2: the beginning and end frames and the delay between them.
-
sheet:getImage()
Returns love2DImage:
-
sheet:seek(s,remove)
Params string s: the name of the quad Params bool remove: if you want to remove the sheet; pass true
-
sheet:getQuads()
Returns table,image: full of quads, then the sheets image.
-
sheet:getQuad(name)
Returns Love2dQuad: the individual quad.
-
sheet:save()
-
sheet:remove()
-
sheet:applyEdit()
Texture mapper¶
local tmap = Gamestate.current().textureMapper
-
tmap:new(shape,img.quad)
Params Shape shape: shapeAdmin shape. Params Love2DImage img: Params Quad quad:
-
tmap:setImage(img,quad)
Params Love2DImage img: Params Quad quad:
-
tmap:update(dt)
-
tmap:updateCol()
Call when the points of your Shape changes.
-
tmap:draw(sx,sy)
Params numbers sx,sy: scalex and scaley
-
tmap:remove()
Text admin¶
to get text admin:
local ta = Gamestate.current().textAdmin
-
ta:addText(x,y,z,font)
Params numbers x,y,z: coordinates. Params love2DFont font: Returns Text:
-
ta:load(data)
Params: table of saved text.
Text¶
-
Text:setText(t,font)
Params string t: the text Params love2DFont: the font
The Text inherits the following functions:
getColision
, draw
, update
, OnMenu
, OnMenu
, OnCopy
, setMod
, save
, remove
However it does not include ``load`` !
layers¶
To manage z coordinates I decided to produce a layer system, it is supposed to replicate the layer method just like in that of graphics production software including photoshop etc.
Obviously it is still missing a bulk of features such as the ability to add effects and drawing methods, but this is coming soon when I sort out some performance issues.
To get layers:
local layers = Gamestate.current().layers
-
layers:update(dt)
Params number dt: delta time.
-
layers:clear()
-
layers:unpack(zmap)
Params number zmap: the zmap of the target layer.
-
layers:save()
Returns table: the table with all the saved data.
-
layers:load(a)
Params table a: the table retrieved from layers:save()
-
layers:getRange()
Returns numbers min,max: the range of z cords in use.
-
layers:seek(zmap)
Params number zmap: the z coord of the target layer.
-
layers:removeLayer([layer or zmap])
Params Layer layer: Params number zmap: the z coord of the layer.
-
layers:move(l,z)
Params Layer l: Params number z: the new z cordinate.
-
layers:moveLayers(old,new)
-
layers:addLayer(name,zmap,modx,mody,col,sound,transp)
Params stirng name: the identifying name of the layer. Params numbers zmap,modx,mody: the z coord and modifier position. Params booleans col,sound: Params number transp: transparency, out of 255 Returns Layer:
Layer¶
-
Layer:getMod()
Returns numbers modx,mody:
-
Layer:setParalax(x,y)
Params numbers x,y: the modifiers
-
Layer:setColision(col)
Params boolean col: if the layer enables collision.
-
Layer:setName(name)
Params string name: the new name of the layer.
-
Layer:setData(name,zmap,modx,mody,col,sound,transp)
Same params as
layers:addLayer()
-
Layer:unpack()
Returns: name,zmap,modx,mody,col,sound,transp
Map admin¶
The map admin is a table of functions used for drawing and parsing the map.
Be very careful when modifying these functions.
Note
The self parameter in the functions bellow relates to a State such as Play,Editor or Battle.
-
mapAdmin.
parse
(active, passive, self)¶ Params table active: HardonCollider active shapes. Params table passive: HardonCollider passive shapes. Returns table: active shapes.
-
mapAdmin.
scanModules
(self, collider, ret)¶ Params HardonCollider collider: Params table ret: return table. Returns table: of modules.
-
mapAdmin.
updateSingle
(shape, dt)¶ Params Instance shape: the instance as found from parse/parseSingle
-
mapAdmin.
parseHead
(self)¶ parses the head portion, use for Editor only.
-
mapAdmin.
parseSingle
(self, shape, dt, rt[, cond or filter])¶ Params HardonCollider_shape shape: Params table rt: return table for priority instances. Params boolean cond: if the instance should be updated or not. Params function filter: filter that either allows an instance through or not
-
mapAdmin.
parseTail
(self, dt)¶ Params number dt: delta time. Used for Editor only.
-
mapAdmin.
draw_visible
(self, zmap, current_zmap)¶ Params none zmap: used for legacy. Params number current_zmap: the current zmap.
-
mapAdmin.
mousepressed
(self, mxb, x, y, b)¶ Params mxb: use ui:getmxb()
Params x,y: position of the click Params string b: the keyConstant.
-
mapAdmin.
updateCol
(self, mxb)¶ Params mxb: use ui:getmxb()
-
mapAdmin.
shapeCol
(self, mxb, dt, a, b)¶ Params mxb: use ui:getmxb()
Params HardonCollider_shapes a,b: the shapes colliding
-
mapAdmin.
shapeStop
(self, mxb, dt, a, b)¶ Params mxb: use ui:getmxb()
Params HardonCollider_shapes a,b: the shapes colliding
-
mapAdmin.
clear
(collider, self)¶ Params HardonCollider collider:
-
mapAdmin.
save
(self, name, items)¶ Params string name: the map name. Params table items: a table of instances.
-
mapAdmin.
load
(self, file)¶ Params string file: the filename of the map.