-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
b464a74
commit 1c8af7d
Showing
18 changed files
with
456 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Promete.Example.Kernel; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class DemoAttribute(string path, string description) : Attribute | ||
{ | ||
public string Path { get; } = path; | ||
|
||
public string Description { get; } = description; | ||
} |
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,63 @@ | ||
using System.Reflection; | ||
|
||
namespace Promete.Example.Kernel; | ||
|
||
public class DemoFileSystem | ||
{ | ||
public Folder Root { get; } = new Folder(""); | ||
|
||
public DemoFileSystem() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
var scenes = GetType().Assembly.GetTypes() | ||
.Select(type => (type, attribute: type.GetCustomAttribute<DemoAttribute>())) | ||
.Where(t => t.attribute is not null) as IEnumerable<(Type, DemoAttribute)>; | ||
|
||
foreach (var (type, attribute) in scenes) | ||
{ | ||
var path = attribute.Path; | ||
if (path.IndexOf('/') < 0) path = "/" + path; | ||
var a = path.LastIndexOf('/'); | ||
var folderPath = path.Remove(a); | ||
var fileName = path[(a + 1)..]; | ||
var folder = CreateOrGetFolder(folderPath); | ||
|
||
var file = new SceneFile(fileName, attribute.Description, type, folder); | ||
|
||
folder.Files.Add(file); | ||
folder.Files.Sort((f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.Ordinal)); | ||
} | ||
} | ||
|
||
private Folder CreateOrGetFolder(string path) | ||
{ | ||
path = path.ToLowerInvariant(); | ||
var nest = path.Split('/').Where(s => !string.IsNullOrEmpty(s)); | ||
var current = Root; | ||
foreach (var name in nest) | ||
{ | ||
var el = current.Files.FirstOrDefault(f => f.Name == name); | ||
switch (el) | ||
{ | ||
case null: | ||
{ | ||
var folder = new Folder(name, current); | ||
current.Files.Add(folder); | ||
current = folder; | ||
break; | ||
} | ||
case Folder f: | ||
current = f; | ||
break; | ||
default: | ||
// el is other non-null type | ||
throw new Exception($"'{path}' already exists"); | ||
} | ||
} | ||
return current; | ||
} | ||
} |
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,10 @@ | ||
namespace Promete.Example.Kernel; | ||
|
||
public static class DemoKernel | ||
{ | ||
public static DemoFileSystem FileSystem { get; } = new(); | ||
|
||
public static Folder CurrentFolder { get; set; } = FileSystem.Root; | ||
|
||
public static int CurrentIndex { get; set; } | ||
} |
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,17 @@ | ||
namespace Promete.Example.Kernel; | ||
|
||
public class Folder(string name, Folder? parent = null) : IFileSystemElement | ||
{ | ||
public string Name { get; } = name; | ||
|
||
public List<IFileSystemElement> Files { get; } = []; | ||
|
||
public Folder? Parent { get; } = parent; | ||
|
||
public int Count => Files.Count; | ||
|
||
public string GetFullPath() | ||
{ | ||
return Parent == null ? Name : $"{Parent.GetFullPath()}/{Name}"; | ||
} | ||
} |
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,7 @@ | ||
namespace Promete.Example.Kernel; | ||
|
||
public interface IFileSystemElement | ||
{ | ||
string Name { get; } | ||
Folder? Parent { get; } | ||
} |
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,9 @@ | ||
namespace Promete.Example.Kernel; | ||
|
||
public class SceneFile(string name, string description, Type scene, Folder? parent = null) : IFileSystemElement | ||
{ | ||
public string Name { get; } = name; | ||
public string Description { get; } = description; | ||
public Type Scene { get; } = scene; | ||
public Folder? Parent { get; } = parent; | ||
} |
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 |
---|---|---|
@@ -1,96 +1,80 @@ | ||
using Promete; | ||
using Promete.Audio; | ||
using Promete.Elements; | ||
using Promete.Example.Kernel; | ||
using Promete.Graphics; | ||
using Promete.Input; | ||
using Promete.Windowing; | ||
using Color = System.Drawing.Color; | ||
|
||
using static Promete.Example.Kernel.DemoKernel; | ||
|
||
namespace Promete.Example; | ||
|
||
public class MainScene : Scene | ||
public class MainScene(PrometeApp app, IWindow window, Mouse mouse, Keyboard keyboard, ConsoleLayer console) : Scene | ||
{ | ||
private Tilemap map; | ||
|
||
private readonly PrometeApp app; | ||
private readonly IWindow window; | ||
private readonly Keyboard keyboard; | ||
private readonly ConsoleLayer console; | ||
private readonly Mouse mouse; | ||
private readonly ITile tile; | ||
private readonly AudioPlayer player; | ||
private readonly VorbisAudioSource sound; | ||
private readonly WaveAudioSource sfx1; | ||
|
||
public MainScene(PrometeApp app, IWindow window, Keyboard keyboard, Mouse mouse, ConsoleLayer console) | ||
public override void OnStart() | ||
{ | ||
this.app = app; | ||
this.window = window; | ||
this.keyboard = keyboard; | ||
this.mouse = mouse; | ||
this.console = console; | ||
|
||
player = new AudioPlayer(); | ||
sound = new VorbisAudioSource("assets/kagerou.ogg"); | ||
sfx1 = new WaveAudioSource("assets/lineclear.wav"); | ||
|
||
tile = new Tile(window.TextureFactory.CreateSolid(Color.Red, (16, 16))); | ||
} | ||
|
||
public override Container Setup() | ||
public override void OnUpdate() | ||
{ | ||
map = new Tilemap((16, 16)); | ||
string a = ""; | ||
return new Container | ||
{ | ||
map, | ||
}; | ||
OutputUI(); | ||
HandleInput(); | ||
} | ||
|
||
public override void OnUpdate() | ||
private void OutputUI() | ||
{ | ||
console.Clear(); | ||
console.Print("Hello, Promete!"); | ||
console.Print($"FPS: {window.FramePerSeconds}"); | ||
console.Print($"UPS: {window.UpdatePerSeconds}"); | ||
var pan = (mouse.Position.X - window.Size.X / 2) / (window.Size.X / 2f); | ||
console.Print($"pan: {pan}"); | ||
console.Print("Promete Demo\n"); | ||
console.Print($"現在のディレクトリ: /{CurrentFolder.GetFullPath()}\n"); | ||
|
||
if (keyboard.Escape.IsKeyDown) | ||
for (var i = 0; i < CurrentFolder.Files.Count; i++) | ||
{ | ||
app.Exit(); | ||
var item = CurrentFolder.Files[i]; | ||
var label = item is SceneFile file ? $"{file.Name} - {file.Description}" : item.Name; | ||
console.Print($"{(i == CurrentIndex ? ">" : " ")} {label}"); | ||
} | ||
|
||
if (mouse[MouseButtonType.Left]) | ||
{ | ||
var (x, y) = mouse.Position / 16; | ||
map[x, y] = tile; | ||
} | ||
console.Print($"{(CurrentIndex == CurrentFolder.Files.Count ? ">" : " ")} もどる"); | ||
} | ||
|
||
if (keyboard.Space.IsKeyDown) | ||
private void HandleInput() | ||
{ | ||
if (keyboard.Up.IsKeyDown) | ||
{ | ||
if (player.IsPlaying) player.Stop(); | ||
else player.Play(sound); | ||
CurrentIndex--; | ||
if (CurrentIndex < 0) CurrentIndex = 0; | ||
} | ||
|
||
if (mouse[MouseButtonType.Right].IsButtonDown) | ||
else if (keyboard.Down.IsKeyDown) | ||
{ | ||
player.PlayOneShotAsync(sfx1, mouse.Position.Y / (float)window.Height, 2f, pan); | ||
CurrentIndex++; | ||
if (CurrentIndex > CurrentFolder.Files.Count) CurrentIndex = CurrentFolder.Files.Count; | ||
} | ||
else if (keyboard.Enter.IsKeyDown) | ||
{ | ||
if (CurrentIndex == CurrentFolder.Files.Count) | ||
{ | ||
if (CurrentFolder.Parent == null) return; | ||
|
||
if (keyboard.Number1.IsKeyDown) | ||
CurrentFolder = CurrentFolder.Parent; | ||
CurrentIndex = 0; | ||
} | ||
else | ||
{ | ||
var item = CurrentFolder.Files[CurrentIndex]; | ||
switch (item) | ||
{ | ||
case Folder folder: | ||
CurrentFolder = folder; | ||
CurrentIndex = 0; | ||
break; | ||
case SceneFile file: | ||
app.LoadScene(file.Scene); | ||
break; | ||
} | ||
} | ||
} | ||
else if (keyboard.Escape.IsKeyDown) | ||
{ | ||
TestAwaitingTaskAsync(); | ||
app.Exit(); | ||
} | ||
} | ||
|
||
private async void TestAwaitingTaskAsync() | ||
{ | ||
player.PlayOneShot(sfx1); | ||
await Task.Delay(1000); | ||
player.PlayOneShot(sfx1); | ||
await Task.Delay(1000); | ||
player.PlayOneShot(sfx1); | ||
await Task.Delay(1000); | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,74 @@ | ||
using Promete.Audio; | ||
using Promete.Example.Kernel; | ||
using Promete.Input; | ||
using Promete.Windowing; | ||
|
||
namespace Promete.Example.examples.audio; | ||
|
||
[Demo("/audio/ogg vorbis", "BGM を再生します")] | ||
public class OggVorbisExampleScene(PrometeApp app, IWindow window, Keyboard keyboard, ConsoleLayer console) : Scene | ||
{ | ||
private readonly AudioPlayer audio = new(); | ||
private IAudioSource bgm = new VorbisAudioSource("./assets/kagerou.ogg"); | ||
|
||
public override void OnStart() | ||
{ | ||
window.Title = "Ogg Vorbis playback example"; | ||
console.Print("Ogg Vorbis playback Example"); | ||
|
||
window.FileDropped += WindowOnFileDropped; | ||
} | ||
|
||
public override void OnUpdate() | ||
{ | ||
console.Cursor += VectorInt.Up * 2; | ||
console.Print($""" | ||
Location: {audio.Time / 1000f:0.000} / {audio.Length / 1000f:0.000} | ||
[↑] Volume Up | ||
[↓] Volume Down | ||
[←] Pitch Down | ||
[→] Pitch Up | ||
PRESS ESC TO RETURN | ||
"""); | ||
|
||
if (keyboard.Escape.IsKeyUp) | ||
app.LoadScene<MainScene>(); | ||
|
||
if (keyboard.Up.IsKeyDown) | ||
audio.Gain += 0.1f; | ||
|
||
if (keyboard.Down.IsKeyDown) | ||
audio.Gain -= 0.1f; | ||
|
||
if (keyboard.Left.IsKeyDown) | ||
audio.Pitch -= 0.1f; | ||
|
||
if (keyboard.Right.IsKeyDown) | ||
audio.Pitch += 0.1f; | ||
|
||
if (keyboard.Space.IsKeyDown) | ||
{ | ||
if (audio.IsPlaying) | ||
audio.Stop(); | ||
else | ||
audio.Play(bgm); | ||
} | ||
} | ||
|
||
public override void OnDestroy() | ||
{ | ||
audio.Stop(); | ||
audio.Dispose(); | ||
window.FileDropped -= WindowOnFileDropped; | ||
} | ||
|
||
private void WindowOnFileDropped(FileDroppedEventArgs e) | ||
{ | ||
var path = e.Path; | ||
if (!path.EndsWith(".ogg")) return; | ||
|
||
audio.Stop(); | ||
bgm = new VorbisAudioSource(path); | ||
audio.Play(bgm); | ||
} | ||
} |
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,29 @@ | ||
using Promete.Audio; | ||
using Promete.Example.Kernel; | ||
using Promete.Input; | ||
using Promete.Windowing; | ||
|
||
namespace Promete.Example.examples.audio; | ||
|
||
[Demo("/audio/wav sfx", "短い効果音をいくつか再生します")] | ||
public class WavExampleScene(PrometeApp app, IWindow window, Keyboard keyboard, ConsoleLayer console) : Scene | ||
{ | ||
private readonly AudioPlayer player = new(); | ||
private readonly WaveAudioSource sfx = new("assets/lineclear.wav"); | ||
|
||
public override void OnStart() | ||
{ | ||
console.Print("SFX Example\n"); | ||
console.Print("[SPACE]: Replay"); | ||
console.Print("[ESC]: Quit"); | ||
} | ||
|
||
public override void OnUpdate() | ||
{ | ||
if (keyboard.Space.IsKeyUp) | ||
player.PlayOneShotAsync(sfx); | ||
|
||
if (keyboard.Escape.IsKeyUp) | ||
app.LoadScene<MainScene>(); | ||
} | ||
} |
Oops, something went wrong.