Scirra / Construct-feature-requests

A place to submit feature requests and suggestions for Construct.
https://www.construct.net
11 stars 1 forks source link

JSON: Add more ACE #8

Open XHXIAIEIN opened 10 months ago

XHXIAIEIN commented 10 months ago

Reviewed guidelines

Checked for duplicate suggestions

JSON expression: JSON.CurIndex

We need an expression like loopindex for use in a For each loop of a JSON object.

JSON.CurIndex

Currently, it is necessary to Add a new local variable externally to record it, which is very cumbersome.

Snipaste_2024-01-08_21-25-53

Why is this idea important?

This helps to use data structures better.

When Loop in this structure, it is very inconvenient if you want to know which number it is (for example, used to ID for objects in menu).

{
    "1000":{"id": "1000", "name": "apple"},
    "1001":{"id": "1001", "name": "banana"},
    "1002":{"id": "1002", "name": "carrot"}
}
XHXIAIEIN commented 10 months ago

JSON expression: JSON.KeyCount

Dictionary has the useful KeyCount expression, but the JSON object does not have it.

Add JSON.KeyCount(path) expressions like Object.keys(path).length. Return the number of keys in Path.

This is very useful for statistics and UI lists. For example, if you want to create objects based on the number of keys in the path. And assign index numbers to these objects

Currently, you have to access the path via JSON: For each and create a local variable outside to count, which is very cumbersome.

XHXIAIEIN commented 10 months ago

JSON action: Stop Loop

We also need Stop Loop action.

When Loop in this structure, When you find a matching value, need a 'Stop loop' so that it does not traverse the entire file.

[
    {"id": "1000", "name": "apple"},
    {"id": "1001", "name": "banana"},
    {"id": "1002", "name": "carrot"}
]
XHXIAIEIN commented 10 months ago

JSON condition: 'is Empty'

is Empty condition can be used to check whether the object at the path is empty.This is still very useful. For example, it is used to detect the quantity of UI, inventory, item, Achievement, Status Entry, etc.

"data": []
"data": {}
"data": ""

Snipaste_2024-01-08_21-55-01

XHXIAIEIN commented 10 months ago

JSON expression: GetDefault

Dictionary has the useful GetDefault() expression, but the JSON object does not have it.

I would appreciate if JSON would also get this functionality as it is very handy.

GetDefault(key, valueIfMissing)

Return the value stored for a key, but if it is missing, return a different value instead. For example Dictionary.GetDefault("name", "guest") will return the value of the key "name" if it exists, otherwise it will return the string "guest".

XHXIAIEIN commented 10 months ago

JSON action: For Each(Ordered)

order any JSON array or object by their keys and/or by their values (ascending/descending), For example, it is very useful when you want to add sorting functionality to the UI.

Snipaste_2024-01-09_17-08-46

for example:

[
    {"id": "7001", "name": "banana"},
    {"id": "1002", "name": "carrot"},
    {"id": "2024", "name": "apple"}
]

Order By "id"

{"id": "1002", "name": "carrot"},
{"id": "2024", "name": "apple"}
{"id": "7001", "name": "banana"},

Order By "id.name"

{"id": "2024", "name": "apple"}
{"id": "7001", "name": "banana"},
{"id": "1002", "name": "carrot"},
xtrad commented 9 months ago

I really agree,

Construct should add more attention to this plugin, because this plugin is very important in game development