ZeToX2007
offline
Опыт:
7,009Активность: |
Loading structs from SLK files
Собсвенно уже дошёл до этого в vJass... но из-за своего английского ничего не понял. собственно там про что написано ?
» Очень много букв Loading structs from SLK files It is possible to load (convert) an slk into code to be added to the map's script, specifically struct assigments. This can be really useful when a system uses structs to store data, since SLK is a table format it can save some work and make things easier to edit without the manual struct assigning. The preprocessor to load an slk file is //! loaddata "path.slk" . The file path argument follows exactly the same rules as the ones I already specified in import (including lookup folders) Both the slk and the struct type to be loaded need to follow very specific rules. The SLK The SLK file requires to have an struct name at (row 1, column 1) Then the first row contains field names, the next rows contain a [key] and values for the names specified up there. stname this is just an example 1 2 3 4 5 6 7 8 9 10 11 12 In the example, the name of the struct type to be loaded is stname, the keys of the instances that will be loaded are 1 and 7, and the rest is information about fields and values. The struct type The struct type to be used (in the example, stname) requires a getFromKey static method that returns a value of the struct type. getFromKey() would simply convert a key value and return an equivalent struct, this is because you often want data structs to be related to something else. (Most of the times the [something else] will be an object id.) For this example, getFromKey would have to take an integer value The struct type also requires to have the fields declared in the SLK file, the SLK is not forced to list all the fields of the struct type. So if we have this struct definition: struct stname integer this integer is integer just integer an integer example static stname array values static method getFromKey takes integer i returns nothing if (stname.values[i]!=0) then set values[i]=stname.create() endif return stname.values[i] endmethod endstruct And we also load the SLK from the previous example, the loaded init code would be: set s=stname.getFromKey(1) set s.this=2 set s.is=3 set s.just=4 set s.an=5 set s.example=6 set s=stname.getFromKey(7) set s.this=8 set s.is=9 set s.just=10 set s.an=11 set s.example=12 Notice that this code is then run after the struct and libraries initialization For a more practical explanation check out the SLK demo included in the JassHelper distribution. |
22.08.2009, 22:38 | #1
+0/−0
Профиль |
Приват |
Поиск |
Цитата |
IP: Записан
|
ZeToX2007
offline
Опыт:
7,009Активность: |
Может кто нибудь поможет всё таки?)
ZeToX2007 добавил: Может кто нибудь поможет всё таки?) |
26.08.2009, 15:43 | #2
+0/−0
Профиль |
Приват |
Поиск |
Цитата |
IP: Записан
|
SageOne
x
offline
Опыт:
46,054Активность: |
ZeToX2007, а на что есть интернет переводчики? Самому было влом, перевел Сократом...
» Еще больше букв
Загрузка structs из файлов SLK
Возможно должно загружать (преобразование) slk в код, который нужно добавлять к сценарию карты, особо struct assigments. Это может быть действительно полезным когда система использует structs, чтобы загружать данные, с тех пор как SLK - табличный формат, который он может сохранить некоторую работу и делать вещами легче, чтобы редактироваться без ручного struct правопреемника.
Препроцессор, чтобы загружать slk файл - ! loaddata "path.slk". Файловый аргумент пути следует за точно теми же правилами как те Я уже определил в импорте (включая папки поиска)
Как slk так и тип struct, чтобы быть загруженн нужно следовать за очень специфическими правилами.
SLK Файл SLK требует иметь имя struct в (погребите 1, столбец 1) Затем первая колонка содержит имена области, следующие колонки содержат [key] и величины для имен определенных по там.
stname это - просто пример 1 2 3 4 5 6 7 8 9 10 11 12 В примере, имя типа struct, чтобы быть загруженн - stname, клавиши примеров, которые будут загружены, - 1 и 7, и остальные - информация об областях и величинах.
Тип struct Тип struct, чтобы быть использованн (в примере, stname), требует статический метод getFromKey, который возвращает величину типа struct.
getFromKey(), должно просто преобразовывать ключевую величину и возвращать эквиалентный struct, дело в том, что Вы часто хотите, чтобы данные structs обусловливались нечто другое. (Наиболее время [something else] будет объектом id.)
Для этого примера, getFromKey должен бы взять величину целого
Тип struct также требует объявить области в файл SLK, SLK не вынужден указывать все области типа struct.
Так если у нас есть это struct определение:
struct stname
integer this integer is integer just integer an integer example static stname array values
static method getFromKey takes integer i returns nothing
if (stname.values[i]!=0) then set values[i]=stname.create() endif return stname.values[i] endmethod endstruct
И мы также загружаем SLK из предшествующего примера, загруженный init код должен быть:
set s=stname.getFromKey(1)
set s.this=2 set s.is=3 set s.just=4 set s.an=5 set s.example=6 set s=stname.getFromKey(7) set s.this=8 set s.is=9 set s.just=10 set s.an=11 set s.example=12 Обратите внимание как этот код был, тогда работайте после инициализация struct и библиотек
Для более практического объяснения, подтвердите SLK демонстрационный включенный в распределении JassHelper. |
26.08.2009, 16:22 | #3
+0/−0
Профиль |
Приват |
Поиск |
Цитата |
IP: Записан
|
Van Damm
wait... what?
offline
Опыт:
22,268Активность: |
Это вряд ли тебе понадобится. Фишка позволяет загружать данные в структуры из внешних SLK-файлов.
|
26.08.2009, 17:28 | #4
+0/−0
Профиль |
Приват |
Поиск |
Цитата |
IP: Записан
|