This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
9 changed files
with
128 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Realm.Assets; | ||
using UnityEngine; | ||
using Realm.Jobs; | ||
|
||
namespace Realm.Gui; | ||
|
||
public enum AsyncIconStatus { Unstarted, Loading, Loaded, Errored } | ||
|
||
sealed class AsyncIcon | ||
{ | ||
private readonly string iconFilename; | ||
private readonly string iconURL; | ||
|
||
public AsyncIconStatus Status { get; private set; } | ||
|
||
public AsyncIcon(string iconFilename, string iconURL) | ||
{ | ||
this.iconFilename = iconFilename; | ||
this.iconURL = iconURL; | ||
} | ||
|
||
public void StartLoading() | ||
{ | ||
Status = AsyncIconStatus.Loading; | ||
Job.Start(() => Status = Load()); | ||
} | ||
|
||
private AsyncIconStatus Load() | ||
{ | ||
if (Futile.atlasManager._allElementsByName.ContainsKey(iconURL)) { | ||
return AsyncIconStatus.Loaded; | ||
} | ||
|
||
string path = Path.Combine(RealmPaths.IconFolder.FullName, iconFilename); | ||
|
||
if (File.Exists(path) && (DateTime.UtcNow - File.GetLastWriteTimeUtc(path)).TotalDays < 10) { | ||
return GetIcon(path); | ||
} | ||
|
||
var proc = BackendProcess.Execute($"-dl \"{iconURL}\" \"{path}\""); | ||
if (proc.ExitCode == 0 && File.Exists(path)) { | ||
return GetIcon(path); | ||
} | ||
|
||
Program.Logger.LogError($"Error downloading icon for {iconFilename}. {proc}"); | ||
|
||
return AsyncIconStatus.Errored; | ||
} | ||
|
||
private AsyncIconStatus GetIcon(string iconPath) | ||
{ | ||
using FileStream stream = File.OpenRead(iconPath); | ||
|
||
Texture2D tex = Asset.LoadTexture(stream); | ||
|
||
if (tex.width != 128 || tex.height != 128) { | ||
Program.Logger.LogError($"Icon texture for {iconFilename} was not 128x128"); | ||
UnityEngine.Object.Destroy(tex); | ||
return AsyncIconStatus.Errored; | ||
} | ||
else { | ||
HeavyTexturesCache.LoadAndCacheAtlasFromTexture(iconURL, tex); | ||
return AsyncIconStatus.Loaded; | ||
} | ||
} | ||
} |
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,26 @@ | ||
using Menu; | ||
using Realm.Assets; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace Realm.Gui.Elements; | ||
|
||
sealed class LoadSpinny : PositionedMenuObject | ||
{ | ||
public readonly MenuSprite ico; | ||
|
||
public LoadSpinny(MenuObject owner, Vector2 pos) : base(owner.menu, owner, pos) | ||
{ | ||
subObjects.Add(ico = new(this, default, Asset.SpriteFromRes("HARDHAT"))); | ||
} | ||
|
||
public override void Update() | ||
{ | ||
base.Update(); | ||
|
||
ico.sprite.rotation += 360f / 40f; | ||
} | ||
} |
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,6 +1,5 @@ | ||
using Menu; | ||
using Realm.Gui.Menus; | ||
using UnityEngine; | ||
|
||
namespace Realm.Gui; | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using UnityEngine; | ||
|
||
namespace Realm.ModLoading; | ||
namespace Realm.ModLoading; | ||
|
||
sealed class AudbEntry | ||
{ | ||
|
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,6 +1,6 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>0.10.0</Version> | ||
<Version>0.10.1</Version> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
</Project> |