Hi,
I'm writing a small wrapper around a bank to make it a bit easier to use it.
When my wrapper is used, the programmer creates a layout of how the information in the bank is stored. Here is some code to show how:
(In a RPG looking way)
GSL_INT is equal to 4, since an Int uses 4 bytes. I also have GSL_BYTE, GSL_SHORT, GSL_FLOAT and so on...
I don't have one for strings, so the 8 in the array means 8 bytes (chars) is used for the name.
Everything works just fine. I also have a method in the type that returns the offset in bytes:
Using that method I can get the offset i should peek/poke in the bank. But my "problem" comes when I want to use all this:
This is not a pretty sight. This is what I want some help with. How should I do to simplify it?
I could creade peekint/pokeint, peekbyte/pokebyte and so on in my type but I am looking for something better. If at all possible.
What I want is something like this:
But the "get" method needs to be able to return bytes,ints,floats,etc and that isn't possible, afaik.
Anyone got any idea?
I'm writing a small wrapper around a bank to make it a bit easier to use it.
When my wrapper is used, the programmer creates a layout of how the information in the bank is stored. Here is some code to show how:
(In a RPG looking way)
Local save:TGameSave = TGameSave.create() ' Format the layout ' name (string), hp, hpmax, mana, manamax, gold Local layout:Int[] = [ 8, GSL_INT, GSL_INT, GSL_INT, GSL_INT, GSL_INT ] save.create_layout( layout )
GSL_INT is equal to 4, since an Int uses 4 bytes. I also have GSL_BYTE, GSL_SHORT, GSL_FLOAT and so on...
I don't have one for strings, so the 8 in the array means 8 bytes (chars) is used for the name.
Everything works just fine. I also have a method in the type that returns the offset in bytes:
Method get_offset( fs_index ) Local off = 0 If fs_index < 0 Or fs_index >= Len( bank_layout ) Then Return -1 ' error For Local i = 0 Until fs_index off:+bank_layout[i] Next Return off EndMethod
Using that method I can get the offset i should peek/poke in the bank. But my "problem" comes when I want to use all this:
Print "Pokes some stuff into the savefile..." save.bank.PokeInt( save.get_offset(1), 73 ) save.bank.PokeInt( save.get_offset(2), 100 ) save.bank.PokeInt( save.get_offset(3), 20 ) save.bank.PokeInt( save.get_offset(4), 20 ) save.bank.PokeInt( save.get_offset(5), 143 ) Print "Peeks some stuff from the savefile:" Print "HP : "+save.bank.PeekInt( save.get_offset(1) )+"/"+save.bank.PeekInt( save.get_offset(2) ) Print "MANA: "+save.bank.PeekInt( save.get_offset(3) )+"/"+save.bank.PeekInt( save.get_offset(4) ) Print "GOLD: "+save.bank.PeekInt( save.get_offset(5) )
This is not a pretty sight. This is what I want some help with. How should I do to simplify it?
I could creade peekint/pokeint, peekbyte/pokebyte and so on in my type but I am looking for something better. If at all possible.
What I want is something like this:
local hero_hp = save.get( 1 ) local hero_mana = save.get( 3 )
But the "get" method needs to be able to return bytes,ints,floats,etc and that isn't possible, afaik.
Anyone got any idea?