全面战争:战锤3

全面战争:战锤3

Variant Selector
Marthenil  [开发者] 2023 年 4 月 13 日 下午 6:52
Community functionality
Discussions about community functions etc go here
< >
正在显示第 1 - 10 条,共 10 条留言
LazyIcarus 2022 年 11 月 27 日 下午 4:34 
Hi, I have mods that dynamically adjust the art set and I'd like it so that variant selector only shows amongst all the variants unlocked so far. I've implemented this by exposing two global functions. Could you please add this to the main mod so I don't have to maintain a fork of this mod? This would also enable a more transparent way of adding variants since they run actual code rather than returning a table from a file.

---Global function to allow dynamically changing variant options ---@param character_subtype_key string ---@param art_set_ids table Table with numerical keys each mapping to an art set ID function Set_character_variants(character_subtype_key, art_set_ids) variants_table[character_subtype_key] = art_set_ids; -- no need to rebuild anything since the UI components are generated only when opened end ---Global function to alert variant selector that a variant for a character has been changed by an external source, ---presumably the same source that called Set_character_variants since they need to know what each index corresponds to ---@param character_cqi integer|string ---@param variant_index integer function Has_set_character_variant(character_cqi, variant_index) character_variant_index[tostring(character_cqi)] = variant_index; end
Marthenil  [开发者] 2022 年 11 月 28 日 上午 1:01 
I was already passing setfenv to the loaded files so you can load code in them as well (well, technically you already can, just no game functions) next update, but yeah more control is better, I'll add something like that too.
LazyIcarus 2022 年 11 月 28 日 下午 5:27 
Not too familiar with lua so not sure if passing setfenv is sufficient for what my mods need. They listen for in game events to unlock and switch to variants. For example, waits for turn 15 to pass. This is what I meant by "dynamically" - during the course of a play session rather than variants loaded upon loading the game.
Marthenil  [开发者] 2022 年 11 月 28 日 下午 5:54 
Basically using setfenv (and passing the game environment to the loaded chunk) would make Variant Selector files pretty much equivalent to any old lua file loaded through "script/campaign/mod".They already are perfectly valid lua chunks but because they don't get the function environment you can't call game functions within them, just basic lua stuff.

It wouldn't be sufficient for your purpose though (at least as is) cause the return is only read once.
Still, it's useful for other cases, say you can read if a mod is installed and if that's true return X variant table or else return Y variant table.
最后由 Marthenil 编辑于; 2022 年 11 月 28 日 下午 5:56
LazyIcarus 2022 年 11 月 28 日 下午 8:29 
I see... That's a bit low level and dependent on mod load order right? Your mod would have to be loaded after the mods you want to check if they're installed. Glad to hear it'll be added in the next update. Please allow assigning entire art set tables for character subtypes like I've proposed above, rather than going for an incremental "update" and "remove" API. I need to manage which of the variants' been unlocked and variant selector is only an optional dependency so it can't be the only source of truth for it.
Marthenil  [开发者] 2023 年 4 月 13 日 下午 12:29 
Kinda late but this is now a thing.
LazyIcarus 2023 年 4 月 13 日 下午 1:37 
Nice, will take a look into the new code to see how to make my stuff compatible
LazyIcarus 2023 年 4 月 13 日 下午 4:24 
Is it possible to capitalize the first letter of these global functions? I think the general convention is to have capitalized first letter snake case for global functions and snake case for local functions (as you current have)
Marthenil  [开发者] 2023 年 4 月 13 日 下午 6:48 
No, CA formatting is all snakecase with no capitals, even for globals, imma keep it like that. HOWEVER, I should probably make the global a single object that contains all the functions, instead.

And done.
最后由 Marthenil 编辑于; 2023 年 4 月 13 日 下午 7:06
Marthenil  [开发者] 2023 年 4 月 14 日 上午 8:09 
Alright alright alright, this is the final update for these functions. From now on they are set in stone and I'm not touching their names or functionality again. (I might do some type-checking and error reporting later)
< >
正在显示第 1 - 10 条,共 10 条留言
每页显示数: 1530 50