[plugin] JSON (import/export/generate/edit/inspect/...)

Post your work in progress addons and get feedback

Post » Mon Mar 24, 2014 2:36 pm

@shinkan
Yeah maybe square brackets are misleading:
Here's a better representation of what we could get

Code: Select all
// square
root[]
root["Wizard"]
root["Wizard","stats"]
root["Wizard","stats","hp"]
// curly
root{}
root{"Wizard"}
root{"Wizard","stats"}
root{"Wizard","stats","hp"}
// normal
root()
root("Wizard")
root("Wizard","stats")
root("Wizard","stats","hp")
// angle
root<>
root<"Wizard">
root<"Wizard","stats">
root<"Wizard","stats","hp">
// nothing
root
root "Wizard"
root "Wizard","stats"
root "Wizard","stats","hp"

What do you prefer?
note that's it's really only an esthetic/cosmetic consideration. It will change nothing in how it works =)
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Mon Mar 24, 2014 2:38 pm

@shinkan
What you describe is actually a (minor) bug you also have in the function plugin =)
Funny one, I never got around to report it.
But it's something that should be solved by Ashley.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Mon Mar 24, 2014 2:52 pm

Yann wrote:@shinkan
Yeah maybe square brackets are misleading:
Here's a better representation of what we could get

Code: Select all
// square
root[]
root["Wizard"]
root["Wizard","stats"]
root["Wizard","stats","hp"]
// curly
root{}
root{"Wizard"}
root{"Wizard","stats"}
root{"Wizard","stats","hp"}
// normal
root()
root("Wizard")
root("Wizard","stats")
root("Wizard","stats","hp")
// angle
root<>
root<"Wizard">
root<"Wizard","stats">
root<"Wizard","stats","hp">
// nothing
root
root "Wizard"
root "Wizard","stats"
root "Wizard","stats","hp"

What do you prefer?
note that's it's really only an esthetic/cosmetic consideration. It will change nothing in how it works =)



Though choice :D

For only one parameter "nothing" looks cleanest - root "Wizard"
but for multiple parameters "normal" have more sense to it - root("Wizard","stats","hp")

If I had to choose, I would go with "normal"


Yann wrote:@shinkan
What you describe is actually a (minor) bug you also have in the function plugin =)
Funny one, I never got around to report it.
But it's something that should be solved by Ashley.


Oh. I don't recall that in function plugin... Just double checked that and no issue here. Can TAB back and forth with "name" and "parameters" (one or many) in function plugin while creating a new function, or editing existing one.
ImageImageImageImage
B
157
S
66
G
42
Posts: 2,603
Reputation: 35,343

Post » Mon Mar 24, 2014 3:26 pm

It should be root~"Wizard","stats","hp"~

But just for Wizard
Image ImageImage
B
169
S
50
G
174
Posts: 8,325
Reputation: 110,794

Post » Mon Mar 24, 2014 8:29 pm

@shinkan
Ok my bad, I think I've seen it on the function plugin at some point but I might have dreamt that :D
Anyway, I don't think I did something wrong setting up the UI, it might be some iffy secret stuff going on Ashley side I'm not aware of. (maybe having a comboParam before a variadicParams mess things up...)

And unfortunately I don't have enough control to do "nothing if there's nothing and parenthesis if there's something"
I can only put
Code: Select all
<i>[{...}]</i>
as far as I know, to tell the plugin to display [parm0,param1,param2,...] in italic with and with 0 param it will leave the brackets the same way you still have the parenthesis even with no parameters in the function call action.

@newt nice one =)
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Mon Mar 24, 2014 8:46 pm

@vtrix
An idea for you, going back to your post about weapons:
You could put a JSON object in container with your weapon object type.

This way you could have automatic picking, but also you weapon JSON could have a structure like this:
Code: Select all
{
  "name": "rifle",
  "surname": "MyLittleRifle",
  "fireRate": 0.5,
  "damage":5,
  "bullets":[
    {type:"superbadass",perforation:5,speed:500,"fx":"flash"},
    {type:"medium",perforation:1,speed:300,"fx":"flash"},
    {type:"fake",perforation:0,speed:0,"fx":"smoke"},
  ]
}


This way you can imagine a game were weapons can be picked, dropped, with their amunitions, the amunitions can be removed, sorted, placed in other weapons, and each bullet have specific properties. The "bullets" property would be an array where the order is used to shot them sequencially.

And since it's a container, each weapon you have in your layout could have very different or random properties. And to organize your project better you can even put information about animation or frames to play/display, this way you can leave all your weapon frames in the same sprite and same for bullets.
Everything synched with just one object instead of a lot of array/dictionnary

Maybe a few things would be redundant with instance variables... but meh :D
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Mon Mar 24, 2014 11:28 pm

@Yann , great idea's, but where i was pointing at with the weapons, was an inventory that would be divided by weapontype (shields,swords,etc..) but now i already know alot more on how i would put it together.

i've made some progress with my first tests,
https://dl.dropboxusercontent.com/u/616 ... index.html
(you can click on the first icons)

basicly 3 objects as "folders", in the folders you have arrays with again objects with the data, and ofcourse inside.. theres..another array, inception!

now next will be the hard part, modifying data, connecting data, how to get a specific array entry, etc..

im wondering if everything is supposed to happen in the json object or are there parts where i should generate a c2.array and work with that and then reimport to the json
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Tue Mar 25, 2014 12:10 am

@vtrix
Not really sure what I'm looking at, but it sure looks neat :D
And it seems that you manage to get the hang of the plugin pretty well :]
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Wed Mar 26, 2014 1:40 am

:D at least it looks neat, yeah just displaying some data,

going further, so if you want to do something with an array,
lets say a drag and drop rearrange of items in the array

would you suggest to make a temp array or somehow manipulate the json array itself

well i guess the best way would be to duplicate the json array, then you can use the arrayfeatures

but then how do you work with the object inside? any insights?
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Wed Mar 26, 2014 2:18 am

Well, depends on what you want to do but in general, the basic functions you want to have with arrays are access using index and as a by product of that, being able to loop through the entries.
To loop, you just have to use the basic C2 repeat or for loop. The plugin has the JSON.Length(origin,p,a,t,h,...) expression that returns the length of the array at the given path. All you need to loop.
If you start messing with array indices though (like creating holes in the indexing) you'd have to check for undefined durring your looping.
Otherwise, other functions like push/pop/shift/unshift/insert/delete (what you would need for drag&drop and rearrange) are indeed not implemented. It's not too hard to implement via events using loop, but it would probably be better to have the javascript functions directly. Though you would only be able to push/unshift simple values (not object or array)) unless I do something like JSON.pushJSON(origin,p,a,t,h,...)... Not sure I would want to go that far.

Otherwise, the foreach loop implemented in the plugin is for looping through object (but you can use it to loop through arrays as well, though I wouldn't trust the ordering on that one)

So yeah in the end, the only feasible way to move objects arround is to so a insertJSON, pushJSON and unshiftJSON. Converting the branch of the object you want to move to JSON and that would be parsed and inserted as a new object.

I might throw a new capx with some example of that tomorrow night. If I have time =)
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

PreviousNext

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 2 guests