X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fdatasource.qc;h=d51a1f74893682130152f79b07a742747165fcc2;hb=ac55e67fb51bbd9a4d878c830df885f18715ef11;hp=49cc571761885e394686651985b548d98af1f7c7;hpb=1556aa4ea70b3b275afb1cb4587e555fb44f71c3;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/datasource.qc b/qcsrc/menu/xonotic/datasource.qc index 49cc57176..d51a1f748 100644 --- a/qcsrc/menu/xonotic/datasource.qc +++ b/qcsrc/menu/xonotic/datasource.qc @@ -1,23 +1,39 @@ -#ifndef DATASOURCE_H -#define DATASOURCE_H -CLASS(DataSource, Object) - entity DataSource_true; - entity DataSource_false; - INIT_STATIC(DataSource) { - DataSource_true = NEW(Object); - DataSource_false = NULL; +#include "datasource.qh" + + CONSTRUCTOR(StringSource, string str, string sep) + { + CONSTRUCT(StringSource); + this.StringSource_str = str; + this.StringSource_sep = sep; + } + METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) + { + int n = tokenizebyseparator(this.StringSource_str, this.StringSource_sep); + if (i < 0 || i >= n) return DataSource_false; + string s = argv(i); + if (returns) returns(s, string_null); + return DataSource_true; + } + METHOD(StringSource, reload, int(entity this, string filter)) + { + return tokenizebyseparator(this.StringSource_str, this.StringSource_sep); + } + + CONSTRUCTOR(CvarStringSource, string cv, string sep) + { + CONSTRUCT(CvarStringSource); + this.CvarStringSource_cvar = cv; + this.StringSource_sep = sep; + } + METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) + { + string s = this.CvarStringSource_cvar; + this.StringSource_str = s ? cvar_string(s) : string_null; + return SUPER(CvarStringSource).getEntry(this, i, returns); + } + METHOD(CvarStringSource, reload, int(entity this, string filter)) + { + string s = this.CvarStringSource_cvar; + this.StringSource_str = s ? cvar_string(s) : string_null; + return SUPER(CvarStringSource).reload(this, filter); } - /** - * get entry `i` passing `name` and `icon` through `returns` if it is not null - * returns `DataSource_false` if out of bounds - * otherwise returns an entity or `DataSource_true` - */ - METHOD(DataSource, getEntry, entity(int i, void(string name, string icon) returns)) { return DataSource_false; } - /** return the index of the first match for `find`. optional */ - METHOD(DataSource, indexOf, int(string find)) { return -1; } - /** reload all entries matching `filter` returning how many matches were found */ - METHOD(DataSource, reload, int(string filter)) { return 0; } - /** cleanup on shutdown. optional */ - METHOD(DataSource, destroy, void(entity)) { } -ENDCLASS(DataSource) -#endif