# Writing Levels for GraphColoring
The `assets/levels` folder contains [XML](https://en.wikipedia.org/wiki/XML) files which describe levels.
If you would like to submit a level, please create a pull request.
## `level-list.xml`
The file `assets/levels/level-list.xml` contains a list of level categories and their levels in XML format. It should be relatively clear how to add a new level or category. Note that you will need to delete your `saves` directory or update the version number in `level-list.xml` if you change it for the application to update the levels once you close and re-open it.
## Level XML format overview
In the `assets/levels` directory, there is one folder for each category. Each level is stored as a .xml file in its category's directory and has the following nodes:
- `` - This will control the text displayed at the top of the level. You can create multi-line descriptions with `;` as a delimiter.
- `` and `` - If you add protections to these, all of the vertices/edges in the graph node will have those protections.
- `...` - A list of colors the level will be using.
- `...` - A description of the starting graph
- `...` - Restrictions on the graph.
- `...` - Variables, most importantly `points` and `objective`.
- `...` and `...` - Paths and cycles
## Colors
The `` node contains `` children nodes. Each child node defines a color name. For example, the node `` will allow you to use "red" for vertex colors.
Each `` node can have the following attributes:
- `color` (e.g. `color="#FF0000"`) (required) - This attribute's value is the hex code of the color. It is in hexadecimal format and can be either #RRGGBB or #RRGGBBAA.
- `name` (e.g. `name="red"`) (required) - This is the name which will stand in for the color when creating vertices.
- `vertex-points` (e.g. `vertex-points="3"`) - This is the number of points you will get for creating a vertex with this color. Defaults to 0.
- `edge-points` (e.g. `edge-points="-1"`) - This is the number of points you will get for creating an edge with this color. Defaults to 0.
## Graph
The `` has `` and `` children.
### Vertices
Each `` node describes a vertex and can have the following attributes:
- `x`, `y` (e.g. `x="450" y="350"`) (required) - The x- and y-coordinates of this vertex.
- `id` (e.g. `id="top-left"`) - The ID of this vertex. Used for defining edges and in the `` node. If left empty, the vertex will not have an ID.
- `color` (e.g. `color="red"`)- The color of this vertex. Defaults to the first defined color.
- `origin` (e.g. `origin="t"`) - If a vertex has this attribute, it will be a connectedness origin (i.e. it will be filled in at the start). There can be multiple origins. The value of this attribute is ignored.
- `protect` (e.g. `protect="cde"`) - The protections for this vertex. See Protections section for how to format these.
### Edges
Each `` node describes an edge and can have the following attributes:
- `v1`, `v2` (e.g. `v1="top-left" v2="top-right"`) (required) - The IDs of the vertices which this edge connects.
- `id` (e.g. `id="top-edge"`) - The ID of this edge. Used in the `` node. If left empty, the edge will not have an ID.
- `color` (e.g. `color="red"`) - The color of this edge. Defaults to the first defined color.
- `protect` (e.g. `protect="cd"`) - The protections for this edge. See Protections section for how to format these.
### Protections
Protections can be added to any `` or `` using the `protect` attribute. Vertices and edges can have these protections:
- `c` - Protect the color of the vertex (it will not be editable by the user).
- `d` - Protect the vertex from being deleted.
- `e` - (Vertices only) Disallow the user from adding an edge to/from the vertex.
The `protect` attribute's value is a string containing the characters for all of its protections, e.g. `protect="cd"` for protecting the color and protecting deletion.
#### Global Protections
Global protections are defined in the `` and `` nodes. Both of them can have a `protect` attribute which will apply those protections to all the vertices or edges. There is one additional protection, `a`, which protects new vertices or edges from being added.
For example, `` will protect new vertices from being added, and prevent coloring vertices.
## Rules
The rules node contains the following types of children:
- `` - This node has no attributes and just specifies that the graph must be connected.
- `` or `maximum>` - These are bound rules which specify a minimum or maximum number of vertices or edges.
- `` - These rules describe which colors vertices and edges can be.
### Bound rules
Bound rules can be one of four nodes: ``, ``, ``, or ``. Bound rules limit the number of vertices or edges of a color. For example, `` will restrict the number of red vertices to a maximum of 7.
#### Any and same
If the `color` attribute is `any` (which it defaults to), this will restrict the total number of vertices or edges. For example, `` will restrict the total number of vertices to 3.
If the `color` attribute is `same`, this will restrict all colors at once. For example `` will mean that the user cannot create more than 3 of any color of vertex.
### Edge rules
`` nodes bans edges with the given endpoint and edge colors. The node has the following attributes:
- `v1` - The color of the first vertex.
- `edge` - The color of the edge.
- `v2` - The color of the second vertex.
All these attributes default to `any`.
For example, `` will ban edges from red vertices to red vertices with red edges.
#### Any and same
If any color is specified as `any`, it will be banned for all colors.
For example, `` will ban all edges from red vertices to red vertices, regardless of the edge color.
If any color is specified as `same`, it will be banned for all colors, but if there are multiple uses of `same`, there is the additional requirement that the two `same`s are the same color.
For example, whereas `` bans all edges, `` bans edges from any two vertices of the same color.
## Values
The following nodes can be children of the `` node:
- `` - A comment. For most other nodes, invalidly-named nodes will be ignored, but this is not the case for ``.
- `` - Include values from another file. The file name can be specified through the `file` attribute (e.g., `` will include `assets/levels/includes/foo.xml`).
- `` - Variables. The format of this node is described below.
- `` - Value-based operations. The format of this node is described below.
- `