Handle array merging

This commit is contained in:
ChronosX88 2023-12-11 21:54:07 +03:00
parent f7da23a939
commit 096f3c4387

View File

@ -3,6 +3,7 @@ package io.github.chronosx88.JGUN.storage;
import io.github.chronosx88.JGUN.api.NodeChangeListener;
import io.github.chronosx88.JGUN.models.graph.*;
import io.github.chronosx88.JGUN.models.graph.NodeValue;
import io.github.chronosx88.JGUN.models.graph.values.ArrayValue;
import java.util.*;
@ -102,7 +103,14 @@ public abstract class Storage {
.build())
.build();
}
changedNode.values.put(key, value);
if (value.getValueType() == NodeValue.ValueType.ARRAY) {
// handle appending element to array instead of rewriting
ArrayValue array = (ArrayValue) changedNode.getValues().getOrDefault(key, new ArrayValue(List.of()));
array.getValue().addAll(((ArrayValue) value).getValue());
value = array;
}
changedNode.getValues().put(key, value);
changedNode.getMetadata().getStates().put(key, state);
}