Skip to content

Commit

Permalink
Merge pull request #465 from refinedmods/feat/GH-93/portable-grid-menu
Browse files Browse the repository at this point in the history
Portable grid menu
  • Loading branch information
raoulvdberge authored Dec 31, 2023
2 parents bc8bca8 + ebc21f3 commit 2020283
Show file tree
Hide file tree
Showing 75 changed files with 1,510 additions and 762 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Custom disk models. Fluid disks now have a different model.
- Portable Grid

### Changed

- The Portable Grid now shows an energy bar in the UI.
- The energy bar on creative items now shows the infinity symbol instead of the whole amount.

## [2.0.0-milestone.3.2] - 2023-11-03

### Added
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import java.util.List;
import java.util.Optional;

class MultiStorageExposedStorage<T> extends AbstractImmutableConfiguredProxyStorage<T, CompositeStorageImpl<T>>
class ExposedStorage<T> extends AbstractImmutableConfiguredProxyStorage<T, CompositeStorageImpl<T>>
implements CompositeStorage<T>, CompositeAwareChild<T> {
protected MultiStorageExposedStorage(final StorageConfiguration config) {
protected ExposedStorage(final StorageConfiguration config) {
super(config, new CompositeStorageImpl<>(new ResourceListImpl<>()));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage;

import com.refinedmods.refinedstorage2.api.network.component.StorageProvider;
import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState;
import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage;
import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.StorageState;
import com.refinedmods.refinedstorage2.api.storage.TypedStorage;
import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType;

import java.util.ArrayList;
Expand All @@ -28,13 +30,13 @@ public class MultiStorageNetworkNode extends AbstractStorageNetworkNode implemen
@Nullable
private MultiStorageProvider provider;
@Nullable
private MultiStorageListener listener;
private StateTrackedStorage.Listener listener;

private final long energyUsage;
private final long energyUsagePerStorage;

private final MultiStorageInternalStorage<?>[] cache;
private final Map<StorageChannelType<?>, MultiStorageExposedStorage<?>> exposedStorages;
private final TypedStorage<?, StateTrackedStorage<?>>[] cache;
private final Map<StorageChannelType<?>, ExposedStorage<?>> exposedStorages;
private int activeStorages;

public MultiStorageNetworkNode(final long energyUsage,
Expand All @@ -44,10 +46,10 @@ public MultiStorageNetworkNode(final long energyUsage,
this.energyUsage = energyUsage;
this.energyUsagePerStorage = energyUsagePerStorage;
this.exposedStorages = createExposedStorages(storageChannelTypes);
this.cache = new MultiStorageInternalStorage[size];
this.cache = new TypedStorage[size];
}

private Map<StorageChannelType<?>, MultiStorageExposedStorage<?>> createExposedStorages(
private Map<StorageChannelType<?>, ExposedStorage<?>> createExposedStorages(
final Collection<? extends StorageChannelType<?>> storageChannelTypes
) {
return storageChannelTypes.stream().collect(Collectors.toUnmodifiableMap(
Expand All @@ -56,8 +58,8 @@ private Map<StorageChannelType<?>, MultiStorageExposedStorage<?>> createExposedS
));
}

private MultiStorageExposedStorage<?> createExposedStorage(final StorageChannelType<?> type) {
return new MultiStorageExposedStorage<>(this);
private ExposedStorage<?> createExposedStorage(final StorageChannelType<?> type) {
return new ExposedStorage<>(this);
}

public void setProvider(final MultiStorageProvider provider) {
Expand Down Expand Up @@ -86,23 +88,18 @@ public void onStorageChanged(final int index) {
@SuppressWarnings({"rawtypes", "unchecked"})
private Set<StorageChange> initializeStorage(final int index) {
final Set<StorageChange> results = new HashSet<>();

if (cache[index] != null) {
final StorageChannelType<?> removedType = cache[index].getStorageChannelType();
final MultiStorageExposedStorage<?> relevantComposite = exposedStorages.get(removedType);
results.add(new StorageChange(true, relevantComposite, cache[index]));
final StorageChannelType<?> removedType = cache[index].storageChannelType();
final ExposedStorage<?> relevantComposite = exposedStorages.get(removedType);
results.add(new StorageChange(true, relevantComposite, cache[index].storage()));
}

if (provider != null) {
provider.resolve(index).ifPresentOrElse(resolved -> {
cache[index] = new MultiStorageInternalStorage(
resolved.storage(),
resolved.storageChannelType(),
listener
);
final MultiStorageExposedStorage<?> relevantComposite = exposedStorages.get(
resolved.storageChannelType()
);
results.add(new StorageChange(false, relevantComposite, cache[index]));
cache[index] = (TypedStorage) StateTrackedStorage.of(resolved, listener);
final ExposedStorage<?> relevantComposite = exposedStorages.get(resolved.storageChannelType());
results.add(new StorageChange(false, relevantComposite, cache[index].storage()));
}, () -> cache[index] = null);
}

Expand Down Expand Up @@ -145,19 +142,19 @@ private void enableAllStorages() {

@SuppressWarnings({"unchecked", "rawtypes"})
private void enableAllStoragesForChannel(final StorageChannelType<?> type,
final MultiStorageExposedStorage<?> exposedStorage) {
for (final MultiStorageInternalStorage<?> internalStorage : cache) {
if (internalStorage != null && internalStorage.getStorageChannelType() == type) {
exposedStorage.addSource((MultiStorageInternalStorage) internalStorage);
final ExposedStorage<?> exposedStorage) {
for (final TypedStorage<?, StateTrackedStorage<?>> internalStorage : cache) {
if (internalStorage != null && internalStorage.storageChannelType() == type) {
exposedStorage.addSource((StateTrackedStorage) internalStorage.storage());
}
}
}

private void disableAllStorages() {
exposedStorages.values().forEach(MultiStorageExposedStorage::clearSources);
exposedStorages.values().forEach(ExposedStorage::clearSources);
}

public void setListener(final MultiStorageListener listener) {
public void setListener(final StateTrackedStorage.Listener listener) {
this.listener = listener;
}

Expand All @@ -178,7 +175,7 @@ public StorageState getState(final int index) {
if (!isActive()) {
return StorageState.INACTIVE;
}
return storage.getState();
return storage.storage().getState();
}

@Override
Expand All @@ -189,15 +186,15 @@ protected Set<? extends StorageChannelType<?>> getRelevantStorageChannelTypes()
@Override
@SuppressWarnings("unchecked")
public <T> Optional<Storage<T>> getStorageForChannel(final StorageChannelType<T> channelType) {
final MultiStorageExposedStorage<?> storage = exposedStorages.get(channelType);
final ExposedStorage<?> storage = exposedStorages.get(channelType);
if (storage != null) {
return Optional.of((Storage<T>) storage);
}
return Optional.empty();
}

private record StorageChange(boolean removed,
MultiStorageExposedStorage<?> exposedStorage,
MultiStorageInternalStorage<?> internalStorage) {
ExposedStorage<?> exposedStorage,
StateTrackedStorage<?> internalStorage) {
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage;

import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.TypedStorage;

import java.util.Optional;

@FunctionalInterface
public interface MultiStorageProvider {
Optional<TypedStorage<?>> resolve(int index);
<T> Optional<TypedStorage<T, Storage<T>>> resolve(int index);
}

This file was deleted.

Loading

0 comments on commit 2020283

Please sign in to comment.