Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecs-gestalt): Migrate Components to gestalt's Components. #31

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
/*
* Copyright 2015 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.gestalt.entitysystem.component.EmptyComponent;

/**
* A marker class that indicates if an {@link EntityRef} is rotatable by a screwdriver.
*/
public class RotateableByScrewdriverComponent implements Component {
public class RotateableByScrewdriverComponent extends EmptyComponent<RotateableByScrewdriverComponent> {
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.EmptyComponent;

/**
* A component that indicates the {@link EntityRef} it is attached to is a screwdriver item.
*/
public class ScrewdriverComponent implements Component {
public class ScrewdriverComponent extends EmptyComponent<ScrewdriverComponent> {
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.world.block.RequiresBlockLifecycleEvents;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.reflection.MappedContainer;

import java.util.Set;
import java.util.stream.Collectors;

/**
* A component that indicates the {@link EntityRef} it is attached to is a signal conductor.
* Holds information about conductor's input / output sides.
*/
@RequiresBlockLifecycleEvents
public class SignalConductorComponent implements Component {
public class SignalConductorComponent implements Component<SignalConductorComponent> {
public Set<ConnectionGroup> connectionGroups;

@Override
public void copyFrom(SignalConductorComponent other) {
this.connectionGroups = other.connectionGroups.stream()
.map(ConnectionGroup::copy)
.collect(Collectors.toSet());
}

/**
* Maps a signal conductor entity's input / output sides.
*/
@MappedContainer
public static class ConnectionGroup {
public byte inputSides;
public byte outputSides;

ConnectionGroup copy() {
ConnectionGroup newCG = new ConnectionGroup();
newCG.inputSides = this.inputSides;
newCG.outputSides = this.outputSides;
return newCG;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import com.google.common.collect.Maps;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -24,10 +12,15 @@
* Keeps track of the signal strength on each side of an entity
* Used in SetResetGate
*/
public class SignalConsumerAdvancedStatusComponent implements Component {
public class SignalConsumerAdvancedStatusComponent implements Component<SignalConsumerAdvancedStatusComponent> {
/**
* To get the String representing the side, use BlockNetworkUtil.getResultSide(Block, Side).name()
* -1 is infinite signal, 0 is no signal
*/
public Map<String, Integer> signalStrengths = new HashMap<>();

@Override
public void copyFrom(SignalConsumerAdvancedStatusComponent other) {
this.signalStrengths = Maps.newHashMap(other.signalStrengths);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.block.RequiresBlockLifecycleEvents;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Indicates that an Entity can recieve a Signal
*/
@RequiresBlockLifecycleEvents
public class SignalConsumerComponent implements Component {
public class SignalConsumerComponent implements Component<SignalConsumerComponent> {
//Represents which sides can be connected to, use the SideBitFlag class to interpret this value
public byte connectionSides;
//Represents the operation used for a logic gate
public SignalConsumerComponent.Mode mode = Mode.AT_LEAST_ONE;


@Override
public void copyFrom(SignalConsumerComponent other) {
this.connectionSides = other.connectionSides;
this.mode = other.mode;
}

public enum Mode {
AT_LEAST_ONE, ALL_CONNECTED, EXACTLY_ONE, SPECIAL
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Keeps track of whether or not the entity is recieving a signal.
*/
public class SignalConsumerStatusComponent implements Component {
public class SignalConsumerStatusComponent implements Component<SignalConsumerStatusComponent> {
public boolean hasSignal;

@Override
public void copyFrom(SignalConsumerStatusComponent other) {
this.hasSignal = other.hasSignal;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
/*
* Copyright 2015 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import com.google.common.collect.Lists;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.math.Side;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.List;

Expand All @@ -26,7 +13,13 @@
* The gateType determines the function, and can either be AND, OR, XOR, or NAND.
* functionalSides represents the sides that can affect the gate. There is only one output side, the rest can be input.
*/
public class SignalGateComponent implements Component {
public class SignalGateComponent implements Component<SignalGateComponent> {
public String gateType;
public List<Side> functionalSides = Lists.newArrayList();

@Override
public void copyFrom(SignalGateComponent other) {
this.gateType = other.gateType;
this.functionalSides = Lists.newArrayList(other.functionalSides);
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.block.RequiresBlockLifecycleEvents;
import org.terasology.gestalt.entitysystem.component.Component;
/**
* The component that is added to an entity to allow it to produce a signal.
* The connection sides are the sides that the signal can flow through.
* The signal strength can be either finite or infinite.
* Infinite is represented by -1, 0 represents no signal.
*/
@RequiresBlockLifecycleEvents
public class SignalProducerComponent implements Component {
public class SignalProducerComponent implements Component<SignalProducerComponent> {
public byte connectionSides;
public int signalStrength;

@Override
public void copyFrom(SignalProducerComponent other) {
this.connectionSides = other.connectionSides;
this.signalStrength = other.signalStrength;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.EmptyComponent;

/**
* Responsible for keeping track of whether a signal producer has been modified.
* The presence or abscence of this component is used to store this data.
*/
@ForceBlockActive
public class SignalProducerModifiedComponent implements Component {
public class SignalProducerModifiedComponent extends EmptyComponent<SignalProducerModifiedComponent> {
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.signalling.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;
/**
* Responsible for keeping track of the time delay in a signal
*/
public class SignalTimeDelayComponent implements Component {
public class SignalTimeDelayComponent implements Component<SignalTimeDelayComponent> {
/** delaySetting is the amount of time it is being delayed in milliseconds */
public long delaySetting;

@Override
public void copyFrom(SignalTimeDelayComponent other) {
this.delaySetting = other.delaySetting;
}
}
Loading