Skip to content

Commit

Permalink
Make providing different objects for scenery generation more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Basssiiie committed Oct 19, 2024
1 parent 6bb30ef commit f86f72e
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 400ccd377ed0b7746b3c567d74b00408, type: 3}
m_Script: {fileID: 11500000, guid: 6d3333843e8ee344b86e1249398ab337, type: 3}
m_Name: RoofSideH2
m_EditorClassIdentifier:
_prefab: {fileID: 6135319879212020766, guid: 7cc5bdbf00434d64f9262b8c98536bcd, type: 3}
_animationShader: {fileID: -6465566751694194690, guid: 51e8f198c20324141b9b85da080dd22b,
type: 3}
_scaleMode: 0
_objectIds:
_identifiers:
- rct2.scenery_small.roof1
- rct2.scenery_small.roof2
- rct2.scenery_small.roof5
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 400ccd377ed0b7746b3c567d74b00408, type: 3}
m_Script: {fileID: 11500000, guid: 6d3333843e8ee344b86e1249398ab337, type: 3}
m_Name: SceneryBlock
m_EditorClassIdentifier:
_prefab: {fileID: 5275838848359540594, guid: 8104fba65125982408954986146ca47d, type: 3}
_animationShader: {fileID: 0}
_scaleMode: 0
_objectIds:
_identifiers:
- rct2tt.scenery_small.artdec28
- rct2.scenery_small.brbase
- rct2.scenery_small.brbase2
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1b3ee7f603a4f1a469e1cca4d62ca44c, type: 3}
m_Name: SmallSceneryGenerator
m_EditorClassIdentifier:
_animationShader: {fileID: -6465566751694194690, guid: 51e8f198c20324141b9b85da080dd22b,
type: 3}
_defaultPrefab: {fileID: 4503080842329074919, guid: 3be8c3c47c6fc4d408867ddcee62b87c,
type: 3}
_animationShader: {fileID: -6465566751694194690, guid: 51e8f198c20324141b9b85da080dd22b,
type: 3}
_defaultScaleMode: 2
_prefabOverrides:
- {fileID: 11400000, guid: b6132f03b3909504b8143ece3af3b1fe, type: 2}
- {fileID: 11400000, guid: 6988240bb8ac8b34c8c30e6de73182bb, type: 2}
_providers:
- {fileID: 11400000, guid: ea70123090ff11a4e8d273b55c83a0a8, type: 2}
- {fileID: 11400000, guid: 25206f02ab45cd84db64c0e66266a2bb, type: 2}
2 changes: 1 addition & 1 deletion src/openrct2-unity/Assets/Scenes/ParkScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f58090d8844c91e45a2a0d888eb8d265, type: 3}
m_Name:
m_EditorClassIdentifier:
selectedPark: Six Flags Magic Mountain.SC6
selectedPark: My test park/Test park with house.sv6
--- !u!114 &1491562777
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using OpenRCT2.Generators.Map.Retro.Providers;

#nullable enable

namespace OpenRCT2.Behaviours.Generators.Objects
{
public static class ProviderHelper
{
public static IReadOnlyDictionary<string, IObjectProvider<T>> CreateLookup<T>(ProviderObject<T>[] providers) where T : struct
{
var lookup = new Dictionary<string, IObjectProvider<T>>();

foreach (var provider in providers)
{
var entries = provider.GetEntries();

foreach (var identifier in entries.identifiers)
{
lookup.Add(identifier, entries.provider);
}
}

return lookup;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

#nullable enable

namespace OpenRCT2.Generators.Map.Retro.Providers
{
/// <summary>
/// Unity object that can create a game object provider for a set of OpenRCT2 object identifiers.
/// </summary>
public abstract class ProviderObject<T> : ScriptableObject where T : struct
{
/// <summary>
/// Get all identifiers and their object provider.
/// </summary>
public abstract (string[] identifiers, IObjectProvider<T> provider) GetEntries();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using OpenRCT2.Bindings.TileElements;
using OpenRCT2.Generators.Map.Retro.Data;
using OpenRCT2.Utilities;
using UnityEngine;

#nullable enable

namespace OpenRCT2.Generators.Map.Retro.Providers
{
[CreateAssetMenu(menuName = ("OpenRCT2/Objects/" + nameof(SmallScenerySpriteProviderObject)))]
public class SmallScenerySpriteProviderObject : ProviderObject<SmallSceneryInfo>
{
[SerializeField, Required] GameObject? _prefab;
[SerializeField] Shader? _animationShader;
[SerializeField] ObjectScaleMode _scaleMode;

[ContextMenuItem("Sort Alphabetically ", nameof(SortObjectIds))]
[SerializeField] string[] _identifiers = Array.Empty<string>();

public override (string[] identifiers, IObjectProvider<SmallSceneryInfo> provider) GetEntries()
{
Assert.IsNotNull(_prefab);

var provider = new SmallScenerySpriteObjectProvider(_prefab, _animationShader, _scaleMode);
return (_identifiers, provider);
}

/// <summary>
/// Sorts all object ids alphabetically.
/// </summary>
void SortObjectIds()
{
Array.Sort(_identifiers);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using OpenRCT2.Behaviours.Generators.Objects;
using OpenRCT2.Bindings.TileElements;
using OpenRCT2.Generators.Map;
using OpenRCT2.Generators.Map.Retro;
using OpenRCT2.Generators.Map.Retro.Data;
using OpenRCT2.Generators.Map.Retro.Providers;
using OpenRCT2.Utilities;
using UnityEngine;

Expand All @@ -19,21 +21,15 @@ public class SmallSceneryGeneratorScript : TileElementGeneratorScript
[SerializeField] Shader? _animationShader;
[SerializeField, Required] GameObject _defaultPrefab = null!;
[SerializeField] ObjectScaleMode _defaultScaleMode;
[SerializeField] PrefabEntryObject[] _prefabOverrides = Array.Empty<PrefabEntryObject>();

[SerializeField] ProviderObject<SmallSceneryInfo>[] _providers = Array.Empty<ProviderObject<SmallSceneryInfo>>();

public override ITileElementGenerator CreateGenerator()
{
var prefabs = _prefabOverrides;
var length = prefabs.Length;
var entries = new ObjectEntry[length];
var defaultProvider = new SmallScenerySpriteObjectProvider(_defaultPrefab, _animationShader, _defaultScaleMode);
var providers = ProviderHelper.CreateLookup(_providers);

for ( var i = 0; i < length; i++)
{
entries[i] = prefabs[i].GetObjectEntry();
}

return new SmallSceneryGenerator(_animationShader, _defaultPrefab, _defaultScaleMode, entries);
return new SmallSceneryGenerator(defaultProvider, providers);
}
}
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using OpenRCT2.Bindings.TileElements;
using UnityEngine;

#nullable enable

namespace OpenRCT2.Generators.Map.Retro.Providers
{
public interface IObjectProvider<T> where T : struct
{
/// <summary>
/// Creates an object according to the provider's implementation.
/// </summary>
GameObject CreateObject(int x, int y, int index, in TileElementInfo element, in T data);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f86f72e

Please sign in to comment.