ID:2365279
 
(See the best response by Lummox JR.)
I'm working on a manually-operated card game project, and I'm curious about the methods BYOND has for storing a large number of sets of numbers and strings. Since it's manually-driven and thus it's unnecessary to give individual cards unique behaviors, making each and every card its own unique obj seems a bit excessive when to compared to pointing the card obj to a database or list and having it grab stuff like its name, description, and icon from it, but I'm not familiar enough with how BYOND operates to tell which to use and what's the best way to set such a thing up.
Well, one easy option is JSON. Define your cards in a JSON file, and then load that up to get a list via json_decode(). Your icon files would have to be stored in a subdirectory on your server, since they wouldn't automatically be added to the cache on compile.
That's something I was eyeing, especially since it could potentially allow for individual servers to add their own custom cards. Is there a good way to load every .json file in a particular subdirectory, and if so, is there anything I should keep in mind to prevent potential malicious abuse?

Your icon files would have to be stored in a subdirectory on your server, since they wouldn't automatically be added to the cache on compile.

Could you clarify? I don't really have context on how BYOND knows what icons to load, from my experience it just seems to load them automatically ( even if they're uploaded by a user ) when a client encounters them.
Best response
Specifically, I would create a directory under your project called card_icons and make sure that its contents get distributed with the server code. All the icons referenced in the JSON file could be there, and then you'd load the icon with something like icon = file("card_icons/" + card["icon"]) (assuming card is an associative list loaded from json_decode).

The way icons are normally handled in BYOND is by using single quotes around the file name. This tells the system to create a cache entry in the .rsc file for that icon, and the single-quoted value is a reference to that cache entry. But since you want to define your cards outside of the source, this isn't so much an option. So those icons have to be loaded into the .dyn.rsc file at runtime instead, creating new cache entries on the fly.

You might have something like this:

card
var/name
var/icon

New(list/data)
name = data["name"]
icon = file("card_icons/" + data["icon"])

/*
File data would be expected like this:

[
{"name": "Blast", "icon": "blast.png"},
{"name": "Hide", "icon": "hide.png"}
]
*/


var/list/global_cards
proc/LoadCards(fname)
var/i
var/card/C
global_cards = json_decode(file2text(fname))
for(i in 1 to global_cards.len)
C = new/card(global_cards[i])
// Change the list so we can lookup a card by name
global_cards[i] = C.name
global_cards[C.name] = C