Skip to content

Commit

Permalink
chore: Reformat Loader and Timer for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Nov 26, 2024
1 parent 59f1e9a commit b639279
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 113 deletions.
96 changes: 48 additions & 48 deletions core/src/avm2/globals/flash/display/Loader.as
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
package flash.display {
import flash.display.LoaderInfo;
import flash.display.DisplayObject;
import flash.errors.IllegalOperationError;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import flash.net.URLRequest;
import flash.events.UncaughtErrorEvents;
import __ruffle__.stub_method;

[Ruffle(InstanceAllocator)]
public class Loader extends DisplayObjectContainer {
import flash.display.LoaderInfo;
import flash.display.DisplayObject;
import flash.errors.IllegalOperationError;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import flash.net.URLRequest;
import flash.events.UncaughtErrorEvents;
import __ruffle__.stub_method;
[Ruffle(InstanceAllocator)]
public class Loader extends DisplayObjectContainer {

[Ruffle(InternalSlot)]
private var _contentLoaderInfo: LoaderInfo;
private var _contentLoaderInfo: LoaderInfo;

public function get contentLoaderInfo():LoaderInfo {
return this._contentLoaderInfo;
}
public function get contentLoaderInfo():LoaderInfo {
return this._contentLoaderInfo;
}

public function get content():DisplayObject {
return this._contentLoaderInfo.content;
}
public function get content():DisplayObject {
return this._contentLoaderInfo.content;
}

public native function load(request: URLRequest, context: LoaderContext = null):void;
public native function load(request: URLRequest, context: LoaderContext = null):void;

public native function loadBytes(data: ByteArray, context: LoaderContext = null):void;

public native function unload():void;
public native function loadBytes(data: ByteArray, context: LoaderContext = null):void;

public function unloadAndStop(gc:Boolean = true):void {
stub_method("flash.display.Loader", "unloadAndStop");
this.unload();
}

public function close():void {
stub_method("flash.display.Loader", "close");
}
public native function unload():void;

override public function addChild(child:DisplayObject):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}
public function unloadAndStop(gc:Boolean = true):void {
stub_method("flash.display.Loader", "unloadAndStop");
this.unload();
}

override public function addChildAt(child:DisplayObject, index:int):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}
public function close():void {
stub_method("flash.display.Loader", "close");
}

override public function removeChild(child:DisplayObject):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}
override public function addChild(child:DisplayObject):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}

override public function removeChildAt(index:int):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}
override public function addChildAt(child:DisplayObject, index:int):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}

override public function setChildIndex(child:DisplayObject, index:int):void {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}
override public function removeChild(child:DisplayObject):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}

public function get uncaughtErrorEvents():UncaughtErrorEvents {
return this.contentLoaderInfo.uncaughtErrorEvents;
}
}
override public function removeChildAt(index:int):DisplayObject {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}

override public function setChildIndex(child:DisplayObject, index:int):void {
throw new IllegalOperationError("Error #2069: The Loader class does not implement this method.", 2069);
}

public function get uncaughtErrorEvents():UncaughtErrorEvents {
return this.contentLoaderInfo.uncaughtErrorEvents;
}
}
}
130 changes: 65 additions & 65 deletions core/src/avm2/globals/flash/utils/Timer.as
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
package flash.utils {
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
public class Timer extends EventDispatcher {
private var _currentCount: int;
private var _repeatCount: int;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
public class Timer extends EventDispatcher {
private var _currentCount: int;
private var _repeatCount: int;

[Ruffle(InternalSlot)]
private var _delay: Number;
[Ruffle(InternalSlot)]
private var _delay: Number;

[Ruffle(InternalSlot)]
private var _timerId: int = -1;
[Ruffle(InternalSlot)]
private var _timerId: int = -1;

private function checkDelay(delay:Number): void {
if (!isFinite(delay) || delay < 0) {
throw new RangeError("Timer delay out of range", 2066);
}
}
private function checkDelay(delay:Number): void {
if (!isFinite(delay) || delay < 0) {
throw new RangeError("Timer delay out of range", 2066);
}
}

public function Timer(delay:Number, repeatCount:int=0) {
this.checkDelay(delay);
this._currentCount = 0;
this._delay = delay;
this._repeatCount = repeatCount;
}
public function Timer(delay:Number, repeatCount:int=0) {
this.checkDelay(delay);
this._currentCount = 0;
this._delay = delay;
this._repeatCount = repeatCount;
}

public function get currentCount(): int {
return this._currentCount;
}
public function get currentCount(): int {
return this._currentCount;
}

public function get delay(): Number {
return this._delay;
}
public function get delay(): Number {
return this._delay;
}

public function set delay(value:Number): void {
this.checkDelay(delay);
this._delay = value;
if (this.running) {
this.updateDelay();
}
}
public function set delay(value:Number): void {
this.checkDelay(delay);
this._delay = value;
if (this.running) {
this.updateDelay();
}
}

private native function updateDelay():void;
private native function updateDelay():void;

public function get repeatCount(): int {
return this._repeatCount;
}
public function get repeatCount(): int {
return this._repeatCount;
}

public function set repeatCount(value:int): void {
this._repeatCount = value;
if (this._repeatCount != 0 && this._repeatCount <= this._currentCount) {
this.stop();
}
}
public function set repeatCount(value:int): void {
this._repeatCount = value;
if (this._repeatCount != 0 && this._repeatCount <= this._currentCount) {
this.stop();
}
}

public function get running(): Boolean {
return this._timerId != -1;
}
public function get running(): Boolean {
return this._timerId != -1;
}

public function reset():void {
this._currentCount = 0;
this.stop();
}
public function reset():void {
this._currentCount = 0;
this.stop();
}

public native function stop():void;
public native function start():void;
public native function stop():void;
public native function start():void;

// Returns 'true' if we should cancel the underlying Ruffle native timer
internal function onUpdate():Boolean {
this._currentCount += 1;
this.dispatchEvent(new TimerEvent(TimerEvent.TIMER, false, false));
if (this.repeatCount != 0 && this._currentCount >= this._repeatCount) {
// This will make 'running' return false in a TIMER_COMPLETE event handler
this._timerId = -1;
this.dispatchEvent(new TimerEvent(TimerEvent.TIMER_COMPLETE, false, false));
return true;
}
return false;
}
}
// Returns 'true' if we should cancel the underlying Ruffle native timer
internal function onUpdate():Boolean {
this._currentCount += 1;
this.dispatchEvent(new TimerEvent(TimerEvent.TIMER, false, false));
if (this.repeatCount != 0 && this._currentCount >= this._repeatCount) {
// This will make 'running' return false in a TIMER_COMPLETE event handler
this._timerId = -1;
this.dispatchEvent(new TimerEvent(TimerEvent.TIMER_COMPLETE, false, false));
return true;
}
return false;
}
}
}

0 comments on commit b639279

Please sign in to comment.