What the mod does
ATG QR Codes draws QR codes in game, for anything easier to photograph than to type — a Discord invite on a message-of-the-day card, a registration link on a screen, a URL on a noticeboard.
Codes are generated at runtime from whatever text you hand it. Nothing is pre-rendered, nothing is fetched from the internet, and the encoder is self-contained.
It depends on nothing but the base game, deliberately, so that it sits at the bottom of a mod list and anything above it can reach for it.
There is nothing here for a server owner to configure. This mod has no settings and draws nothing on its own. It is a tool for other mods, and a server loads it because something else on the list wants it.
Putting a code on screen
One call. Give it a widget to live in and the text it should carry:
#ifdef ATG_QRCODES_PRESENT
ATG_QRCodeDisplay code = ATG_QRCodePanel.Create(myContainer, "https://discord.gg/example");
if (!code)
myContainer.SetVisible(false);
#endif
myContainer is any widget of yours — an overlay, a size layout, a frame. The panel
stretches to fill it and then squares itself inside whatever space that turns out to be,
so the container decides how big the code is. Give it somewhere around 240 px or
more; below that the modules get too small for a phone to resolve off a monitor.
Create returns the component driving the code, or null if the text could not be
encoded or the panel could not be built. Every failure is logged with its reason, so
there is nothing to diagnose at the call site — decide whether to hide the space you set
aside, and nothing else.
To change what an existing code says, keep the component and call SetText on it rather
than building a second one:
code.SetText("https://discord.gg/somewhere-else");
What you get
- The ATG mark in the middle, on a light island that keeps it clear of the code around it.
- Error-correction level HIGH, which is what makes the mark survivable: a reader rebuilds the modules it covers from error-correction codewords spread across the whole symbol.
- A four-module quiet zone, drawn on its own light background so the panel works over any surface. Codes routinely fail to scan without one.
- The smallest symbol that fits your text, chosen automatically.
Limits
- Up to 58 characters. Longer is refused and logged rather than drawn unreadably.
- Printable ASCII only. URLs are percent-encoded and never need more; anything outside that range is refused, because what a reader would make of it depends on an encoding the symbol has no way to state.
Load order
The #ifdef above is defined by this mod, so ATG QR Codes has to load before yours.
Enfusion compiles every loaded addon into one script module in load order, and a
#define is only visible to addons compiled after it.
A mod does not have to list this one in its addon.gproj to pick the symbol up — it only
has to load later. On a server that ordering comes from the mod list in the server
config; in Workbench it is the order the addons are loaded in.
The failure is silent. With the order wrong the guarded block compiles out, no code is drawn, and nothing is logged. If your call appears to do nothing at all, check the order first.
A code without the ATG mark
Deliberately more work, and there is no shortcut for it.
Author a layout of your own: put a CanvasWidget in it, attach an ATG_QRCodeDisplay
component, and set that component’s attributes — m_sCanvasWidgetName to your canvas’s
name, m_bShowLogo to off, or m_sLogoTexture to a mark of your own. Then create your
layout and call SetText on the component, which ATG_QRCodeDisplay.FindOn(yourRootWidget)
will find for you.
m_fLogoScale is the mark’s width as a fraction of the code’s, and it is capped at
0.35. Past roughly that width codes start failing to scan, whatever the
error-correction level.
If you only want the module grid and intend to draw it yourself,
ATG_QRCode.Generate(text, level) returns an ATG_QRCodeMatrix and nothing else —
GetSize() and IsDark(x, y) are the whole of it. You are then responsible for the
quiet zone.