-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add foundation for binding script variables
- Loading branch information
1 parent
0d96ff2
commit 3370922
Showing
9 changed files
with
331 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/org/cyclops/integratedscripting/api/item/IScriptVariableFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.cyclops.integratedscripting.api.item; | ||
|
||
import org.cyclops.integrateddynamics.api.item.IVariableFacade; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* Variable facade for variables that refer to a script. | ||
* @author rubensworks | ||
*/ | ||
public interface IScriptVariableFacade extends IVariableFacade { | ||
|
||
/** | ||
* @return The script disk id. | ||
*/ | ||
public int getDisk(); | ||
|
||
/** | ||
* @return The path to the script inside the disk. | ||
*/ | ||
public Path getPath(); | ||
|
||
/** | ||
* @return The referenced member element inside the file referred to by the path inside the disk. | ||
*/ | ||
public String getMember(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...va/org/cyclops/integratedscripting/core/client/model/ScriptingVariableModelProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.cyclops.integratedscripting.core.client.model; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import org.cyclops.integrateddynamics.IntegratedDynamics; | ||
import org.cyclops.integrateddynamics.api.client.model.IVariableModelProviderRegistry; | ||
import org.cyclops.integrateddynamics.core.client.model.SingleVariableModelProvider; | ||
import org.cyclops.integratedscripting.Reference; | ||
|
||
/** | ||
* Collection of variable model providers. | ||
* @author rubensworks | ||
*/ | ||
public class ScriptingVariableModelProviders { | ||
|
||
public static final IVariableModelProviderRegistry REGISTRY = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableModelProviderRegistry.class); | ||
|
||
public static final SingleVariableModelProvider SCRIPT = REGISTRY.addProvider(new SingleVariableModelProvider(new ResourceLocation(Reference.MOD_ID, "customoverlay/script"))); | ||
|
||
public static void load() {} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/cyclops/integratedscripting/core/evaluate/ScriptVariableFacadeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.cyclops.integratedscripting.core.evaluate; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandler; | ||
import org.cyclops.integratedscripting.Reference; | ||
import org.cyclops.integratedscripting.api.item.IScriptVariableFacade; | ||
import org.cyclops.integratedscripting.core.item.ScriptVariableFacade; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* Handler for script variable facades. | ||
* @author rubensworks | ||
*/ | ||
public class ScriptVariableFacadeHandler implements IVariableFacadeHandler<IScriptVariableFacade> { | ||
|
||
private static final IScriptVariableFacade INVALID_FACADE = new ScriptVariableFacade(false, -1, Path.of(""), ""); | ||
private static ScriptVariableFacadeHandler _instance; | ||
|
||
private ScriptVariableFacadeHandler() { | ||
|
||
} | ||
|
||
public static ScriptVariableFacadeHandler getInstance() { | ||
if(_instance == null) _instance = new ScriptVariableFacadeHandler(); | ||
return _instance; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUniqueName() { | ||
return new ResourceLocation(Reference.MOD_ID, "script"); | ||
} | ||
|
||
@Override | ||
public IScriptVariableFacade getVariableFacade(int id, CompoundTag tag) { | ||
if(!tag.contains("disk", Tag.TAG_INT)) { | ||
return INVALID_FACADE; | ||
} | ||
if(!tag.contains("path", Tag.TAG_STRING)) { | ||
return INVALID_FACADE; | ||
} | ||
if(!tag.contains("member", Tag.TAG_STRING)) { | ||
return INVALID_FACADE; | ||
} | ||
return new ScriptVariableFacade(id, tag.getInt("disk"), Path.of(tag.getString("path")), tag.getString("member")); | ||
} | ||
|
||
@Override | ||
public void setVariableFacade(CompoundTag tag, IScriptVariableFacade variableFacade) { | ||
tag.putInt("disk", variableFacade.getDisk()); | ||
tag.putString("path", variableFacade.getPath().toString()); | ||
tag.putString("member", variableFacade.getMember()); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
src/main/java/org/cyclops/integratedscripting/core/item/ScriptVariableFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.cyclops.integratedscripting.core.item; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import net.minecraft.client.renderer.block.model.BakedQuad; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.client.model.data.ModelData; | ||
import org.cyclops.integrateddynamics.api.client.model.IVariableModelBaked; | ||
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue; | ||
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType; | ||
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable; | ||
import org.cyclops.integrateddynamics.api.network.IPartNetwork; | ||
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; | ||
import org.cyclops.integrateddynamics.core.item.VariableFacadeBase; | ||
import org.cyclops.integratedscripting.api.item.IScriptVariableFacade; | ||
import org.cyclops.integratedscripting.core.client.model.ScriptingVariableModelProviders; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** | ||
* Variable facade for variables determined by proxies. | ||
* @author rubensworks | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
public class ScriptVariableFacade extends VariableFacadeBase implements IScriptVariableFacade { | ||
|
||
private final int disk; | ||
private final Path path; | ||
private final String member; | ||
|
||
public ScriptVariableFacade(boolean generateId, int disk, Path path, String member) { | ||
super(generateId); | ||
this.disk = disk; | ||
this.path = path; | ||
this.member = member; | ||
} | ||
|
||
public ScriptVariableFacade(int id, int disk, Path path, String member) { | ||
super(id); | ||
this.disk = disk; | ||
this.path = path; | ||
this.member = member; | ||
} | ||
|
||
@Override | ||
public <V extends IValue> IVariable<V> getVariable(IPartNetwork network) { | ||
if(isValid()) { | ||
// TODO: get variable of script from scripting network | ||
// IVariable<V> variable = getTargetVariable(network).orElse(null); | ||
// return variable; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
return disk >= 0; | ||
} | ||
|
||
@Override | ||
public void validate(IPartNetwork network, IValidator validator, IValueType containingValueType) { | ||
// TODO: validation | ||
// Optional<IVariable> targetVariable = getTargetVariable(network); | ||
// if (!isValid()) { | ||
// validator.addError(Component.translatable(L10NValues.VARIABLE_ERROR_INVALIDITEM)); | ||
// } else if (network.getScript(proxyId) == null) { | ||
// validator.addError(getScriptNotInNetworkError()); | ||
// } else if (!targetVariable.isPresent()) { | ||
// validator.addError(getScriptInvalidError()); | ||
// } else if (!ValueHelpers.correspondsTo(containingValueType, targetVariable.get().getType())) { | ||
// validator.addError(getScriptInvalidTypeError(network, containingValueType, | ||
// targetVariable.get().getType())); | ||
// } | ||
|
||
getVariable(network); | ||
} | ||
|
||
@Override | ||
public IValueType getOutputType() { | ||
return ValueTypes.CATEGORY_ANY; | ||
} | ||
|
||
protected List<Component> getScriptTooltip() { | ||
return List.of( | ||
Component.translatable("script.integratedscripting.tooltip.disk", getDisk()), | ||
Component.translatable("script.integratedscripting.tooltip.path", getPath()), | ||
Component.translatable("script.integratedscripting.tooltip.member", getMember()) | ||
); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
public void appendHoverText(List<Component> list, Level world) { | ||
if(isValid()) { | ||
list.addAll(getScriptTooltip()); | ||
} | ||
super.appendHoverText(list, world); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
public void addModelOverlay(IVariableModelBaked variableModelBaked, List<BakedQuad> quads, RandomSource random, ModelData modelData) { | ||
if(isValid()) { | ||
quads.addAll(variableModelBaked.getSubModels(ScriptingVariableModelProviders.SCRIPT).getBakedModel().getQuads(null, null, random, modelData, null)); | ||
} | ||
} | ||
} |
Oops, something went wrong.