Logo

[Theming] Help with Text files (RageFileUtil)

Register Log In Back To Forums

Post #1 · Posted at 2015-10-02 12:28:46am 8.5 years ago

Offline Th3_Ov3rHell_3XoduZ
Th3_Ov3rHell_3XoduZ Avatar Member
313 Posts
Chile
Reg. 2012-09-13

"ITG, The Best Dance Machine!"

Last updated: 2015-10-02 12:29am
Hi, I have been working on my theme all this time, specifically with the Custom Theme Colors, I have set up on my theme that each player can save 16 differents colors. This means that in total there's 32 slots. But I would like to change this to, instead just lets save colors for each player, makes that for differents profiles. That each profile have its own colors.

http://orig13.deviantart.net/4e8d/f/2015/274/3/d/untitled_by_ov3rhell3xoduz-d9bllcc.png

The only way I think I could make this is with text files. I tried using RageFileUtil but i cant make it work. Also, idk how to get the path for the profile folder. If someone can help me to start with make text files and use them. That would be great. ty.
Quote: Released Themes for SM5 Beta 3
Quote: Released Themes for SM5 Beta 4 & 5.0.7
Quote: Simfles Packs Released

Post #2 · Posted at 2015-10-02 02:15:56am 8.5 years ago

Offline Kyzentun
Kyzentun Avatar Member
3,209 Posts
United States
Reg. 2008-02-20

"I'm honestly pissed off."
I already have a good system for storing per-profile configuration, so I'm just going to talk about it instead. It's better than the ThemePrefs system because it's designed to store any lua table that contains strings, numbers, or tables. It actually handles changes somewhat better too; if you change the config in the theme, the config loaded from a profile will be updated to match. (which might lead to people needing to reset their settings. Plan config changes well)

Copy 00 settings_system.lua and string_needs_escape() and lua_table_to_string() from Consensual into your own Scripts. Change the "settings_prefix" variable at the top to something for your theme. Then make a new file in Scripts for your player config (spawncamping-wallhack has a simple example).
The "create_setting" function returns an object that is used to load and save the config for a profile. The args are the config name, the filename to save the config in, the table of default values, the match depth, and the exceptions list.
Usually you want the match depth to be -1. The match depth is how deep the system goes to make sure that the loaded config has the same table elements as the default config. So if the default config looks like this "{ cat_color= {1, 1, .5, 1}, dog_color= {.5, .5, .75, 1} }", when the config is loaded for a profile the system will make sure the config has two tables, one named "cat_color", and one named "dog_color", each with 4 numbers in it. If the match depth were 1, then the system would force the "cat_color" and "dog_color" tables to exist, but it would not force them to have 4 numbers. If the match depth is 0, then the loaded config doesn't have to be similar to the default config at all.
The exceptions list is a table of names of elements that don't have to be similar to the default config. It's meant for cases that can't be handled by changing the match depth. You probably don't need it, so you can just leave it off.

I typically create a global variable to store the object returned by create_setting, in the same file the default config is in. Then when a profile is loaded, I call the load function to load the data for that profile. When a profile is saved, if the data is dirty, call the save function. sc-wh has a simple example of this in the file I linked, the LoadProfileCustom and SaveProfileCustom functions. I think it's better to make the screen that edits the config set the dirty flag only if the config is changed, but ca25nada decided to take the lazy route and always mark the config as dirty.

When you need to get the config data for a profile, you call get_data on the object, with the profile slot you want the data for. So if the config object is named "playerConfig", you do "local p1_config= playerConfig:get_data(pn_to_profile_slot(PLAYER_1))", an p1_config will be a table identical in structure to your default config, filled with the data loaded from the profile. (sc-wh example)
Change the values in the table when the player changes their config. Then set the dirty flag by calling set_dirty on the object (like sc-wh does in its SaveProfileCustom function). When the save function is called on the object, only the slots that are dirty will actually be saved.

This same system can be used for theme-wide preferences that aren't tied to a profile by passing nil everywhere that you would normally pass a profile slot.
silenttype01: Kyzentun is never harsh. He says it how it is.

GENERATION 24: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Post #3 · Posted at 2015-10-02 02:53:23am 8.5 years ago

Offline Th3_Ov3rHell_3XoduZ
Th3_Ov3rHell_3XoduZ Avatar Member
313 Posts
Chile
Reg. 2012-09-13

"ITG, The Best Dance Machine!"
Ok, i have set up all the files, I modified the default table with the elements I need, and put a value to each one... Now i tested if I can get a value from that table and yes I get... The part i got confused is, how exactly I can save and modify those values. I dont know how to save cuz the folder has been created.
Quote: Released Themes for SM5 Beta 3
Quote: Released Themes for SM5 Beta 4 & 5.0.7
Quote: Simfles Packs Released

Post #4 · Posted at 2015-10-02 03:20:09am 8.5 years ago

Offline Kyzentun
Kyzentun Avatar Member
3,209 Posts
United States
Reg. 2008-02-20

"I'm honestly pissed off."
Modify the values in the table you get from calling get_data. Then call set_dirty to mark it so it'll be saved when you call save.
I'm not sure what was misunderstood, since I went over this in the fourth paragraph.
silenttype01: Kyzentun is never harsh. He says it how it is.

GENERATION 24: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
Register Log In Back To Forums

0 User(s) Viewing This Thread (Past 15 Minutes)

©2006-2024 Zenius -I- vanisher.com -5th style- IIPrivacy Policy
Web Server: 5% · Database: 4% · Server Time: 2024-04-26 20:06:54
This page took 0.004 seconds to execute.
Theme: starlight · Language: englishuk
Reset Theme & Language