This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,401 additions
and
518 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
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
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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
src/main/java/de/edgelord/saltyengine/components/gfx/LightComponent.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,64 @@ | ||
package de.edgelord.saltyengine.components.gfx; | ||
|
||
import de.edgelord.saltyengine.core.stereotypes.ComponentParent; | ||
import de.edgelord.saltyengine.cosmetic.light.Light; | ||
import de.edgelord.saltyengine.cosmetic.light.LightSystem; | ||
import de.edgelord.saltyengine.cosmetic.light.PointLight; | ||
import de.edgelord.saltyengine.graphics.SaltyGraphics; | ||
import de.edgelord.saltyengine.scene.SceneManager; | ||
import de.edgelord.saltyengine.transform.RelationMode; | ||
import de.edgelord.saltyengine.utils.TransformRelationUtils; | ||
|
||
/** | ||
* This {@link de.edgelord.saltyengine.core.Component} makes a {@link Light} follow its parent using the rule | ||
* described in {@link #relationToParent} and {@link TransformRelationUtils}. | ||
* The light and the mode can be set in one of the constructors, if not the defaults are: | ||
* {@code RelationMode.CENTRE} | ||
* and | ||
* {@code new PointLight(parent.getTransform())} | ||
*/ | ||
public class LightComponent extends GFXComponent { | ||
|
||
private RelationMode relationToParent; | ||
private Light light; | ||
|
||
public LightComponent(ComponentParent parent, String name, RelationMode relationToParent, Light light) { | ||
super(parent, name); | ||
|
||
this.light = light; | ||
this.relationToParent = relationToParent; | ||
|
||
addToLightSystem(); | ||
} | ||
|
||
public LightComponent(ComponentParent parent, String name, Light light) { | ||
this(parent, name, RelationMode.CENTRE, light); | ||
} | ||
|
||
public LightComponent(ComponentParent parent, String name, RelationMode relationToParent) { | ||
this(parent, name, relationToParent, new PointLight(parent.getTransform())); | ||
} | ||
|
||
public LightComponent(ComponentParent parent, String name) { | ||
this(parent, name, RelationMode.CENTRE, new PointLight(parent.getTransform())); | ||
} | ||
|
||
@Override | ||
public void draw(SaltyGraphics saltyGraphics) { | ||
} | ||
|
||
@Override | ||
public void onFixedTick() { | ||
TransformRelationUtils.positionRelativeTo(relationToParent, getParent().getTransform(), light.getTransform()); | ||
} | ||
|
||
public void addToLightSystem() { | ||
LightSystem currentLightSystem = SceneManager.getCurrentScene().getLightSystem(); | ||
|
||
if (currentLightSystem == null) { | ||
throw new NullPointerException("Can't add a LightComponent when the current scene has no LightSystem! Set one by using Scene#setLightSystem!"); | ||
} | ||
|
||
currentLightSystem.addLight(light); | ||
} | ||
} |
Oops, something went wrong.